扩展知识二:
使用heartbeatV2的CRM组件进行高可用集群的“集群资源管理crm”
1、更改原来haresources资源管理配置文件的方法可用通过/usr/lib64/heartbeat/resources2cib.py进行转换配置文件格式转换。
[root@node1.dtedu.com~]$/usr/lib64/heartbeat/haresources2cib.py
[root@node1.dtedu.com~]$ls /var/lib/heartbeat/crm/操作后会在此处生成cib.xml文件。
cib.xml
2、启动heartbeat V2版的集群资源管理器crm,需要修改/etc/ha.d/ha.cf配置文件,末尾添加
#crm
crm on
3、监听端口5560、694
[root@node2.dtedu.com /var/www/html]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1344/sshd
tcp 0 0 0.0.0.0:5560 0.0.0.0:* LISTEN 1066/mgmtd
tcp 0 0 :::22 :::* LISTEN 1344/sshd
udp 0 0 0.0.0.0:59913 0.0.0.0:* 1054/heartbeat: wri
udp 0 0 224.5.6.7:694 0.0.0.0:* 1054/heartbeat: wri
4、crm的图形化配置工具需要账户和密码,为hacluster创建密码。(认证方式为本地认证,所以在哪里认证就在哪里启动配置工具,所以这里是的node2上进行配置,当然也可以在各个节点上都创建账户密码)
[root@node2.dtedu.com /var/www/html]# tail /etc/passwd
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
hacluster:x:498:498:heartbeat user:/var/lib/heartbeat/cores/hacluster:/sbin/nologin
[root@node2.dtedu.com /var/www/html]# passwd hacluster
更改用户 hacluster 的密码 。
新的 密码:
无效的密码: 它没有包含足够的不同字符
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@node2.dtedu.com /var/www/html]#
5、运行图像化工具hb_gui,此为通过haresources2cib.py脚本转换后的结果
6、创建以下资源:
6.1、vip,用于高可用的虚拟ip地址
6.2、nfs挂载点,节点挂载的nfs共享文件系统,用于存放HTML页面文件。
6.3、httpd服务,用于启动web服务。
要求:所以资源默认运行在节点1上node1,并且资源间的启动顺序为vip->nfs->httpd。
命令行方式检查高可用集群的状况
Refresh in 5s...
============
Last updated: Thu Mar 30 01:54:33 2017
Current DC: node3.dtedu.com (604f380c-3952-4c80-afdf-56d84aa94f7f)
3 Nodes configured.
3 Resources configured.
============
Node: node2.dtedu.com (f57e6cb6-4edf-4422-adb1-8a5dd467eb9a): online
Node: node3.dtedu.com (604f380c-3952-4c80-afdf-56d84aa94f7f): online
Node: node1.dtedu.com (92dbc6f9-e5ca-4de1-b8b8-d23ed2b9ac0a): online
ha-vip (ocf::heartbeat:IPaddr): Started node2.dtedu.com
ha-nfs (ocf::heartbeat:Filesystem): Started node1.dtedu.com
ha-httpd (lsb:httpd): Started node3.dtedu.com
Failed actions:
ha-nfs_start_0 (node=node3.dtedu.com, call=5, rc=1): complete
具体步骤:
1、创建组id(vip-nfs-httpd)、资源id(ha-vip,ha-nfs,ha-httpd),并添加资源
通过修改orders改变资源启动顺序,通过修改colocations将资源放在一个节点上启动。
扩展知识三
heartbeatV2CRM上搭建高可用的mysql
环境介绍:
1、mysql数据库存储在远程挂载的nfs文件系统上,nfs权限使用no_root_squash。
2、各个节点间使用的mysql账户及密码相同,ID号相同。
3、
具体步骤:
1、创建nfs环境
[root@mail ~]# mkdir /mysqldata
[root@mail ~]# vi /etc/exports
/web/htdocs *(ro)
/mysqldata *(rw,no_root_squash)
[root@mail ~]# exportfs -avr使配置文件生效,免重启。
exporting *:/mysqldata
exporting *:/web/htdocs
比较现实不同服务器的时间
[root@node1.dtedu.com~]$date;ssh node2 "date"
2017年 03月 30日 星期四 04:20:18 EDT
2017年 03月 30日 星期四 03:54:33 EDT
2、节点创建mysql账户及相同ID,为目录授予mysql权限。
[root@node1.dtedu.com~]$mount -t nfs 10.40.0.37:/mysqldata /mysqldata
[root@node1.dtedu.com~]$useradd -r -u 301 mysql
[root@node1.dtedu.com~]$chown mysql:mysql /mysqldata
3、搭建mariadb数据库。
3.1安装gcc、gcc-c++
3.2安装ncurses-devel
3.3删除CMakeCache.txt
具体步骤:
[root@node2.dtedu.com ~]# tar zxf mariadb-10.1.22.tar.gz
[root@node2.dtedu.com ~]# cd mariadb-10.1.22
[root@node2.dtedu.com ~/mariadb-10.1.22]# yum install cmake安装cmake
[root@node2.dtedu.com ~/mariadb-10.1.22]# yum install gcc gcc-c++ ncurses-devel
[root@node2.dtedu.com ~/mariadb-10.1.22]# rm CMakeCache.txt -f
[root@node2.dtedu.com ~/mariadb-10.1.22]# cmake . -DRPM=centos6.7 -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/mysqldata/data -DSYSCONFDIR=/etc
[root@node3.dtedu.com /usr/local/mariadb]# scp ./share/mysql/mysql.server /etc/init.d/mariadb
[root@node3.dtedu.com /usr/local/mariadb]# chkconfig --add mariadb
[root@node3.dtedu.com /usr/local/mariadb]# chkconfig --list mariadb
mariadb 0:关闭1:关闭2:关闭3:关闭 4:关闭5:关闭6:关闭
[root@node3.dtedu.com /usr/local/mariadb]# service mariadb start
Starting MySQL.170330 07:07:17 mysqld_safe Logging to '/mysqldata/data/node3.dtedu.com.err'.
170330 07:07:17 mysqld_safe Starting mysqld daemon with databases from /mysqldata/data
...................................... SUCCESS!
[root@node3.dtedu.com /usr/local/mariadb]# cp share/mysql/my-large.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
配置MariaDB
初始化数据库:
1 2 3 4 5 | [root@example.com mariadb-10.0.21] # cd /usr/local/mysql/ [root@example.com mysql] # scripts/mysql_install_db --user=mysql --datadir=/data/mydata/ [root@example.com mysql] # ls /data/mydata/ aria_log.00000001 ibdata1 ib_logfile1 mysql testaria_log_control ib_logfile0 lost+found performance_schema |
设置配置文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | [root@example.com mysql] # vim /etc/my.cnf [mysqld] port = 3306 socket = /tmp/mysql .sock skip-external-locking key_buffer_size = 256M max_allowed_packet = 1M table_open_cache = 256 sort_buffer_size = 1M read_buffer_size = 1M read_rnd_buffer_size = 4M myisam_sort_buffer_size = 64M thread_cache_size = 8 query_cache_size= 16M # Try number of CPU's*2 for thread_concurrency thread_concurrency = 4 datadir= /data/mydata // 需要添加此项 |
设置启动脚本:
1 2 3 4 | [root@example.com mysql] # cp support-files/mysql.server /etc/init.d/mysqld [root@example.com mysql] # chkconfig --add mysqld [root@example.com mysql] # chkconfig --list mysqld mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭 |
启动服务:
1 2 3 4 | [root@example.com mysql] # service mysqld start Starting MySQL. SUCCESS! [root@example.com mysql] # ss -tunl |grep 3306 tcp LISTEN 0 128 :::3306 :::* |
导出环境变量:
1 2 3 | [root@example.com mysql] # vim /etc/profile.d/mysql.sh export PATH= /usr/local/mysql/bin :$PATH [root@example.com mysql] # source /etc/profile.d/mysql.sh |
导出头文件:
1 2 | [root@example.com mysql] # ln -sv /usr/local/mysql/include/ /usr/local/include/mysql "/usr/local/include/mysql" -> "/usr/local/mysql/include/" |
导出库文件:
1 2 3 4 5 6 7 8 | [root@example.com mysql] # vim /etc/ld.so.conf.d/mysql.conf /usr/local/mysql/lib [root@example.com mysql] # ldconfig -v [root@example.com mysql] # ldconfig -p |grep mysql libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r .so.16 libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient .so.18 libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient .so.16 libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient .so 这里安装的mariadb数据库,但在做crm高可用的时候,需要在复制脚本时将mysql.server复制为mysqld,并且在crm添加资源的时候选择mysqld(LSB)模式。 |
Linux 高可用(HA)集群之heartbeat基于crm进行资源管理详解