2016年11月

配置DNS服务器主从

修改主服务器配置

在主服务器的zone配置中添加

zone "baidu.com." IN {
        type master;
        file "baidu.com.ca";
        // 添加这一项,允许指定的ip来获取zone的数据
        allow-transfer { 192.168.1.126; };
};
修改从服务器配置

一定注意配置文件的权限是否能被named程序读写

zone "baidu.com." IN {
        // 指定类型为slave
        type slave;
        // 指定主服务器ip
        masters { 192.168.1.99; };
        // 指定zone文件的路径,一定注意这个文件的权限,默认路径为/var/named文件下,按照以下配置,路径是:/var/named/slaves/slave1.baidu.com.ca
        file "slaves/slave1.baidu.com.ca";
};

重启就能看到数据同步了

在主服务器设置从服务器的NS记录
vim /var/named/baidu.com.ca

$TTL 1D

baidu.com.      IN SOA  master.baidu.com. root.baidu.com. (
                                        1       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum

baidu.com.      NS      master.baidu.com.
master.baidu.com.       A       192.168.1.99
; 下面就是从服务器的NS记录和A记录,这样在查询NS记录时就能把NS记录也显示出来了
baidu.com.      NS      slave1.baidu.com.
slave1.baidu.com.       A       192.168.1.99
; 下面就是真实解析的域名了
www.baidu.com.  A       192.168.1.99
; 下面这种写法代表的是aaa.baidu.com
aaa     A       192.168.1.99
; ipv6地址的解析
www.baidu.com.  AAAA    ::1

记得要修改 serial的值,然后重启

使不同的客户端查询时获得不同的ip

把上面的配置文件中的

www.baidu.com.  A       192.168.1.99

修改成如下即可

www.baidu.com. 1        A       192.168.1.99
www.baidu.com. 1        A       192.168.1.100
www.baidu.com. 1        A       192.168.1.101
www.baidu.com. 1        A       192.168.1.102
www.baidu.com. 1        A       192.168.1.104
使用秘钥认证来提高安全性
生成秘钥,我的centos 6.6 minimal系统不能生成秘钥,我在其他系统生成的
#为主机master.baidu.com生成长度为128的hmac-md5类型的秘钥
dnssec-keygen -a HMAC-MD5 -b 128 -n HOST master.baidu.com

从生成的文件获取到秘钥

[[email protected] dnskey]# cat ./*
master.baidu.com. IN KEY 512 3 161 AYgLfWsKnGuyh7BVSjNi8w==
Private-key-format: v1.3
Algorithm: 161 (HMAC_SHA1)
Key: AYgLfWsKnGuyh7BVSjNi8w==
Bits: AAA=
Created: 20161126031937
Publish: 20161126031937
Activate: 20161126031937
修改主服务器配置文件named.conf
// 定义秘钥
key masterKey {
        algorithm hmac-md5;
        secret cP1KhD5mTv+91ue0MHdT9g==;
};
// 修改zone允许的更新的条件,之前是ip
zone "baidu.com." IN {
       type master;
       file "baidu.com.ca";
       allow-transfer { key masterKey; };
};

重启named

修改从服务器配置
// 添加下面的
key masterKey {
        algorithm hmac-md5;
        secret cP1KhD5mTv+91ue0MHdT9g==;
};

zone "baidu.com." IN {
        type slave;
        // 在master后指定带上的秘钥
        masters { 192.168.1.99 key masterKey; };
        file "slaves/slave1.baidu.com.ca";
};

ok

centos6.6配置dns服务器

服务器环境 centos 6.6 minimal

安装
安装bind

因为依赖关系所以需要安装这些包

rpm -ivf bind-9.8.2-0.30.rc1.el6.x86_64.rpm bind-libs-9.8.2-0.30.rc1.el6.x86_64.rpm portreserve-0.0.4-9.el6.x86_64.rpm
安装bind-chroot,可以使bind即使被黑也不会影响系统
rpm -ivf bind-chroot-9.8.2-0.30.rc1.el6.x86_64.rpm 
安装caching-nameserver,生成配置文件的范本,在6以下的版本需要单独安装,我这个系统是centos 6.6,不需要单独安装
配置文件

编辑配置

vim /etc/named.conf

添加要解析的zone

// 这里zone的名称要写对,一定要记得结尾的".",和平时在浏览器输入的网址不同
zone "baidu.com." IN {
        // 类型,根据当前dns服务器的类型设置,用的较多的有master和slave,
        type master;
        // zone的配置文件,记得这个文件要能被named程序读取,文件目录为named.conf文件中options的directory选项,默认为"/var/named";
        file "baidu.com.ca";
};

配置zone的配置文件
复制一份已有的配置文件,进行修改

cp -p /var/named/named.localhost /var/named/baidu.com.ca

配置zone

; dns主从服务器配置,下面的含义为一天
$TTL 1D
; @ 和空格都代表当前zone的名称,也就是baidu.com.,前面的@表明当前zone,后面的@代表主服务器,rname.invalid.代表服务器维护人的邮箱也就是 [email protected]
@       IN SOA  @ rname.invalid. (
                                        0       ; serial 
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       127.0.0.1
        AAAA    ::1

解释下上面的参数

参数 解释
$TTL 代表SOA记录的有效期
Serial 代表这个zone 文件的版本,每当zone 文件内容有变动,name server 管理者就应该增加这个号码,因为slave 会将这个号码与其copy 的那份比对以便决定是否要再copy 一次(即进行zone 传输
Refresh Slave server 每隔这段时间(秒),就会检查Master server 上的serial number。不过这里会发生一个问题就是,在master server 在update data 完成到slave server 来检查时再update 可能还有好一段时间,因此这段期间master/slave DNS server间zone files 就可能出现不一致。所以在Bind较新的版本中便加入"notify"功能,使用者在"named.conf" 设定中在需要的zone 中加入"notify"的设定,则master server在update 完成某个zone file 的data 后便会主动发个讯息(NOTIFY),借以通知该其它的slave servers,因此如果slave servers 也有支援这个"notify"功能时,接下来slave servers 马上就可以做zone 传输来更新数据
Retry 当从服务器无法和主站进行串行检查时,要每隔几秒再试一次
Expire 当时间超过Expire 所定的秒数而slave server 都无法和master 取得连络,那么slave 会删除自己的这份copy
Minimum 代表这个zone 文件中所有record 的内定的TTL 值,也就是其它的DNS server cache 这个record时,最长不应该超过这个时间
NS IN NS ns1.kutea.net. (name server, 用来指定操作的DNS服务器主机名称,NS记录是不允许用主机IP地址来表示的。有过域名注册和使用域名的朋友或许知道 域名商要求你指定你域名解释的NS服务器时,你用服务器IP地址来替换,就会报错。就是这个原因了。NS记录其本身就不允许用IP地址来制定
A 和 AAAA A记录 address,即主机记录。(就是将一个域名对应IP地址的记录。)例如下面
IPv4和IPv6指定A记录的格式是:
www IN A 122.128.109.86
mail IN AAAA CDCD:910A:2222:5498:8475:1FF1:3900:2027
PTR 其中这个记录是出现在反向解析zone文件中):
Pointer , 定义某一 IP 地址对应的 domain name ,就是将 IP 地址转换成主机的FQDN
86 IN PTR www.kutea.net. (注意别名记录后面有个小数点)
CNAME Canonical name , 可为同一部主机设定许多别名,例如cdn.kutea.net的别名可为
www.kutea.net和ftp.kutea.net 因此所设定的别名都会连到同一台服务器上。
MX mail exchanger,设定区域中担任邮件服务器的主机,所有要送往那部机器的mail 都要经过mail exchanger 转送。注意 而数字则是该主机邮件传递时的优先次序,此值越低表示有越高的邮件处理优先权。
mail IN MX 3 ns.kutea.net.

因为使用空格代替当前zone又点不直观,就直接写完整的域名了

$TTL 1D

baidu.com.      IN SOA  master.baidu.com. root.baidu.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
; 可以查询baidu.com.下的网址的服务器有下面几个
baidu.com.      NS      master.baidu.com.
baidu.com.      NS      slave1.baidu.com.
baidu.com.      NS      slave2.baidu.com.
; 把ccc.baidu.com交给ddd.baidu.comDNS服务器来处理
ccc.baidu.com.  NS      ddd.baidu.com.
; 上面用到了这几个域名,所以这里需要只想,不然程序会报错
master.baidu.com.       A       192.168.1.99
slave1.baidu.com.       A       192.168.1.99
slave2.baidu.com.       A       192.168.1.99
; 下面就是真实解析的域名了
www.baidu.com.  A       192.168.1.99
; 下面这种写法代表的是aaa.baidu.com
aaa     A       192.168.1.99
; ipv6地址的解析
www.baidu.com.  AAAA    ::1

修改named.conf,允许所有ip可以访问,可以根据需要自己调整,找到下面两项修改

listen-on port 53 { 0.0.0.0/0; };

allow-query     { 0.0.0.0/0; };

ok

配置查询不在配置文件里面的ip

上面配置完成之后,就可以获取到已经设置了的域名的ip,但是没有在配置文件的就不行了

dnssec-enable yes;

yum常用的

使用本地文件作为仓库

[Jin]
name=jin
baseurl=file:///mnt/
gpgcheck=0

yum repolist列出可用的仓库
yum list列出已安装的仓库中的可用软件包
yum list installed列出已经安装的软件包
yum install mysql安装软件包
yum localinstall mysql使用本地已经下载的缓存文件安装
yum remove mysql删除已经安装的文件
yum info mysql查看已安装的程序的信息
yum clean packages清除缓存的包
yum clean headers清楚软件头信息
yum clean all 清除上面的两种信息

rpm包安装

rpm包

系统包所在路径

系统版本 目录
rhel6 /mnt/Packages
rhel5 /mnt/Server
rhel2,3,4 /mnt/RedHat/RPMS

rpm -ivf 安装某个rpm包
rpm -ivf --force 强制重新安装
rpm -ivf --nodeps 忽略依赖关系安装
rpm -qf /usr/bin/mysql 查看执行文件所属的包
rpm -qfi /usr/bin/mysql 查看执行文件所属包的描述信息
rpm -qpi mysql-5.1.73-3.el6_5.x86_64.rpm 查看执行文件所属包的描述信息
rpm -qpl mysql-5.1.73-3.el6_5.x86_64.rpm 查看包里面的文件
rpm -qfl /usr/bin/mysql 查看执行文件所属包里面的文件
rpm -ivf --root /tmp/mysql --nodeps mysql-5.1.73-3.el6_5.x86_64.rpm 解压出包里面的文件
rpm -e 删除
rpm --import ../RPM-GPG-KEY-CentOS-6 导入密钥
rpm -Vf /usr/bin/mysql 查看文件是否修改过

安装的时候,会遇到很多依赖关系的问题
范例,使用系统镜像文件里面带的rpm包安装mysql,系统版本 centos 6.6 minimal

需要安装的包有

[[email protected] Packages]# ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686
mysql-5.1.73-3.el6_5.x86_64.rpm
mysql-bench-5.1.73-3.el6_5.x86_64.rpm
mysql-devel-5.1.73-3.el6_5.x86_64.rpm
mysql-libs-5.1.73-3.el6_5.x86_64.rpm
mysql-server-5.1.73-3.el6_5.x86_64.rpm
mysql-test-5.1.73-3.el6_5.x86_64.rpm

直接安装mysql,缺少perl支持

[[email protected] Packages]# rpm -ivf `ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686`
warning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    /usr/bin/perl is needed by mysql-5.1.73-3.el6_5.x86_64
    perl(Exporter) is needed by mysql-5.1.73-3.el6_5.x86_64
    perl(Fcntl) is needed by mysql-5.1.73-3.el6_5.x86_64
    perl(File::Temp) is needed by mysql-5.1.73-3.el6_5.x86_64
    perl(Getopt::Long) is needed by mysql-5.1.73-3.el6_5.x86_64
    perl(IPC::Open3) is needed by mysql-5.1.73-3.el6_5.x86_64
    perl(Sys::Hostname) is needed by mysql-5.1.73-3.el6_5.x86_64
    /usr/bin/perl is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(Benchmark) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(Cwd) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(DBI) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(Data::Dumper) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(Getopt::Long) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(POSIX) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    perl(sigtrap) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    openssl-devel is needed by mysql-devel-5.1.73-3.el6_5.x86_64
    /usr/bin/perl is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(DBI) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(Data::Dumper) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(File::Basename) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(File::Copy) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(File::Path) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(File::Temp) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(Getopt::Long) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(POSIX) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(Sys::Hostname) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(strict) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(vars) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl-DBD-MySQL is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl-DBI is needed by mysql-server-5.1.73-3.el6_5.x86_64
    /usr/bin/perl is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Carp) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Config) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Cwd) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Data::Dumper) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(English) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Exporter) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Fcntl) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Basename) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Copy) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Find) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Path) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Spec) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Spec::Functions) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(File::Temp) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Getopt::Long) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(IO::File) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(IO::Handle) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(IO::Pipe) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(IO::Select) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(IO::Socket) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(IO::Socket::INET) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Memoize) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(POSIX) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Sys::Hostname) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Time::HiRes) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(Time::localtime) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(base) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(constant) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(if) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(lib) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(strict) is needed by mysql-test-5.1.73-3.el6_5.x86_64
    perl(warnings) is needed by mysql-test-5.1.73-3.el6_5.x86_64

