corosync v2 + pacemaker + crmsh 實現mariadb高可用

高可用mariadb拓撲圖

corosync+pacemaker+crmsh+mariadb.png

一、設計前提

    1、時間同步 # ntpdate 172.16.0.1 或者 # chronyc sources

    2、所有的主機對應的IP地址解析可以正常工作, 主機名要與命令#uname -n 所得的結果一致

         因此,/etc/hosts中的內容為以下內容

        172.16.23.10 node1.rj.com node1 
	    172.16.23.11 node2.rj.com node2 
        172.16.23.12 node3.rj.com node3

二、環境的建立及安裝orosync ,pacemaker ,crmsh 

        三臺機器都安裝好ansible (對于ansible集群管理工具而言需要雙機互信,其中node1當做堡壘機)

	# ssh-keygen  
	# for i in {10..12}; do ssh-copy-id -i 172.16.23.$i ; done ; 此條命令將公鑰發送給三臺機器,其中包括自己也就是堡壘機
	# vim /etc/ansible/hosts 
		[mariadb]
		172.16.23.10
		172.16.23.11
		172.16.23.12
	# ansible mariadb -m ping 測試三臺主機與堡壘機之間的連通性 
	# vim /etc/hosts 主機名解析配置
		172.16.23.10 node1.rj.com node1
		172.16.23.11 node2.rj.com node2
		172.16.23.12 node3.rj.com node3
	# ansible mariadb -m command -a "ntpdate 172.16.0.1"  同步三臺主機的時間 
	# ansible mariadb -m yum -a "name=pacemaker,mariadb-server state=present" 在三臺主機上安裝 mariadb ,corosync 和 pacemaker

        注:yum 安裝pacemaker 的時候,其corosync也會自動安裝上

        # vim /etc/corosync/corosync.conf 
		加入以下信息
		totem {
			version: 2
			crypto_cipher: aes256
			crypto_hash: sha1
			interface {
				ringnumber: 0
				bindnetaddr: 172.16.0.0
				mcastaddr: 239.255.23.1
				mcastport: 5405
				ttl: 1
			}
		logging {
			fileline: off
			to_stderr: no
			to_logfile: yes
			logfile: /var/log/cluster/corosync.log
			to_syslog: no
			debug: off
			timestamp: on
			logger_subsys {
				subsys: QUORUM
				debug: off
			}
		quorum {
			provider: corosync_votequorum
			node {
				ring0_addr: node1.rj.com
				nodeid:1 
			}
			node {
				ring0_addr: node2.rj.com
				nodeid:2 
			}
			
			node {
				ring0_addr: node3.rj.com
				nodeid:3
				}
				
    # corosync-keygen 
	# ansible mariadb -m copy -a "src=/etc/corosync/authkey dest=/etc/corosync/"
	# ansible mariadb -m copy -a "src=/etc/corosync/corosync.conf dest=/etc/corosync/"
	# ansible mariadb -m service -a "name=corosync state=persent"
	# ansible mariadb -m service -a "name=pacemaker state=persent"
	#  tcpdump -i eno16777736 -nn port 5405

        使用tcpdump抓包工具可以來查看三臺主機之間傳遞的心跳信息

ttttttt.png

        注:mariadb在集群資源的配置中必需是開機自啟動的

        這樣corosync才能實別其Unitfile 文件,而不能在配置前啟動所以服務一定是關閉的

	# ansible mariadb -m service -a "name=mariadb enabled=on"
	# ansible mariadb -m service -a "name=corosync enabled=on"
    # ansible mariadb -m service -a "name=pacemaker enabled=on"
	# mkdir rpm && cd rpm 
	# wget 172.18.0.1/pub/Sources/7.x86_64/crmsh/crmsh-2.1.4-1.1.x86_64.rpm 下載crmsh及其所依賴的rpm包 
	# wget 172.18.0.1/pub/Sources/7.x86_64/crmsh/pssh*.rpm
	# wget 172.18.0.1/pub/Sources/7.x86_64/crmsh/python-passh*.rpm 
	# ansible mariadb -m copy -a "src=/root/rpm dest=/root/"
	# for i in {1..3}; do ssh node$i yum -y install /root/rpm/*; done

        查看corosync引擎是否已經正常啟動

        # ansible mariadb -e command -a "grep -e 'Corosync Cluster Engine' -e 'configuration file' /var/log/messages" 
        	Feb 13 11:27:35 node1 systemd: Stopped Corosync Cluster Engine.
        	Feb 13 14:08:03 node1 systemd: Starting Corosync Cluster Engine...
        	Feb 13 14:08:04 node1 corosync: Starting Corosync Cluster Engine (corosync): [  OK  ]
        	Feb 13 14:08:04 node1 systemd: Started Corosync Cluster Engine.
        	Feb 13 14:28:16 node1 systemd: Mounted NFSD configuration filesystem.
        	Feb 13 14:28:44 node1 smartd[787]: Opened configuration file /etc/smartmontools/smartd.conf
        	Feb 13 14:32:12 node1 systemd: Starting Corosync Cluster Engine...
        	Feb 13 14:32:13 node1 corosync: Starting Corosync Cluster Engine (corosync): [  OK  ]
        	Feb 13 14:32:13 node1 systemd: Started Corosync Cluster Engine.
        	Feb 13 14:43:03 node1 systemd: Started Corosync Cluster Engine.

        查看其成員之間的結點通知信息是否正常 

        # ansible mariadb -e command -a "grep TOTEM /var/log/messages"

        查看啟動過程中是否有錯誤信息產生 

        # ansible mariadb -e command -a "grep 'ERROR' /var/log/messages"

        查看pacemaker是否已經正常啟動

        # ansible mariadb -e command -a "grep 'pacemaker' /var/log/messages "

        使用以下命令查看結點的狀態

        # crm status  
		Last updated: Mon Feb 13 15:43:08 2017		Last change: Mon Feb 13 14:33:58 2017 by hacluster via crmd on node3.rj.com
		Stack: corosync
		Current DC: node3.rj.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum
		3 nodes and 0 resources configured

		Online: [ node1.rj.com node2.rj.com node3.rj.com ]

        查看pacemaker 和與corosync所啟動的進程 

        # ansible mariadb -m command -a "ps auxf " | grep pacemaker
		root       1720  0.0  1.3 130484  6384 ?        Ss   14:33   0:00 /usr/sbin/pacemakerd -f
		haclust+   1729  0.0  2.7 132816 13268 ?        Ss   14:33   0:01  \_ /usr/libexec/pacemaker/cib
		root       1730  0.0  1.4 133968  6956 ?        Ss   14:33   0:00  \_ /usr/libexec/pacemaker/stonithd
		root       1731  0.0  0.8 102936  4108 ?        Ss   14:33   0:00  \_ /usr/libexec/pacemaker/lrmd
		haclust+   1732  0.0  1.3 124780  6736 ?        Ss   14:33   0:00  \_ /usr/libexec/pacemaker/attrd
		haclust+   1733  0.0  0.7 114896  3668 ?        Ss   14:33   0:00  \_ /usr/libexec/pacemaker/pengine
		haclust+   1734  0.0  1.5 143160  7484 ?        Ss   14:33   0:00  \_ /usr/libexec/pacemaker/crmd
        # ansible marriadb -m command -a "ps auxf" | grep corosync 
	     root       1483  0.6  7.9 134848 38436 ?        Ssl  14:32   0:28 corosync

三、利用crmsh來配置corosync的IP地址資源及mariadb資源  

        如果想要查看某種類別下的所用資源代理的列表,可以使用類似以下的命令來實現

    #crm ra list lsb 
	#crm ra list ocf heartbeat 
	#crm ra list ocf pacemaker 
	#crm ra list ocf stonith

配置vip 

    # crm configure property stonith-enabled=false 關閉stonsth設備
	# crm configure primitive DBIP ocf:heartbeat:IPaddr params ip=172.16.23.23 添加vip資源代理  
	# crm configure verify 查看是否有錯誤
	# crm configure commit 用來提交配置信息 
	# crm configure show  可以用來查看配置信息
		node 1: node1.rj.com
		node 2: node2.rj.com
		node 3: node3.rj.com
		primitive DBIP IPaddr \
			params ip=172.16.23.23
		property cib-bootstrap-options: \
			have-watchdog=false \
			dc-version=1.1.13-10.el7-44eb2dd \
			cluster-infrastructure=corosync \
			stonith-enabled=false
	# crm node standby node1.rj.com	當將node1結點成為備用結點時 
	# ansible mariadb -m command -a "ip addr list" 查看其vip的變化信息
	# crm ra info systemd:mairadb 用來查看systemd類型的mariadb資源的語法格式 
		systemd unit file for mariadb (systemd:mariadb)

		MariaDB database server

		Operations' defaults (advisory minimum):

			start         timeout=15
			stop          timeout=15
			status        timeout=15
			restart       timeout=15
			monitor       timeout=15 interval=15 start-delay=15

vip資源 

node1 noline pirector.png 

    當node1 # crm node standby node1.rj.com 時

ansible 查看vip信息.png

       定義mariadbg資源并設定監控

	# crm configure primitive MDB systemd:mariadb op start timeout=15s op stop timeout=15s op monitor interval=15s timeout=15s 
	# crm configure group DBservice DBIP MDB
	# crm configure verify 
	# crm configure commit 
	# crm configure show  
		node 1: node1.rj.com \
			attributes standby=on
		node 2: node2.rj.com \
			attributes standby=off
		node 3: node3.rj.com \
			attributes standby=off
		primitive DBIP IPaddr \
			params ip=172.16.23.23
		primitive MDB systemd:mariadb \
			op start timeout=15s interval=0 \
			op stop timeout=15s interval=0 \
			op monitor interval=15s timeout=15s
		group DBservice DBIP MDB
		property cib-bootstrap-options: \
			have-watchdog=false \
			dc-version=1.1.13-10.el7-44eb2dd \
			cluster-infrastructure=corosync \
			stonith-enabled=false \
			no-quorum-policy=ignore

        為mariadb服務加入數據庫資源,并配置遠程用戶遠程接入進行測試 

注:此時有一個資源已經啟動,但其它的兩個mariadb服務啟動之后才能進行對數據庫的更改

               但更改完后旋得再將那兩個結點的數據庫停止調

	node1 node2 node3上執行: #  mysql -e "GRANT ALL  ON *.* TO 'root'@'%.%.%.%' IDENTIFIED BY 'centos.123';" 
	node1 # mysql -e "CREATE DATABASE NODE1"
	node2 # mysql -e "CREATE DATABASE NODE2"
	node3 # mysql -e "CREATE DATABASE NODE3"

        啟用一臺測試機進行測試

test3.png

    node1	# systemctl stop corosync.service pacemaker.service 當node1的服務停止時

test2.png

node2   # systemctl stop corosync.service pacemaker.service 當node2的的服務停止時

test1.png

原創文章,作者:renjin,如若轉載,請注明出處:http://www.www58058.com/68313

(0)
renjinrenjin
上一篇 2014-06-09 12:16
下一篇 2014-08-25 15:47

相關推薦

  • sed編輯器

    sed: Stream EDitor, 行編輯器;  用法: sed [option]… ‘script’ inputfile… script: ‘地址命令‘  常用選項: -n:不輸出模式中的內容至屏幕; -e: 多點編輯; -f /PATH/TO/SCRIPT_F…

    Linux干貨 2015-07-06
  • 阿里巴巴開源項目nginx_concat_module企業部署實例

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1580194        公司的前端開發工程師今天找我,讓我給他搞下淘寶的一個開源項目 nginx_concat_m…

    Linux干貨 2016-08-15
  • ELK+RabbitMQ架構處理nginx及tomcat日志

    前言       查看日志的傳統方法是:登錄操作系統,使用命令工具如cat、tail、sed、awk、grep等等進行過濾輸出后分析,處理少量日志還好,日志量大處理效率就沒那么高了。而且很多情況下開發人員需要查看并分析日志進行排錯,但他們對Linux命令又不是太熟悉,而且有時候又不能賦予他們服務器權限,更多時…

    Linux干貨 2016-08-02
  • 高級文件系統管理之磁盤配額及RAID的運用

    本章內容 設定文件系統配額 設定和管理軟RAID設備 一,概述 配置配額系統: 綜述 在內核中執行 以文件系統為單位啟用 磁盤配額最小單位是以文件系統為單位啟用,就是一個掛載點,而不能以目錄為單位 對不同組或者用戶的策略不同 根據塊或者節點進行限制 執行軟限制(soft limit) 硬限制(hard limit) 初始化 分區掛載選項:usrquota、g…

    Linux干貨 2016-09-07
  • Linux基礎學習總結(五)

    1、顯示當前系統上root、fedora或user1用戶的默認shell; grep -E ‘^(root|fedora|user1)\>’ /etc/passwd | awk -F ‘:’ ‘{print $7}’ 2、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello(); grep -E ‘…

    Linux干貨 2016-10-20
  • linux基礎第二周

    1.?用chattr命令防止系統中某個關鍵文件被修改:# chattr +i /etc/resolv.conf 然后用mv /etc/resolv.conf等命令操作于該文件,都是得到Operation not permitted 的結果。vim編輯該文件時會提示W10: Warning: Changing a readonly file錯誤。要想修改此文件…

    2017-09-09
欧美性久久久久