四、搭建RHCS的高可用集群
4.1、配置Stepping主机上的NtpServer和主机名、以及ssh与其他各个几点的ssh互信和NtpServer
配置hostname
|
1
2
3
4
5
6
|
[root@stepping ~]# vim /etc/hosts172.16.7.1 node1.chris.com node1 172.16.7.2 node2.chris.com node2 172.16.7.3 node3.chris.com node3 172.16.7.4 node4.chris.com node4 172.16.7.8 stepping.chris.com stepping |
配置互信
|
1
2
3
4
5
|
[root@stepping ~]#ssh-keygen -t rsa[root@stepping ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub node1[root@stepping ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub node2[root@stepping ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub node3[root@stepping ~]#ssh-copy-id -i ~/.ssh/id_rsa.pub node4 |
配置NtpServer服务器
配置之前先把本地磁盘做成yum,需要在每个节点上都配置
把本地磁盘挂载到media目录下
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# mount /dev/cdrom /media 挂载光盘vim /etc/yum.repos.d/server.repo,添加如下内容# repos on instructor for classroom use# Main rhel5 server [base] name=Instructor Server Repository baseurl=file:///media/Server gpgcheck=0# This one is needed for xen packages [VT] name=Instructor VT Repository baseurl=file:///media/VT gpgcheck=0# This one is needed for clustering packages [Cluster] name=Instructor Cluster Repository baseurl=file:///media/Cluster gpgcheck=0# This one is needed for cluster storage (GFS, iSCSI target, etc...)packages [ClusterStorage] name=Instructor ClusterStorage Repository baseurl=file:///media/ClusterStorage gpgcheck=0 |
安装NtpServer服务器
[root@stepping ~]#yum –y install ntp
修改配置文件
[root@stepping ~]#vim /etc/ntp.conf
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
restrict default kod nomodify notrap nopeer noquery #默认禁止所有客户端请求时间同步 restrict -6 default kod nomodify notrap nopeer noquery #IPv6的定义# Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1restrict -6 ::1restrict 172.16.0.0 mask 255.255.0.0 nomodify #restrict 定义允许同步的网段 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server 127.0.0.1 #本地上层的ntp服务器,这个必须定义的,指向本地就行 |
通过stepping主机做跳板机配置其他节点的配置
首先定义一个命令别名,方便下面的多个服务器上部署操作:
|
1
2
|
alias hap='for I in {1..4}; do' 配置包括Target在内的主机的命令别名alias hcp='for I in {1..3}; do' 配置不包括Target在内的主机的命令别名 |
配置node1-node4节点主机名
[root@stepping ~]#hap ssh node$I "hostname node$I.chris.com" ; done 注意此处由于命令中有变量,使用双引号
同步各个节点时间
[root@stepping ~]#hap ssh node$I 'ntpdate 172.16.7.8' ; done

复制hosts文件到各个节点
[root@stepping ~]#hap scp /etc/hosts node$I:/etc/ ; done

关闭各个节点的selinux设置
[root@stepping ~]#hap ssh node$I 'setenforce 0' ; done
配置各个节点上的yum
|
1
2
|
[root@stepping ~]#hap ssh node$I 'mount /dev/cdrom /media' ; done [root@stepping ~]#hap scp /etc/yum.repos.d/server.repo node$I:/etc/yum.repos.d/ ; done |

4.2、在node1、node2、node3上安装apache的httpd服务,并进行相关的测试
[root@stepping ~]#hcp ssh node$I 'yum -y install httpd' ; done #安装httpd服务,注意只需在node1-3,所有使用hcp
|
1
2
|
[root@stepping ~]#hcp ssh node$I "echo node$I.chris.com>/var/www/html/index.html"; done |
#设置节点上的各个主页内容,分别为
|
1
2
3
|
[root@stepping ~]#node1.chris.com[root@stepping ~]#node2.chris.com[root@stepping ~]#node3.chris.com |
启动服务并通过curl进行测试
|
1
2
3
4
|
[root@stepping ~]#hcp ssh node$I "service httpd start"; done[root@stepping ~]#hcp curl node$I ; done[root@stepping ~]#hcp ssh node$I "service httpd stop"; done[root@stepping ~]#hcp ssh node$I "chkconfig httpd off"; done |