安装perl,需要perl-libs

rpm -ivf perl-5.10.1-136.el6.x86_64.rpm 
warning: perl-5.10.1-136.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    libperl.so()(64bit) is needed by perl-4:5.10.1-136.el6.x86_64
    perl(Module::Pluggable) is needed by perl-4:5.10.1-136.el6.x86_64
    perl(Pod::Simple) is needed by perl-4:5.10.1-136.el6.x86_64
    perl(version) is needed by perl-4:5.10.1-136.el6.x86_64
    perl-libs is needed by perl-4:5.10.1-136.el6.x86_64
    perl-libs = 4:5.10.1-136.el6 is needed by perl-4:5.10.1-136.el6.x86_64

安装perl-libs,失败,和上面的包互相需要,这种时候需要两个包一起安装,并且很多这种模块的包都是互相

rpm -ivf perl-libs-5.10.1-136.el6.x86_64.rpm 
warning: perl-libs-5.10.1-136.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    perl = 4:5.10.1-136.el6 is needed by perl-libs-4:5.10.1-136.el6.x86_64

同时安装,又和其他的互相依赖,同理,全都一起安装

rpm -ivf perl-libs-5.10.1-136.el6.x86_64.rpm perl-5.10.1-136.el6.x86_64.rpm
warning: perl-libs-5.10.1-136.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    perl(Module::Pluggable) is needed by perl-4:5.10.1-136.el6.x86_64
    perl(Pod::Simple) is needed by perl-4:5.10.1-136.el6.x86_64
    perl(version) is needed by perl-4:5.10.1-136.el6.x86_64

