; corosync v2+pacemaker实现mariadb的高可用 | Linux运维部落

corosync v2+pacemaker实现mariadb的高可用

高可用mariadb拓扑图

corosync+pacemaker+crmsh+mariadb.png

一、设计前提

1、时间同步 # ntpdate 172.16.0.1 或者 # chronyc sources

2、所有的主机对应的IP地址解析可以正常工作, 主机名要与命令#uname -n 所得的结果一致

因此,/etc/hosts中的内容为以下内容

172.16.23.10node1.rj.comnode1
	172.16.23.11node2.rj.comnode2
172.16.23.12node3.rj.comnode3

二、环境的建立及安装orosync ,pacemaker ,crmsh

三台机器都安装好ansible (对于ansible集群管理工具而言需要双机互信,其中node1当做堡垒机)

	#ssh-keygen
	#foriin{10..12};dossh-copy-id-i172.16.23.$i;done;此条命令将公钥发送给三台机器,其中包括自己也就是堡垒机
	#vim/etc/ansible/hosts
		[mariadb]
		172.16.23.10
		172.16.23.11
		172.16.23.12
	#ansiblemariadb-mping测试三台主机与堡垒机之间的连通性
	#vim/etc/hosts主机名解析配置
		172.16.23.10node1.rj.comnode1
		172.16.23.11node2.rj.comnode2
		172.16.23.12node3.rj.comnode3
	#ansiblemariadb-mcommand-a"ntpdate172.16.0.1"同步三台主机的时间
	#ansiblemariadb-myum-a"name=pacemaker,mariadb-serverstate=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
	#ansiblemariadb-mcopy-a"src=/etc/corosync/authkeydest=/etc/corosync/"
	#ansiblemariadb-mcopy-a"src=/etc/corosync/corosync.confdest=/etc/corosync/"
	#ansiblemariadb-mservice-a"name=corosyncstate=persent"
	#ansiblemariadb-mservice-a"name=pacemakerstate=persent"
	#tcpdump-ieno16777736-nnport5405

使用tcpdump抓包工具可以来查看三台主机之间传递的心跳信息

ttttttt.png

注:mariadb在集群资源的配置中必需是开机自启动的

这样corosync才能实别其Unitfile 文件,而不能在配置前启动所以服务一定是关闭的

	#ansiblemariadb-mservice-a"name=mariadbenabled=on"
	#ansiblemariadb-mservice-a"name=corosyncenabled=on"
#ansiblemariadb-mservice-a"name=pacemakerenabled=on"
	#mkdirrpm&&cdrpm
	#wget172.18.0.1/pub/Sources/7.x86_64/crmsh/crmsh-2.1.4-1.1.x86_64.rpm下载crmsh及其所依赖的rpm包
	#wget172.18.0.1/pub/Sources/7.x86_64/crmsh/pssh*.rpm
	#wget172.18.0.1/pub/Sources/7.x86_64/crmsh/python-passh*.rpm
	#ansiblemariadb-mcopy-a"src=/root/rpmdest=/root/"
	#foriin{1..3};dosshnode$iyum-yinstall/root/rpm/*;done

查看corosync引擎是否已经正常启动

#ansiblemariadb-ecommand-a"grep-e'CorosyncClusterEngine'-e'configurationfile'/var/log/messages"
	Feb1311:27:35node1systemd:StoppedCorosyncClusterEngine.
	Feb1314:08:03node1systemd:StartingCorosyncClusterEngine...
	Feb1314:08:04node1corosync:StartingCorosyncClusterEngine(corosync):[OK]
	Feb1314:08:04node1systemd:StartedCorosyncClusterEngine.
	Feb1314:28:16node1systemd:MountedNFSDconfigurationfilesystem.
	Feb1314:28:44node1smartd[787]:Openedconfigurationfile/etc/smartmontools/smartd.conf
	Feb1314:32:12node1systemd:StartingCorosyncClusterEngine...
	Feb1314:32:13node1corosync:StartingCorosyncClusterEngine(corosync):[OK]
	Feb1314:32:13node1systemd:StartedCorosyncClusterEngine.
	Feb1314:43:03node1systemd:StartedCorosyncClusterEngine.

查看其成员之间的结点通知信息是否正常

#ansiblemariadb-ecommand-a"grepTOTEM/var/log/messages"

查看启动过程中是否有错误信息产生

#ansiblemariadb-ecommand-a"grep'ERROR'/var/log/messages"

查看pacemaker是否已经正常启动

#ansiblemariadb-ecommand-a"grep'pacemaker'/var/log/messages"

使用以下命令查看结点的状态

#crmstatus
		Lastupdated:MonFeb1315:43:082017		Lastchange:MonFeb1314:33:582017byhaclusterviacrmdonnode3.rj.com
		Stack:corosync
		CurrentDC:node3.rj.com(version1.1.13-10.el7-44eb2dd)-partitionwithquorum
		3nodesand0resourcesconfigured

		Online:[node1.rj.comnode2.rj.comnode3.rj.com]

