一、实验环境
1)实验图
2)同步时间;确保可以使用主机名通信;确保可以使用ssh秘钥方式进行彼此登录;由于是两台设备,需要仲裁;
确保可以使用主机名通信
web1修改hosts文件如下: 172.16.2.12 SQL1.linux.com SQL1 172.16.2.14 SQL2.linux.com SQL2 web2修改hosts文件如下: 172.16.2.12 SQL1.Linux.com SQL1 172.16.2.14 SQL2.linux.com SQL2
确保主机可以使用ssh秘钥彼此登录
[root@SQL1~]# ssh-keygen -P '' \\生成秘钥 [root@SQL1~]# ssh-copy-id -i .ssh/id_rsa.pub root@172.16.2.14 \\将公钥复制给web2 [root@SQL2 ~]# ssh-keygen -P '' \\生成秘钥 [root@SQL2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@172.16.2.12 \\将公钥复制给web1
确保主机之间时间同步
[root@SQL1 ~]# crontab -e */5 * * * * /usr/sbin/ntpdate 172.16.2.13 [root@SQL2 ~]# crontab -e */5 * * * * /usr/sbin/ntpdate 172.16.2.13
测试
[root@SQL1 ~]# date; ssh SQL2 'date' Sat Jun 27 15:10:35 CST 2015 Sat Jun 27 15:10:35 CST 2015 [root@SQL2 ~]# date;ssh SQL1 'date' Sat Jun 27 15:11:13 CST 2015 Sat Jun 27 15:11:13 CST 2015
二、安装配置heartbeat v2
1)安装依赖包;前提准备好epel源
阿里云eple源 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo
[root@SQL1 heartbeat]# yum -y install net-snmp-libs PyXML gettext-devel libtool-ltdl pygtk2-libglade libnet [root@SQL1 heartbeat]# rpm -ivh heartbeat-pils-2.1.4-12.el6.x86_64.rpm [root@SQL1 heartbeat]# rpm -ivh heartbeat-stonith-2.1.4-12.el6.x86_64.rpm [root@SQL1 heartbeat]# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm [root@SQL1 heartbeat]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm [root@SQL2 heartbeat]# yum -y install net-snmp-libs PyXML gettext-devel libtool-ltdl pygtk2-libglade libnet [root@SQL2 heartbeat]# rpm -vih heartbeat-pils-2.1.4-12.el6.x86_64.rpm [root@SQL2 heartbeat]# rpm -ivh heartbeat-stonith-2.1.4-12.el6.x86_64.rpm [root@SQL2 heartbeat]# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm [root@SQL2 heartbeat]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm
2)对heartbeat进行配置
[root@SQL1 ha.d]# rpm -ql heartbeat \\查看heartbeat生成文件 [root@SQL1 ~]# cd /usr/share/doc/heartbeat-2.1.4/ [root@SQL1 heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/ authkeys :是主机之间信息传递使用的秘钥 ha.cf:是heartbeat的主配置文件 haresource: 资源配置文件 [root@SQL1 heartbeat-2.1.4]# cd /etc/ha.d/ [root@SQL1 ha.d]# openssl rand -hex 6 e5b50e897cb4 \\生成秘钥 [root@SQL1 ha.d]# vim authkeys \\配置秘钥 auth 1 1 md5 e5b50e897cb4 [root@SQL1 ha.d]# chmod 400 authkeys \\修改秘钥文件的权限;建议使用400;如果不修改权限heartbeat无法启动 [root@SQL1 ha.d]# vim ha.cf logfile /var/log/ha-log \\ 定义日志文件 mcast eth0 227.10.10.1 694 1 0 \\定义组播地址以及传递的相关属性(mcast组播;bcast广播;ucast单播) auto_failback on \\抢占模式;主节点恢复故障后从备用节点那里抢回主节点功能 node SQL1.linux.com \\添加ha节点;此名称必须是“uname -n”看到的主机名 node SQL2.linux.com \\添加ha节点;此名称必须是“uname -n”看到的主机名 ping 172.16.2.1 \\ 定义仲裁设备 compression bz2 \\启用压缩功能 compression_threshold 2 \\大于多少k之后开始压缩 crm on \\启用heartbeat v2版
3)在SQL1节点将配置复制给SQL2一份
[root@SQL1 ha.d]# scp authkeys ha.cf haresources.bak SQL2:/etc/ha.d/
4)启动服务
[root@SQL1 ~]# service heartbeat start; ssh SQL2 "service heartbeat start" logd is already running Starting High-Availability services: Done. logd is already running Starting High-Availability services: Done.
5)查看监听端口:监听在组播地址227.10.10.1的UDP/694端口
[root@SQL1 ~]# ss -upln State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 227.10.10.1:694 *:* users:(("heartbeat",23422,7),("heartbeat",23423,7)) UNCONN 0 0 *:60749 *:* users:(("heartbeat",23422,6),("heartbeat",23423,6))
6)安装mariadb数据库
配置mysql共享存储
[root@time-or-nfs ~]# groupadd -g 300 mysql \\由于nfs权限与mysql初始化要求,需要创建mysql用户组 [root@time-or-nfs ~]# useradd -u 300 -g 300 mysql [root@time-or-nfs ~]# mkdir -pv /mydata/data \\创建共享目录 [root@time-or-nfs ~]# vim /etc/exports \\编辑nfs配置文件 /mydata 172.16.2.0/24(rw,no_root_squash) \\编辑共享权限 [root@time-or-nfs ~]# service nfs start \\启动nfs服务
[root@SQL1 ~]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local \\解压mariadb [root@SQL1 ~]# cd /usr/local/ \\\切换目录 [root@SQL1 local]# ln -sv mariadb-5.5.36-linux-x86_64/ mysql \\创建软连接 [root@SQL1 local]# groupadd -g 300 mysql \\ 创建mysql组,GID要与nfs服务器上的mysql的GID相同 [root@SQL1 local]# useradd -u 300 -g 300 mysql \\创建mysql组,UDI与nfs服务器上的UID相同 [root@SQL1 local]# mkdir /mydata \\创建挂载目录 [root@SQL1 local]# mount -t nfs 172.16.2.13:/mydata /mydata \\挂载共享文件 [root@SQL1 local]# cd mysql [root@SQL1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ \\初时化数据库 [root@SQL1 mysql]# mkdir /etc/mysql/ \\创建mysql配置文件存放目录 [root@SQL1 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf \\复制mysql配置文件到/etc/mysql/ [root@SQL1 mysql]# vim /etc/mysql/my.cnf \\编辑mysql的配置文件 datadir=/mydata/data \\设置数据存放目录 innodb_file_per_table = on \\开启每表结构 skip_name_resolve = on \\禁止mysql主机名解析 [root@SQL1 mysql]# cp support-files/mysql.server /etc/init.d/mysqld \\复制启动脚本到/etc/init.d目录下 [root@SQL1 mysql]# chkconfig --add /etc/init.d/mysqld \\添加mysql启动脚本为lsb风格 [root@SQL1 mysql]# service mysqld start \\启动mysql Starting MySQL... [ OK ] [root@SQL1 mysql]# mysql \\进入mysql mysql> CREATE DATABASE heartbeat; \\创建测试数据库 mysql> use heartbeat; \\设置默认库 mysql> CREATE TABLE ha_mysql(Number INT); \\创建测试表 mysql> GRANT ALL ON heartbeat.* TO "heartbeat"@"172.16.2.%" IDENTIFIED BY "heartbeat"; \\用户授权 mysql> FLUSH PRIVILEGES; \\刷新权限 mysql> SHOW DATABASES; \\查看数据库 +--------------------+ | Database | +--------------------+ | information_schema | | heartbeat | | mysql | | performance_schema | | test | +--------------------+ mysql> USE heartbeat ; \\切换数据库 mysql> show tables; \\查看表 +---------------------+ | Tables_in_heartbeat| +---------------------+ | ha_mysql | +---------------------+ [root@SQL1 mysql]# service mysqld stop \\停止数据库 Shutting down MySQL. [ OK ] [root@SQL1 mysql]# umount /mydata/ \\卸载共享目录
[root@SQL2 ~]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local [root@SQL2 ~]# cd /usr/local [root@SQL2 local]# ln -sv mariadb-5.5.36-linux-x86_64/ mysql [root@SQL2 local]# cd mysql/ [root@SQL2 mysql]# groupadd -g 300 mysql [root@SQL2 mysql]# useradd -u 300 -g 300 mysql [root@SQL2 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf [root@SQL2 mysql]# vim /etc/mysql/my.cnf datadir = /mydata/data innodb_file_per_table = on skip_name_resolve = on [root@SQL2 mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@SQL2 mysql]# chkconfig --add /etc/init.d/mysqld [root@SQL2 mysql]# mount -t nfs 172.16.2.13:/mydata/ /mydata/ [root@SQL2 mysql]# service mysqld start Starting MySQL.. [ OK ] [root@SQL2 mysql]# mysql -h172.16.2.14 -uheartbeat -p mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | heartbeat | | test | +--------------------+ mysql> USE heartbeat; mysql> SHOW TABLES ; +---------------------+ | Tables_in_heartbeat| +---------------------+ | ha_mysql | +---------------------+ [root@SQL2 mysql]# service mysqld stop Shutting down MySQL. [ OK ] [root@SQL2 mysql]# umount /mydata/
7)设置hacluster用户的密码(设置hacluster用户密码只需要在一个节点设置即可)
[root@SQL1 ~]# echo "test" | passwd --stdin hacluster
8)在图形终端启动heartbeat的图形接口:hb_gui (或者使用xshell的企业版)
9)添加vip
10)添加nfs文件系统
11)添加mysql服务
12)添加vip与nfs的排序约束
13)添加mysql与nfs的排序约束
14)添加vip与nfs的顺序约束
15)添加mysql服务与nfs的顺序约束
16)添加本地约束
17)启动资源
18)测试访问mysql
[root@SQL1 ~]# mysql -h 172.16.2.100 -uheartbeat -p Enter password: mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | heartbeat | | test | +--------------------+ mysql> USE heartbeat; mysql> SHOW TABLES; +---------------------+ | Tables_in_heartbeat| +---------------------+ | ha_mysql | +---------------------+
19)切换工作主机;选择sql2,右击选择Standby;在弹出的对话框中选择yes
20)测试访问:
[root@SQL2 ~]# mysql -h172.16.2.100 -uheartbeat -p Enter password: mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema| | heartbeat | | test | +--------------------+ mysql> USE heartbeat; mysql> SHOW TABLES; +---------------------+ | Tables_in_heartbeat| +---------------------+ | ha_mysql | +---------------------+
原创文章,作者:马行空,如若转载,请注明出处:http://www.178linux.com/5728
评论列表(2条)
向你学习,有个问题想问一下,我运行hb_gui &报错,是该如何解决。。安装了Xmanager的。[root@node2 ~]# hb_gui & [1] 2384 [root@node2 ~]# Traceback (most recent call last): File “/usr/bin/hb_gui”, line 41, in import gtk, gtk.glade, gobject File “/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py”, line 64, in _init() File “/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py”, line 52, in _init _gtk.init_check() RuntimeError: could not open display
@charles2311:我是在另一台测试机上,安装的gone桌面,进行试验的