corosync+pacemaker雙機同步

環境  :兩臺服務器版本:centos7(64)

IP分配:192.168.1.204(主 web1) 192.168.1.205(備份 web2) 192.168.1.206(VIP)

需要的rpm包安裝:http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/x86_64/


關閉防火牆:

vi /etc/selinux/config

SELINUX=disable


關閉selinux:
systemctl stop firewalld

systemctl disable firewalld


web1服務器環境配置:

yum install "python*" corosync* pacemaker*  rsync -y

rpm -ivh crmsh-2.1.4-1.1.x86_64.rpm


配置時間同步:

yum install ntpdate ntp -y

rm -fr /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

vi /etc/ntp.conf (server cn.pool.ntp.org)添加中國時間

        # Please consider joining the pool (http://www.pool.ntp.org/join.html).
        server cn.pool.ntp.org

ntpdate -d cn.pool.ntp.org 檢查差異時間

ntpdate cn.pool.ntp.org  同步時間

vi /etc/sysconfig/ntpd:SYNC_HWCLOCK=yes 添加硬件時鐘

chkconfig --levels 235 ntpd on

systemctl restart  ntpd

設置本地解析:
192.168.1.204 web1
192.168.1.205 web2

ssh設置互信:

ssh-keygen -t rsa

將生成id_rsa.pub互傳對方/root/.ssh/更名爲:authorized_keys

修改corosync.conf:

[root@web1 tools]# cat /etc/corosync/corosync.conf
compatibility: whitetank  
  totem {  
  version:                             2  
  token:                               3000  
  token_retransmits_before_loss_const: 10  
  join:                                60  
  consensus:                           3600  
  vsftype:                             none  
  max_messages:                        20  
  clear_node_high_bit:                 yes  
  rrp_mode:                            none  
  secauth:                             on  
  threads:                             2  
  interface {  
    ringnumber:  0  
    bindnetaddr: 192.168.1.0
    mcastaddr:   239.32.12.5  
    mcastport:   5405  
  }  
}  
 
logging {  
  fileline:        off  
  to_stderr:       yes  
  to_logfile:      yes  
  to_syslog:       no  
  logfile: /var/log/cluster/corosync.log  
  syslog_facility: daemon  
  debug:           off  
  timestamp:       on  
  logger_subsys {  
    subsys: AMF  
    debug:  off  
    tags:   enter|leave|trace1|trace2|trace3|trace4|trace6  
  }  
}  
 
 
amf {  
  mode: disabled  
}  
 
aisexec {  
  user:  root  
  group: root  
}  
       quorum {  
           provider: corosync_votequorum  
           expected_votes: 2  
           two_node: 1  
       }

   mv /dev/{random,random.bak}

   ln -s /dev/urandom /dev/random

   corosync-keygen

   scp -p authkey corosync.conf [email protected]:/etc/corosync 將web1文件傳送至web2

啓動corosync:

  ssh web2 "systemctl start corosync "

  systemctl start corosync

  啓動pacemaker
   systemctl start pacemaker


出現 錯誤:
    Last updated: Mon May  4 14:43:13 2015
    Last change: Mon May  4 14:26:45 2015
    Current DC: NONE
    0 Nodes configured
    0 Resources configured    增加在corosync文件底部即可:     

            quorum {  
           provider: corosync_votequorum  
           expected_votes: 2  
           two_node: 1  
       }

crm操作:

crm(live)configure# property stonith-enabled=false
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=192.168.1.206
crm(live)configure# commit


2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:69:ab:ad brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.204/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.1.206/24 brd 192.168.1.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe69:abad/64 scope link

可以看到VIP已經添加上去,即可使用VIP訪問,實驗關閉服務自動切換


wKioL1Vm4BmhnYGJAAHCm74OOUI653.jpg

如果出現腦裂,vip無法跳轉,重啓雙機corosync/pacemaker服務


關於pacemaker服務資源調度:

強行停止服務kill掉服務,不會自動重啓;因爲,節點沒有故障,所有資源不會轉移,默認情況下,pacemaker不會對任何資源進行監控,所以,即便是資源關掉了,只要節點沒有故障,資源依然不會轉移;要想達到資源轉移的目的,得定義監控(monitoer);http://www.it165.net/admin/html/201405/3066.html

   

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章