Linux 高可用(HA)集群之Corosync详解(3)

三、Corosync 详细配置
1.提供配置文件

[root@node1 ~]# cd /etc/corosync/ 
[root@node1 corosync]# ll   
总用量 24   
-rw-r--r-- 1 root root  445 5月  15 05:09 corosync.conf.example   
-rw-r--r-- 1 root root 1084 5月  15 05:09 corosync.conf.example.udpu   
drwxr-xr-x 2 root root 4096 5月  15 05:09 service.d   
drwxr-xr-x 2 root root 4096 5月  15 05:09 uidgid.d

注:大家可以看到提供一个样例文件corosync.conf.example

[root@node1 corosync]# cp corosync.conf.example corosync.conf

2.修改配置文件
[root@node1 corosync]# cat corosync.conf 
# Please read the corosync.conf.5 manual page   
compatibility: whitetank
totem { 
    version: 2   
    secauth: on #启动认证   
    threads: 2   
    interface {   
        ringnumber: 0   
        bindnetaddr: 192.168.18.0 #修改心跳线网段   
        mcastaddr: 226.99.10.1 #组播传播心跳信息   
        mcastport: 5405   
        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   
}
#启用pacemaker
service { 
    ver: 0   
    name: pacemaker   
}
aisexec { 
    user: root   
    group: root   
}

注:用 man corosync.conf 可以查看所有选项的意思。
3.生成密钥文件
注:corosync生成key文件会默认调用/dev/random随机数设备,一旦系统中断的IRQS的随机数不够用,将会产生大量的等待时间,因此,为了节约时间,我们在生成key之前讲random替换成urandom,以便节约时间。
[root@node1 corosync]# mv /dev/{random,random.bak}   
[root@node1 corosync]# ln -s /dev/urandom /dev/random
[root@node1 corosync]# corosync-keygen   
Corosync Cluster Engine Authentication key generator.   
Gathering 1024 bits for key from /dev/random.   
Press keys on your keyboard to generate entropy.   
Writing corosync key to /etc/corosync/authkey.

4.查看生成的key文件
[root@node1 corosync]# ll 
总用量 24   
-r-------- 1 root root  128 8月  13 14:16 authkey   
-rw-r--r-- 1 root root  521 8月  13 11:11 corosync.conf   
-rw-r--r-- 1 root root  445 5月  15 05:09 corosync.conf.example   
-rw-r--r-- 1 root root 1084 5月  15 05:09 corosync.conf.example.udpu   
drwxr-xr-x 2 root root 4096 5月  15 05:09 service.d   
drwxr-xr-x 2 root root 4096 5月  15 05:09 uidgid.d

5.将key文件authkey与配置文件corosync.conf复制到node2上
[root@node1 corosync]# scp -p authkey corosync.conf node2:/etc/corosync/ 
authkey                                                                                100%  128    0.1KB/s  00:00   
corosync.conf                                                                          100%  521    0.5KB/s  00:00 
[root@node2 ~]# cd /etc/corosync/ 
[root@node2 corosync]# ll   
总用量 24   
-r-------- 1 root root  128 8月  13 14:16 authkey   
-rw-r--r-- 1 root root  521 8月  13 11:11 corosync.conf   
-rw-r--r-- 1 root root  445 5月  15 05:09 corosync.conf.example   
-rw-r--r-- 1 root root 1084 5月  15 05:09 corosync.conf.example.udpu   
drwxr-xr-x 2 root root 4096 5月  15 05:09 service.d   
drwxr-xr-x 2 root root 4096 5月  15 05:09 uidgid.d

注:corosync 到这里配置全部完成。下面我们进行启动测试!
四、Corosync 启动信息
1.启动corosync

[root@node1 ~]# ssh node2 "service corosync start" 
Starting Corosync Cluster Engine (corosync): [确定]   
[root@node1 ~]# service corosync start   
Starting Corosync Cluster Engine (corosync):              [确定]

2.查看corosync启动信息

(1).查看corosync引擎是否正常启动
[root@node1 ~]# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log   
Aug 13 14:20:15 corosync [MAIN  ] Corosync Cluster Engine ('1.4.1'): started and ready to provide service.   
Aug 13 14:20:15 corosync [MAIN  ] Successfully read main configuration file '/etc/corosync/corosync.conf'.   
Aug 13 17:08:51 corosync [MAIN  ] Corosync Cluster Engine ('1.4.1'): started and ready to provide service.   
Aug 13 17:08:51 corosync [MAIN  ] Successfully read main configuration file '/etc/corosync/corosync.conf'.   
Aug 13 17:08:51 corosync [MAIN  ] Corosync Cluster Engine exiting with status 18 at main.c:1794.

(2).查看初始化成员节点通知是否正常发出

[root@node1 ~]# grep  TOTEM /var/log/cluster/corosync.log   
Aug 13 14:20:15 corosync [TOTEM ] Initializing transport (UDP/IP Multicast).   
Aug 13 14:20:15 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).   
Aug 13 14:20:15 corosync [TOTEM ] The network interface [192.168.18.201] is now up.   
Aug 13 14:20:15 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.   
Aug 13 14:20:40 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.

(3).检查启动过程中是否有错误产生

[root@node1 ~]# grep ERROR: /var/log/cluster/corosync.log   
Aug 13 14:20:15 corosync [pcmk  ] ERROR: process_ais_conf: You have configured a cluster using the Pacemaker plugin for Corosync. The plugin is not supported in this environment and will be removed very soon.   
Aug 13 14:20:15 corosync [pcmk  ] ERROR: process_ais_conf:  Please see Chapter 8 of 'Clusters from Scratch' () for details on using Pacemaker with CMAN

(4).查看pacemaker是否正常启动
[root@node1 ~]# grep pcmk_startup /var/log/cluster/corosync.log   
Aug 13 14:20:15 corosync [pcmk  ] info: pcmk_startup: CRM: Initialized   
Aug 13 14:20:15 corosync [pcmk  ] Logging: Initialized pcmk_startup   
Aug 13 14:20:15 corosync [pcmk  ] info: pcmk_startup: Maximum core file size is: 18446744073709551615   
Aug 13 14:20:15 corosync [pcmk  ] info: pcmk_startup: Service: 9   
Aug 13 14:20:15 corosync [pcmk  ] info: pcmk_startup: Local hostname: node1.test.com

3.查看集群状态
[root@node1 ~]# crm_mon
Last updated: Tue Aug 13 17:41:31 2013 
Last change: Tue Aug 13 14:20:40 2013 via crmd on node1.test.com   
Stack: classic openais (with plugin)   
Current DC: node2.test.com - partition with quorum   
Version: 1.1.8-7.el6-394e906   
2 Nodes configured, 2 expected votes   
0 Resources configured.
Online: [ node1.test.com node2.test.com ]

注:大家可以看到,集群运行正常,node1与node2都在线,DC是node2节点。但是还没有配置资源,配置资源就要用到pacemaker,在下一篇博客中我们重点讲解pacemaker使用。用pacemaker来增加各种资源。^_^……

linux

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2c9adace79125eb1a033b06fa13f956d.html