再次安装

rpm -ivf perl-libs-5.10.1-136.el6.x86_64.rpm perl-5.10.1-136.el6.x86_64.rpm perl-Module-Pluggable-3.90-136.el6.x86_64.rpm perl-Pod-Simple-3.13-136.el6.x86_64.rpm perl-version-0.77-136.el6.x86_64.rpm perl-Pod-Escapes-1.04-136.el6.x86_64.rpm
warning: perl-libs-5.10.1-136.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
perl-Pod-Escapes-1.04-136.el6
perl-Module-Pluggable-3.90-136.el6
perl-version-0.77-136.el6
perl-Pod-Simple-3.13-136.el6
perl-libs-5.10.1-136.el6
perl-5.10.1-136.el6

再次安装mysql,根据提示安装所有mysql需要的程序,使用命令的关键字查看包,然后安装,提示变少了

[[email protected] Packages]# rpm -ivf `ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686`
warning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    perl(DBI) is needed by mysql-bench-5.1.73-3.el6_5.x86_64
    openssl-devel is needed by mysql-devel-5.1.73-3.el6_5.x86_64
    perl(DBI) is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl-DBD-MySQL is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl-DBI is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(Time::HiRes) is needed by mysql-test-5.1.73-3.el6_5.x86_64

安装perl-DBI