查看pacemaker 和与corosync所启动的进程

#ansiblemariadb-mcommand-a"psauxf"|greppacemaker
		root17200.01.31304846384?Ss14:330:00/usr/sbin/pacemakerd-f
		haclust+17290.02.713281613268?Ss14:330:01\_/usr/libexec/pacemaker/cib
		root17300.01.41339686956?Ss14:330:00\_/usr/libexec/pacemaker/stonithd
		root17310.00.81029364108?Ss14:330:00\_/usr/libexec/pacemaker/lrmd
		haclust+17320.01.31247806736?Ss14:330:00\_/usr/libexec/pacemaker/attrd
		haclust+17330.00.71148963668?Ss14:330:00\_/usr/libexec/pacemaker/pengine
		haclust+17340.01.51431607484?Ss14:330:00\_/usr/libexec/pacemaker/crmd
#ansiblemarriadb-mcommand-a"psauxf"|grepcorosync
	root14830.67.913484838436?Ssl14:320:28corosync

三、利用crmsh来配置corosync的IP地址资源及mariadb资源

如果想要查看某种类别下的所用资源代理的列表,可以使用类似以下的命令来实现

#crmralistlsb
	#crmralistocfheartbeat
	#crmralistocfpacemaker
	#crmralistocfstonith

配置vip

#crmconfigurepropertystonith-enabled=false关闭stonsth设备
	#crmconfigureprimitiveDBIPocf:heartbeat:IPaddrparamsip=172.16.23.23添加vip资源代理
	#crmconfigureverify查看是否有错误
	#crmconfigurecommit用来提交配置信息
	#crmconfigureshow可以用来查看配置信息
		node1:node1.rj.com
		node2:node2.rj.com
		node3:node3.rj.com
		primitiveDBIPIPaddr\
			paramsip=172.16.23.23
		propertycib-bootstrap-options:\
			have-watchdog=false\
			dc-version=1.1.13-10.el7-44eb2dd\
			cluster-infrastructure=corosync\
			stonith-enabled=false
	#crmnodestandbynode1.rj.com	当将node1结点成为备用结点时
	#ansiblemariadb-mcommand-a"ipaddrlist"查看其vip的变化信息
	#crmrainfosystemd:mairadb用来查看systemd类型的mariadb资源的语法格式
		systemdunitfileformariadb(systemd:mariadb)

		MariaDBdatabaseserver

		Operations'defaults(advisoryminimum):

			starttimeout=15
			stoptimeout=15
			statustimeout=15
			restarttimeout=15
			monitortimeout=15interval=15start-delay=15

vip资源

node1 noline pirector.png

当node1#crmnodestandbynode1.rj.com时

ansible 查看vip信息.png

定义mariadbg资源并设定监控

	#crmconfigureprimitiveMDBsystemd:mariadbopstarttimeout=15sopstoptimeout=15sopmonitorinterval=15stimeout=15s
	#crmconfiguregroupDBserviceDBIPMDB
	#crmconfigureverify
	#crmconfigurecommit
	#crmconfigureshow
		node1:node1.rj.com\
			attributesstandby=on
		node2:node2.rj.com\
			attributesstandby=off
		node3:node3.rj.com\
			attributesstandby=off
		primitiveDBIPIPaddr\
			paramsip=172.16.23.23
		primitiveMDBsystemd:mariadb\
			opstarttimeout=15sinterval=0\
			opstoptimeout=15sinterval=0\
			opmonitorinterval=15stimeout=15s
		groupDBserviceDBIPMDB
		propertycib-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服务启动之后才能进行对数据库的更改

但更改完后旋得再将那两个结点的数据库停止调

	node1node2node3上执行:#mysql-e"GRANTALLON*.*TO'root'@'%.%.%.%'IDENTIFIEDBY'centos.123';"
	node1#mysql-e"CREATEDATABASENODE1"
	node2#mysql-e"CREATEDATABASENODE2"
	node3#mysql-e"CREATEDATABASENODE3"

启用一台测试机进行测试

test3.png

node1	#systemctlstopcorosync.servicepacemaker.service当node1的服务停止时

test2.png

node2#systemctlstopcorosync.servicepacemaker.service当node2的的服务停止时

test1.png

原创文章,作者:nene,如若转载,请注明出处:/88193

发表评论

电子邮件地址不会被公开。 必填项已用*标注

联系我们

400-080-6560

在线咨询:点击这里给我发消息

邮件:1660809109@qq.com

工作时间:周一至周五,9:30-18:30,节假日同时也值班

友情链接:万达娱乐招商  万达开户  万达娱乐招商  万达娱乐主管  万达直属  万达娱乐开户  万达娱乐直属QQ  万达娱乐注册  万达主管  万达主管