pcs+pacemaker+corosync 配置http主從高可用
mysql-01 | 192.168.1.153 |
mysql-02 | 192.168.1.154 |
vip | 192.168.1.160 |
os | rhel 7.2 |
參考 http://www.361way.com/rhel7-pcsd-ha/5260.html
1、初始化系統 節點1&2
# systemctl disable firewalld
# vi /etc/selinux/config
SELINUX=disabled |
# hostnamectl set-hostname mysql-01 # mysql-02
# yum -y install chrony pacemaker pcs fence-agents-all httpd
# systemctl enable chronyd
# systemctl start chronyd
# vi /etc/hosts
192.168.1.153 mysql-01 192.168.1.154 mysql-02 |
# reboot
2、pcs 配置
# echo"redhat" |passwd --stdin hacluster # 節點1&2,修改 hacluster 密碼
# systemctl start pcsd.service # 節點1&2
# systemctl status pcsd.service # 節點1&2
# pcs clusterauth mysql-01 mysql-02 -u hacluster -p redhat # 節點1 認證配置
# pcs clustersetup --name mycluster mysql-01 mysql-02 # 節點1 生成叢集檔案,另一節點會自動生成
# cat /etc/corosync/corosync.conf
3、pcs叢集服務啟動
# pcs status
Error: cluster is not currently running on this node |
# pcs clusterstart --all # 啟動叢集服務
# pcs cluster enable --all # 設定開機自啟動
# pcs status
# 檢視狀态,節點是否online,daemon是否都active 與 enabled,若沒有則手動 systemctl enable *
Cluster name: mycluster Stack: corosync Current DC: mysql-01 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum Last updated: Fri Oct 27 08:05:10 2017 Last change: Thu Oct 26 15:39:23 2017 by root via cibadmin on mysql-01 2 nodes configured 2 resources configured Online: [ mysql-01 mysql-02 ] Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled |
4、resource 資源配置 節點1
# pcs resource create VirtIP IPAddr ip=192.168.1.160 cidr_netmask=24op monitor interval=30s
# pcs resource create Httpd apacheconfigfile="/etc/httpd/conf/httpd.conf"
# pcs constraint colocation add Httpd with VirtIP INFINITY # 啟用 resource 資源
# pcs property set stonith-enabled=false
# pcs property set no-quorum-policy=ignore
# pcs property set default-resource-stickiness="INFINITY"
# pcs statusresources # 檢視狀态
VirtIP (ocf::heartbeat:IPaddr): Started mysql-01 Httpd (ocf::heartbeat:apache): Started mysql-01 |
# ip a # 在 mysql-01 上檢視vip
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16780032: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 00:50:56:a7:26:00 brd ff:ff:ff:ff:ff:ff inet 192.168.1.153/24 brd 192.168.1.255 scope global eno16780032 valid_lft forever preferred_lft forever inet 192.168.1.160/24 brd 192.168.1.255 scope global secondary eno16780032 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fea7:2600/64 scope link valid_lft forever preferred_lft forever |
# ps -ef | grep http # 檢視 http 程序是否啟動
5、開啟 web 管理頁面 節點1&2
# vi /usr/lib/pcsd/ssl.rb
webrick_options = { :Port => 2224, #:BindAddress => primary_addr, #:Host => primary_addr, :BindAddress => '0.0.0.0', :Host => '0.0.0.0', :SSLEnable => true, :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE, :SSLCertificate => OpenSSL::X509::Certificate.new(crt), :SSLPrivateKey => OpenSSL::PKey::RSA.new(key), :SSLCertName => [[ "CN", server_name ]], :SSLOptions => get_ssl_options(), } |
# systemctl restart pcsd
# netstat -tunlp # 檢視 2224 端口是否啟用
# web 端登入 https://192.168.1.153:2224
# 輸入賬号密碼 hacluster / redhat
# + ADDExisting
6、測試
# 手動shutdown 節點1,看vip是否漂移,http服務是否啟用等(略)