[[email protected] Packages]# rpm -ivf perl-DBI-1.609-4.el6.x86_64.rpm 
warning: perl-DBI-1.609-4.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
perl-DBI-1.609-4.el6

再安装mysql查看需要的包

[[email protected] Packages]# rpm -ivf `ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686`
warning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    openssl-devel is needed by mysql-devel-5.1.73-3.el6_5.x86_64
    perl-DBD-MySQL is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(Time::HiRes) is needed by mysql-test-5.1.73-3.el6_5.x86_64

安装openssl-devel

[[email protected] Packages]# rpm -ivf openssl-devel-1.0.1e-30.el6.x86_64.rpm 
warning: openssl-devel-1.0.1e-30.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    krb5-devel is needed by openssl-devel-1.0.1e-30.el6.x86_64
    zlib-devel is needed by openssl-devel-1.0.1e-30.el6.x86_64

加上这两个再安装

[[email protected] Packages]# rpm -ivf openssl-devel-1.0.1e-30.el6.x86_64.rpm krb5-devel-1.10.3-33.el6.x86_64.rpm zlib-devel-1.2.3-29.el6.x86_64.rpm 
warning: openssl-devel-1.0.1e-30.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    keyutils-libs-devel is needed by krb5-devel-1.10.3-33.el6.x86_64
    libcom_err-devel is needed by krb5-devel-1.10.3-33.el6.x86_64
    libselinux-devel is needed by krb5-devel-1.10.3-33.el6.x86_64

