Fedora 15上做主从、双主模型的集群
Fedora 15上做双主模型的集群
拓扑如下所示:
----------- ----------
| HA1 |____| HA2 |
|__________| |________|
----------- ----------
| HA1 |____| HA2 |
|__________| |________|
HA1:
IP:192.168.1.78/24
HA2:
IP:192.168.1.151/24
VIP:192.168.1.110
IP:192.168.1.78/24
HA2:
IP:192.168.1.151/24
VIP:192.168.1.110
一、配置网络属性
HA1:
#ifconfit eth0 192.168.1.78/24
#route add default gw 192.168.1.1
#hostname node1.linuxidc.com
HA2:
#ifconfig eth0 192.168.1.151/24
#route add default gw 192.168.1.1
#hostname node2.linuxidc.com
二、配置主机名及两个之间不实用密码能相互通信
#vim /etc/hosts 添加如下内容
192.168.1.78 node1.linuxidc.com node1
192.168.1.151 node2.linuxidc.com node2
同样在HA2上也添加这些内容
#ping node2|node1能解析出来就OK啦
#vim /etc/hosts 添加如下内容
192.168.1.78 node1.linuxidc.com node1
192.168.1.151 node2.linuxidc.com node2
同样在HA2上也添加这些内容
#ping node2|node1能解析出来就OK啦
分别在两个HA上生成一对密钥,如下所示
[root@node1 ~]# ssh-keygen -t rsa //生成公钥和密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
59:71:5d:4d:4c:6d:71:b1:ec:04:17:26:49:cb:27:a1 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| . o*.@@|
| oo.X B|
| .E + * |
| o = |
| S . |
| |
| |
| |
| | //这个图案就是所谓的指纹信息吧,呵呵,RedHat上没有
+-----------------+
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2 //拷贝公钥到对方机
[root@node1 ~]# ssh-keygen -t rsa //生成公钥和密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
59:71:5d:4d:4c:6d:71:b1:ec:04:17:26:49:cb:27:a1 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| . o*.@@|
| oo.X B|
| .E + * |
| o = |
| S . |
| |
| |
| |
| | //这个图案就是所谓的指纹信息吧,呵呵,RedHat上没有
+-----------------+
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2 //拷贝公钥到对方机
器上
The authenticity of host 'node2 (192.168.1.151)' can't be established.
RSA key fingerprint is 77:b6:c6:09:51:f9:f4:70:c1:35:81:47:a5:19:f4:d2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,192.168.1.151' (RSA) to the list of known
The authenticity of host 'node2 (192.168.1.151)' can't be established.
RSA key fingerprint is 77:b6:c6:09:51:f9:f4:70:c1:35:81:47:a5:19:f4:d2.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,192.168.1.151' (RSA) to the list of known
hosts.
root@node2's password: //输入对方机器的密码
Now try logging into the machine, with "ssh 'root@node2'", and check in:
root@node2's password: //输入对方机器的密码
Now try logging into the machine, with "ssh 'root@node2'", and check in:
~/.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
在HA2上做同上的操作,我就不具体演示了!
在HA2上做同上的操作,我就不具体演示了!
三、配置yum源,我使用的是163做的镜像源
http://mirrors.163.com/
这上面有对应fedora的yum源配置使用的说明,我就不做详细阐述了
如果你没有DNS解析域名,还要在/etc/hosts文件中手动添加解析奥,我的如下:
66.35.62.166 mirrors.fedoraproject.org
213.129.242.84 mirrors.rpmfusion.org
123.58.173.106 mirrors.163.com
这些对应的域名和IP关系大家都会,就是使用ping可以解析出,不解释!
http://mirrors.163.com/
这上面有对应fedora的yum源配置使用的说明,我就不做详细阐述了
如果你没有DNS解析域名,还要在/etc/hosts文件中手动添加解析奥,我的如下:
66.35.62.166 mirrors.fedoraproject.org
213.129.242.84 mirrors.rpmfusion.org
123.58.173.106 mirrors.163.com
这些对应的域名和IP关系大家都会,就是使用ping可以解析出,不解释!
四、安装集群软件
两个节点上都要做的
#yum install corosync pacemaker -y //由于是网络镜像,会比较慢,耐心等会吧!
两个节点上都要做的
#yum install corosync pacemaker -y //由于是网络镜像,会比较慢,耐心等会吧!
安装完成之后就是配置了,注意配置的时候选择的端口和地址不能跟已存在的集群冲突,所
以我就做了一下简单的设置
#export ais_port=4000
#export ais_mcast=226.94.1.1
#export ais_port=4000
#export ais_mcast=226.94.1.1
接下来就是配置corosync了:
#cd /etc/corosync/
#cp corosync.conf.example corosync.conf
#vim !$ 把配置改成如下
# Please read the corosync.conf.5 manual page
compatibility: whitetank
#cd /etc/corosync/
#cp corosync.conf.example corosync.conf
#vim !$ 把配置改成如下
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.1.0 //指定集群所在的网段的网络号
mcastaddr: 226.94.1.1 //组播地址
mcastport: 4000 //端口号
ttl: 1
}
}
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.1.0 //指定集群所在的网段的网络号
mcastaddr: 226.94.1.1 //组播地址
mcastport: 4000 //端口号
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
to_syslog: no
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
####以下是添加的内容
service {
ver: 1 //定义pacemaker的版本,fedora上使用版本1,而在redhat上可以
fileline: off
to_stderr: no
to_logfile: yes
to_syslog: no
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
####以下是添加的内容
service {
ver: 1 //定义pacemaker的版本,fedora上使用版本1,而在redhat上可以
使用0
name: pacemaker
}
aisexec {
user: root
group: root
}
其中注释的内容为所修改的内容
配置完成之后,拷贝一个到另一个节点上
#scp -p /etc/corosync/corosync.conf node2:/etc/corosync/
name: pacemaker
}
aisexec {
user: root
group: root
}
其中注释的内容为所修改的内容
配置完成之后,拷贝一个到另一个节点上
#scp -p /etc/corosync/corosync.conf node2:/etc/corosync/
确保没有错误的情况下,可以在HA1上启动了,启动之后还要进行一些列的检测
#/etc/init.d/corosync start
#/etc/init.d/corosync start
添加认证密钥
#corosync-keygen //这个要是新机器的话,时间会长一点,要有点耐性等待!
#scp -p authkeys corosync.conf node2:/etc/corosync/
配置完成之后,现在HA1上启动corosync:
#server corosync start
Starting corosync (via systemctl): [ OK ] oK,corosync
#corosync-keygen //这个要是新机器的话,时间会长一点,要有点耐性等待!
#scp -p authkeys corosync.conf node2:/etc/corosync/
配置完成之后,现在HA1上启动corosync:
#server corosync start
Starting corosync (via systemctl): [ OK ] oK,corosync
服务启动成功!
接下来就是检测集群是否正确启动并且已经可以和其他节点建立集群关系了:
查看corosync引擎是否正常启动:
[root@node1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file"
接下来就是检测集群是否正确启动并且已经可以和其他节点建立集群关系了:
查看corosync引擎是否正常启动:
[root@node1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file"
/var/log/messages
Sep 18 23:09:44 node1 smartd[786]: Opened configuration file /etc/smartd.conf
Sep 19 13:41:03 node1 smartd[801]: Opened configuration file /etc/smartd.conf
Sep 19 20:44:55 node1 smartd[680]: Opened configuration file /etc/smartd.conf
[root@node1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file"
Sep 18 23:09:44 node1 smartd[786]: Opened configuration file /etc/smartd.conf
Sep 19 13:41:03 node1 smartd[801]: Opened configuration file /etc/smartd.conf
Sep 19 20:44:55 node1 smartd[680]: Opened configuration file /etc/smartd.conf
[root@node1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file"
/var/log/cluster/corosync.log
Sep 18 17:12:06 corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and
Sep 18 17:12:06 corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and
ready to provide service.
Sep 18 17:12:06 corosync [MAIN ] Successfully read main configuration file
Sep 18 17:12:06 corosync [MAIN ] Successfully read main configuration file
'/etc/corosync/corosync.conf'.
Sep 18 17:12:06 corosync [MAIN ] Corosync Cluster Engine exiting with status 8
Sep 18 17:12:06 corosync [MAIN ] Corosync Cluster Engine exiting with status 8
at main.c:1702.
Sep 18 17:16:11 corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and
Sep 18 17:16:11 corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and
ready to provide service.
查看初始化成员节点通知是否正常发出:
[root@node1 ~]# grep TOTEM /var/log/cluster/corosync.log
[root@node1 ~]# grep TOTEM /var/log/cluster/corosync.log
检查启动过程中是否有错误产生:
[root@node2 ~]# grep ERROR: /var/log/cluster/corosync.log | grep -v
[root@node2 ~]# grep ERROR: /var/log/cluster/corosync.log | grep -v
unpack_resources
查看pacemaker是否正常启动:
[root@node1 ~]# grep pcmk_startup /var/log/cluster/corosync.log
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Sep 19 13:48:48 corosync [pcmk ] Logging: Initialized pcmk_startup
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: Maximum core file size is:
[root@node1 ~]# grep pcmk_startup /var/log/cluster/corosync.log
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Sep 19 13:48:48 corosync [pcmk ] Logging: Initialized pcmk_startup
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: Maximum core file size is:
4294967295
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: Service: 9
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: Local hostname: node1.luo
检查完毕,接下来就可以启动另一个节点了,最好在同一个节点上启动所有的其他的集群节
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: Service: 9
Sep 19 13:48:48 corosync [pcmk ] info: pcmk_startup: Local hostname: node1.luo
检查完毕,接下来就可以启动另一个节点了,最好在同一个节点上启动所有的其他的集群节
点:
[root@node1 ~]# ssh node2 -- '/etc/init.d/corosync start'
Starting corosync (via systemctl): [ OK ]
启动成功了!
[root@node1 ~]# ssh node2 -- '/etc/init.d/corosync start'
Starting corosync (via systemctl): [ OK ]
启动成功了!
接下来就是启动pacemaker了!
[root@node1 corosync]# /etc/init.d/pacemaker start
Starting pacemaker (via systemctl): [ OK ]
ok,同样启动成功
[root@node1 corosync]# /etc/init.d/pacemaker start
Starting pacemaker (via systemctl): [ OK ]
ok,同样启动成功
# ps axf //查看进程
1724 ? R 5:59 /usr/lib/heartbeat/stonithd
1725 ? R 5:59 /usr/lib/heartbeat/cib
1726 ? S 0:00 /usr/lib/heartbeat/lrmd
1727 ? R 5:59 /usr/lib/heartbeat/attrd
1728 ? S 0:00 /usr/lib/heartbeat/pengine
1729 ? R 5:59 /usr/lib/heartbeat/crmd
可以看出已经有进程了
1724 ? R 5:59 /usr/lib/heartbeat/stonithd
1725 ? R 5:59 /usr/lib/heartbeat/cib
1726 ? S 0:00 /usr/lib/heartbeat/lrmd
1727 ? R 5:59 /usr/lib/heartbeat/attrd
1728 ? S 0:00 /usr/lib/heartbeat/pengine
1729 ? R 5:59 /usr/lib/heartbeat/crmd
可以看出已经有进程了
当然这个时候有个关键性的设置,就是关闭防火墙,如果你没有关闭防火墙功能,下面将会
给你带来很大的麻烦,我开始就是没有关闭防火墙,后来看日志才知道,所以你做的时候可
以把防火墙先关闭了,但是在真正应用之中,还是要开启防火墙功能
#setup 然后在里面选择Firewall configure 然后disabled就行了
#setup 然后在里面选择Firewall configure 然后disabled就行了
接下来使用crm的内部命令进行查看
#crm_mon 或crm status
Online: [ node2.linuxidc.com node1.linuxidc.com ]可以看出,集群的节点都启动了
#crm_mon 或crm status
Online: [ node2.linuxidc.com node1.linuxidc.com ]可以看出,集群的节点都启动了
一切准备停当,接下来就是双主集群的配置了!
五、安装apache服务和集群文件系统-GFS2
为了方便验证,我就安装一个apache服务用于测试:
#yum install httpd -y
在HA1上的添加测试页面:
#echo "<h1>node1.linuxidc.com<h1>" >/var/www/html/index.html
在HA2上的添加测试页面:
#echo "<h1>node2.linuxidc.com<h1>" >/var/www/html/index.html
然后把两个节点上的/etc/httpd/conf/httpd.conf的配置文件,保持一下的内容是开启的,
为了方便验证,我就安装一个apache服务用于测试:
#yum install httpd -y
在HA1上的添加测试页面:
#echo "<h1>node1.linuxidc.com<h1>" >/var/www/html/index.html
在HA2上的添加测试页面:
#echo "<h1>node2.linuxidc.com<h1>" >/var/www/html/index.html
然后把两个节点上的/etc/httpd/conf/httpd.conf的配置文件,保持一下的内容是开启的,
如果有注释的,请去掉注释
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
保证httpd服务不会随着开机自动启动
#chkconfig httpd off
#chkconfig httpd off
#crm configure property stonith-enabled=false //关闭stonith设备
#crm configure property no-quorum-policy=ignore //关闭两节点之间的选举
#crm configure
#crm configure property no-quorum-policy=ignore //关闭两节点之间的选举
#crm configure
为httpd添加资源
# crm configure primitive WebSite ocf:heartbeat:apache params
# crm configure primitive WebSite ocf:heartbeat:apache params
configfile=/etc/httpd/conf/httpd.conf op monitor interval=1min
# crm configure primitive ClusterIP ocf:heartbeat:IPaddr2 params
# crm configure primitive ClusterIP ocf:heartbeat:IPaddr2 params
ip=192.168.1.110 cidr_netmask=32 op monitor interval=30s //添加一个虚拟IP
[root@node1 ~]# crm status
============
Last updated: Mon Sep 19 23:44:05 2011
Stack: openais
Current DC: node2.linuxidc.com - partition with quorum
Version: 1.1.5-1.fc15-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
[root@node1 ~]# crm status
============
Last updated: Mon Sep 19 23:44:05 2011
Stack: openais
Current DC: node2.linuxidc.com - partition with quorum
Version: 1.1.5-1.fc15-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node2.linuxidc.com node1.linuxidc.com ]
ClusterIP (ocf::heartbeat:IPaddr2): Started node1.linuxidc.com
WebSite (ocf::heartbeat:apache): Started node2.linuxidc.com
可以看到两个资源不在同一个节点上,所以需要做一下的设置:
#crm configure colocation website-with-ip INFINITY: WebSite ClusterIP //做一个
WebSite (ocf::heartbeat:apache): Started node2.linuxidc.com
可以看到两个资源不在同一个节点上,所以需要做一下的设置:
#crm configure colocation website-with-ip INFINITY: WebSite ClusterIP //做一个
位置约束
然后再使用crm status 查看资源已经都流转到同一个节点上了,如下所示
Online: [ node2.linuxidc.com node1.linuxidc.com ]
然后再使用crm status 查看资源已经都流转到同一个节点上了,如下所示
Online: [ node2.linuxidc.com node1.linuxidc.com ]
ClusterIP (ocf::heartbeat:IPaddr2): Started node1.linuxidc.com
WebSite (ocf::heartbeat:apache): Started node1.linuxidc.com
还要控制资源的启动停止顺序
#crm configure order apache-after-ip mandatory: ClusterIP WebSite //定义ip的资
WebSite (ocf::heartbeat:apache): Started node1.linuxidc.com
还要控制资源的启动停止顺序
#crm configure order apache-after-ip mandatory: ClusterIP WebSite //定义ip的资
源要在apache的服务启动之前启动
指定优先的Location
#crm configure location prefer-pcmk-l WebSite 50: node1.linuxidc.com
#crm configure location prefer-pcmk-l WebSite 50: node1.linuxidc.com
#crm configure show //查看一下自己的配置如下
[root@node1 ~]# crm configure show
node node1.linuxidc.com
node node2.linuxidc.com
primitive ClusterIP ocf:heartbeat:IPaddr2 \
params ip="192.168.1.110" cidr_netmask="32" \
op monitor interval="30s"
primitive WebSite ocf:heartbeat:apache \
params configfile="/etc/httpd/conf/httpd.conf" \
op monitor interval="1min"
location prefer-pcmk-l WebSite 50: node1.linuxidc.com
colocation website-with-ip inf: WebSite ClusterIP
order apache-after-ip inf: ClusterIP WebSite
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.fc15-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
resource-stickiness="100"
如上图所示,资源已经启动了,所以接下来就可以往下做了!
可以在浏览其中输入http://192.168.1.110可以访问web服务了!
[root@node1 ~]# crm configure show
node node1.linuxidc.com
node node2.linuxidc.com
primitive ClusterIP ocf:heartbeat:IPaddr2 \
params ip="192.168.1.110" cidr_netmask="32" \
op monitor interval="30s"
primitive WebSite ocf:heartbeat:apache \
params configfile="/etc/httpd/conf/httpd.conf" \
op monitor interval="1min"
location prefer-pcmk-l WebSite 50: node1.linuxidc.com
colocation website-with-ip inf: WebSite ClusterIP
order apache-after-ip inf: ClusterIP WebSite
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.fc15-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
resource-stickiness="100"
如上图所示,资源已经启动了,所以接下来就可以往下做了!
可以在浏览其中输入http://192.168.1.110可以访问web服务了!
相关推荐
星愿心愿 2020-11-24
rikeyone 2020-11-04
一路到黑 2020-10-30
89437401 2020-10-29
86417413 2020-11-25
89612310 2020-11-09
tianyayi 2020-08-16
83911930 2020-07-28
89612310 2020-07-27
CNxuwang 2020-07-20
86477414 2020-06-28
TuxedoLinux 2020-06-17
87354452 2020-06-10
行万里 2020-06-09
jLawrencee 2020-05-19
songxiugongwang 2020-03-07
hahhah0 2020-05-08
zhiliang 2020-04-23