这里的实验环境还是使用我们上一节的 http://www.linuxidc.com/Linux/2014-03/98673.htm 首先停止节点资源,然后删除
NFS共享存储节点配置: # mkdir /mydata # vim /etc/exports /mydata 192.168.100.0/24(no_root_squash,rw) # service nfs restart # groupadd -g 3306 MySQL # useradd -g 3306 -u 3306 -s /sbin/nologin -M mysql # chown -R /mydata 注:这里必需将nfs共享的资源设定为no_root_squash,否则mysql服务无法启动
Node节点配置: 在这里node1与node2的配置完全一样
# groupadd -g 3306 mysql # useradd -g 3306 -u 3306 -s /sbin/nologin -M mysql # mkdir /mydata # tar xvf mysql-5.5.22-linux2.6-i686.tar.gz -C /usr/local/ # cd /usr/local/ # ln -s mysql-5.5.22-linux2.6-i686/ mysql # cd mysql # chown -R root:mysql . # mount -t nfs 192.168.100.9:/mydata /mydata # cd /usr/local/mysql/ # scripts/mysql_install_db --user=mysql --datadir=/mydata/data # ln -s /usr/local/mysql/bin/* /usr/bin/ # cp support-files/my-large.cnf /etc/my.cnf # vim /etc/my.cnf datadir = /mydata/data innodb_file_per_table = 1 # cp support-files/mysql.server /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld off # service mysqld start # scp /ect/my.cnf node2:/etc # scp /etc/init.d/mysqld node2:/etc/init.d # service mysqld start # mysql
测试mysql是否正常使用 mysql> create database mydb; mysql> grant all privileges on *.* to root@'%' identified by 'asdasd'; mysql> flush privileges; # service mysqld stop # service heartbeat start # ssh node2 'service heartbeat start' # hb_gui 注意 1. 使用上面这条命令必需在DC上连接与配置,否则会启动失败,查看哪个节点是DC,我们可以使用命令crm_mon 2. 测试完必后必需将每个节点的mysql设为开机关闭,且卸载nfs共享存储 添加组与资源,使用上一节的步骤:
至此,我们可以从任何一台mysql客户机登陆我们mysql高可用集群了
测试在nfs服务器上登陆mysql集群,看它是否一切正常: [root@fs ~]# mysql -uroot -h 192.168.100.10 -p mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mydb | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.01 sec)
mysql> use mydb; Database changed mysql> create table test1 ( -> id int not null auto_increment primary key, -> name varchar(20) not null -> ); Query OK, 0 rows affected (0.11 sec)