又出现新的,再加

[[email protected] Packages]# rpm -ivf openssl-devel-1.0.1e-30.el6.x86_64.rpm krb5-devel-1.10.3-33.el6.x86_64.rpm zlib-devel-1.2.3-29.el6.x86_64.rpm keyutils-libs-devel-1.4-5.el6.x86_64.rpm libcom_err-devel-1.41.12-21.el6.x86_64.rpm libselinux-devel-2.0.94-5.8.el6.x86_64.rpm 
warning: openssl-devel-1.0.1e-30.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    libsepol-devel >= 2.0.32-1 is needed by libselinux-devel-2.0.94-5.8.el6.x86_64
    pkgconfig(libsepol) is needed by libselinux-devel-2.0.94-5.8.el6.x86_64

安装

[[email protected] Packages]# rpm -ivf openssl-devel-1.0.1e-30.el6.x86_64.rpm krb5-devel-1.10.3-33.el6.x86_64.rpm zlib-devel-1.2.3-29.el6.x86_64.rpm keyutils-libs-devel-1.4-5.el6.x86_64.rpm libcom_err-devel-1.41.12-21.el6.x86_64.rpm libselinux-devel-2.0.94-5.8.el6.x86_64.rpm libsepol-2.0.41-4.el6.x86_64.rpm libsepol-devel-2.0.41-4.el6.x86_64.rpm 
warning: openssl-devel-1.0.1e-30.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
    package libsepol-2.0.41-4.el6.x86_64 is already installed

提示有个包已经安装,去掉这个,再安装

[[email protected] Packages]# rpm -ivf openssl-devel-1.0.1e-30.el6.x86_64.rpm krb5-devel-1.10.3-33.el6.x86_64.rpm zlib-devel-1.2.3-29.el6.x86_64.rpm keyutils-libs-devel-1.4-5.el6.x86_64.rpm libcom_err-devel-1.41.12-21.el6.x86_64.rpm libselinux-devel-2.0.94-5.8.el6.x86_64.rpm libsepol-devel-2.0.41-4.el6.x86_64.rpm 
warning: openssl-devel-1.0.1e-30.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
libsepol-devel-2.0.41-4.el6
libselinux-devel-2.0.94-5.8.el6
libcom_err-devel-1.41.12-21.el6
keyutils-libs-devel-1.4-5.el6
krb5-devel-1.10.3-33.el6
zlib-devel-1.2.3-29.el6
openssl-devel-1.0.1e-30.el6

