V2 版本不再基于haresoures配置文件,而是基于crm实现。XML,只需在任意一个节点定义资源之后就可以通知给所以节点。
/var/lib/heartbeat/crm :用户用XML格式定义资源文件的路径
但是XML格式的文件一般用户都不会写,不用着急,heartbeast内置了一个程序会帮我们把haresoures格式文件翻译为XML格式文件:另外也可以用GUI图像话界面配置。
/usr/lib64/hearebeat/haresources2cib.py(python编写)
[root@node1 ha.d]# vim ha. node node1.nyist.com node node2.nyist.com # crm on---------------启动crm [root@node1 ha.d]# /usr/lib64/heartbeat/ha_propagate Propagating HA configuration files to node node2.nyist.com. ha. 100% 10KB 10.4KB/s 00:00 authkeys
root@node1 heartbeat2]# ss -tunlp | grep 5560 tcp LISTEN 0 10 *:5560 *:* users:(("mgmtd",11576,10)) mamtd:接收用户的连接命令,并提供API接口的进程 此时就有了一大堆crm命令可以使用了 [root@node1 heartbeat2]# crm crmadmin crm_failcount crm_resource crm_uuid crm_attribute crm_master crm_sh crm_verify crm_diff crm_mon crm_standby
hacluster:x:496:493:heartbeat user:/var/lib/heartbeat/cores/hacluster:/sbin/nologin [root@node1 ~]# passwd hacluster
将Mysql定义到集群中:
[root@My2 ~]# mkdir /nfs [root@My2 ~]# vim /etc/exports /nfs 172.16.0.0/16(rw,no_root_squash) [root@My2 ~]# groupadd -r -g 306 mysql [root@My2 ~]# useradd -r -u 306 -g 306 mysql [root@My2 ~]# id mysql uid=306(mysql) gid=306(mysql) groups=306(mysql) [root@My2 ~]# setfacl -m u:mysql:rwx /nfs
[root@node1 ~]# groupadd -r -g 306 mysql [root@node1 ~]# useradd -r -g 306 -u 306 mysql [root@node1 ~]# id mysql uid=306(mysql) gid=306(mysql) groups=306(mysql)
[root@node1 ~]# mkdir /mydata [root@node1 ~]# mount -t nfs 172.16.20.62:/nfs /mydata/ [root@node1 ~]# su mysql bash-4.1$ cd /mydata/ bash-4.1$ mkdir data binlogs relaylogs [root@node1 ~]# tar -xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/ [root@node1 ~]# cd /usr/local/ [root@node1 local]# ln -sv mariadb-10.0.10-linux-x86_64/ mysql [root@node1 mysql]# cd mysql [root@node1 mysql]# chown root.mysql .* -R [root@node1 mysql]# cp support-files/my-large.cnf /etc/my.cnf [root@node1 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@node1 mysql]# vim /etc/my.cnf datadir=/mydata/data bin-log=/mydata/binlogs/mysql-bin 导出头文件,PATH环境变量,库文件,帮助文件 [root@node1 mysql]# vim /etc/man.config [root@node1 mysql]# vim /etc/profile.d/mysql.sh [root@node1 mysql]# ln /usr/local/mysql/include /usr/include/ [root@node1 mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql `/usr/include/mysql' -> `/usr/local/mysql/include' [root@node1 mysql]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf [root@node1 mysql]# ldconfig
6、heartbeat默认具有负载均衡的功能,所以当你定义两个资源的时候,会平均分配到两个节点上。停掉一个节点,资源会转移到另一个节点上。
[root@node2 ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.0.10-MariaDB-log MariaDB Server Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> grant all on *.* TO 'xuqimin'@'172.16.%.%' IDENTIFIED BY 'xuqimin'; Query OK, 0 rows affected (0.00 sec) [root@My2 nfs]# mysql -uxuqimin -h172.16.20.10 -pxuqimin Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 10.0.10-MariaDB-log MariaDB Server Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databeses; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'databeses' at line 1 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | xuxu | +--------------------+