再安装mysql查看需要的包

[[email protected] Packages]# rpm -ivf `ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686`
warning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
    perl-DBD-MySQL is needed by mysql-server-5.1.73-3.el6_5.x86_64
    perl(Time::HiRes) is needed by mysql-test-5.1.73-3.el6_5.x86_64

安装这个两个包

[[email protected] Packages]# rpm -ivf perl-DBD-MySQL-4.013-3.el6.x86_64.rpm perl-Time-HiRes-1.9721-136.el6.x86_64.rpm 
warning: perl-DBD-MySQL-4.013-3.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
perl-Time-HiRes-1.9721-136.el6
perl-DBD-MySQL-4.013-3.el6

再安装mysql

[[email protected] Packages]# rpm -ivf `ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686`
warning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
    package mysql-libs-5.1.73-3.el6_5.x86_64 is already installed

去掉这个提示的已经安装过的包,再安装

[[email protected] Packages]# rpm -ivf `ls | grep -i "^mysql.*" | grep -v conne | grep -v python | grep -v i686 | grep -v mysql-libs`
warning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing packages for installation...
mysql-5.1.73-3.el6_5
mysql-server-5.1.73-3.el6_5
mysql-test-5.1.73-3.el6_5
mysql-bench-5.1.73-3.el6_5
mysql-devel-5.1.73-3.el6_5

修复已经损坏的文件系统

1.根据开机信息确认损坏文件的系统的分区

错误信息如下:

Checking filesystem
/dev/sda2: clean 113626/3203072 files, 1133795/12800000 blocks
/dev/sdb1: clean 11/4016 files, 1673/16032 blocks
fsck.ext4: Unable to resolve 'UUID=39eac6d2-0188-4a1f-a795-5564bc7c21878'
/dev/sda3: clean 17/3203072 files, 247079/12800000 blocks
/dev/sda6: clean 2031/1782368 files, 226501/12800000 blocks


***An error occured during the filesystem check
***Dropping you to a shell; the system will reboot
***when you leave the shell.

Give root password for maintainence
(or type Controll-D to continue)

有上可知/dev/sda2,/dev/sdb1,/dev/sda3,/dev/sda6分区是好了,排除下,其余的的分区可能就有问题了

我这里是修改了fstab文件引起的问题,进入系统挂载文件所在目录,把fstab修改成正确的文件就行了

mount -o remount,rw /
2.镜像损坏文件系统的分区中的数据到另一个硬盘
  • 如果遇到fsck时,请小心,如果可能,尽快断开系统,unmount所有分区
  • 必须执行fsck时,先做准备工作
    1.使用dd命令将涉及到的分区输出到另外的存储体(最好不要在出错的存储体上做dd),命令dd if=/dev/sda of=/dev/sdb0
    2.将整个linux存储体挂载到虚拟机环境中,将linux存储体设置为 Nopersisten 模式。再执行,执行后,如果数据完好,尽快使用ftp等方式拷贝出来
    3.将整个linux存储体挂载到其他系统,做好镜像后,在fsck
3.使用linux系统光盘进入lnux rescue模式进行修复
4.卸载在损坏的分区
5.使用fsck命令检查文件系统,再修复文件系统

如以上几种方式不能执行,必须执行fsck时,小心观察fsck的执行提示(关掉-a),如果发现有提示节点错误需更正或清0,节点描述文件大小不正确等信息,应立即停止fsck
因回复需要参考很多信息,应尽可能保持系统不工作状态,至少不能再次mount分区(即使不做任何读写操作,也会因为系统的工作原理不断降低数据恢复的可能性,增加数据恢复的难度)
寻求专业数据恢复公司的帮助

# 遇到提示选择 no,先看看错误是什么,如果是以上的几种的话。。。
fsck.ext4 /dev/sdb3
6.重启系统查看分区数据是否真正常
7.修复完文件系统可能会丢失一些文件,丢失的文件在相应的分区的lost+found目录
8.回复lost+found文件中丢失的文件