mysql cluster
重启mysql
/etc/init.d/mysql restart
在主机3-4上
mysql –uroot –p
change master to
master_host=’192.168.254.111’,
master_port=3306,
master_user=’copy’,
master_password=’copy’,
master_log_file=’mysql-bin.000005’,
master_log_pos=’106’;
start slave;
show slave status;
测试
同上,分别在1和2上创建1个数据库,看是否同步
5 安装xinetd
在主机1-6上
emerge –av xinetd
rc-update add xinetd default
/etc/init.d/xinetd start
在主机1-2上
vi /etc/xinetd.d/mysqlchk
## /etc/xinetd.d/mysqlchk#service mysqlchk_write{flags= reusesocket_type = streamport= 9200wait= nouser= nobodyserver= /opt/mysqlchk_status.shlog_on_failure += useriddisable= noonly_from =192.168.254.0/24}service mysqlchk_replication{flags= reusesocket_type = streamport= 9201wait= nouser= nobodyserver= /opt/mysqlchk_replication.shlog_on_failure += useriddisable= noonly_from = 192.168.254.0/24}在主机1上
vi /opt/mysqlchk_status.sh
#!/bin/bashmysql_host=localhostmysql_port=3306mysql_username=rootmysql_password=rooterror_msg=`/usr/bin/mysql --host=$mysql_host --port=$mysql_port --user=$mysql_username --password=$mysql_password -e show databases; 2>dev/null`if [ $error_msg != ]then# mysql is fine, return http 200/bin/echo -e http/1.1 200 ok\r\n/bin/echo -e content-type: content-type:text\r\n/bin/echo -e \r\n/bin/echo -e mysql is running.\r\n/bin/echo -e \r\nelse#mysql is down, return http 503/bin/echo -e http/1.1 503 service unavailable\r\n/bin/echo -e content-type: content-type:text/plain\r\n/bin/echo -e \r\n/bin/echo -e mysql is *down*.\r\n/bin/echo -e \r\nfivi /opt/mysqlchk_replication.sh
#!/bin/bashmysql_host=localhostmysql_port=3306mysql_username=rootmysql_password=root/usr/bin/mysql --host=$mysql_host --port=$mysql_port --user=$mysql_username --password=$mysql_password -e show slave status; > /tmp/check_repl.txtiostat=`grep slave_io_running /tmp/check_repl.txt | awk '{print $2}'`sqlstat=`grep slave_sql_running /tmp/check_repl.txt | awk '{print $2}'`#echo iostat:$iostat and sqlstat:$sqlstatif [ $iostat = no ] || [ $sqlstat = no ];then#mysql is down,return http 503/bin/echo -e http/1.1 503 service unavailable\r\n/bin/echo -e content-type: content-type:text/plain\r\n/bin/echo -e \r\n/bin/echo -e mysql replication is *down*.\r\n/bin/echo -e \r\nelse#mysql is fine,return http 200/bin/echo -e http/1.1 200 ok\r\n/bin/echo -e content-type: content-type:text/plain\r\n/bin/echo -e \r\n/bin/echo -e mysql replication is running.\r\n/bin/echo -e \r\nfi在主机2上
vi /opt/mysqlchk_status.sh
#!/bin/bashmysql_host=localhostmysql_port=3306mysql_username=rootmysql_password=rooterror_msg=`/usr/bin/mysql --host=$mysql_host --port=$mysql_port --user=$mysql_username --password=$mysql_password -e show databases; 2>dev/null`if [ $error_msg != ]then# mysql is fine, return http 200/bin/echo -e http/1.1 200 ok\r\n/bin/echo -e content-type: content-type:text\r\n/bin/echo -e \r\n/bin/echo -e mysql is running.\r\n/bin/echo -e \r\nelse#mysql is down, return http 503/bin/echo -e http/1.1 503 service unavailable\r\n/bin/echo -e content-type: content-type:text/plain\r\n/bin/echo -e \r\n/bin/echo -e mysql is *down*.\r\n/bin/echo -e \r\nfivi /opt/mysqlchk_replication.sh
#!/bin/bashmysql_host=localhostmysql_port=3306mysql_username=rootmysql_password=root/usr/bin/mysql --host=$mysql_host --port=$mysql_port --user=$mysql_username --password=$mysql_password -e show slave status; > /tmp/check_repl.txtiostat=`grep slave_io_running /tmp/check_repl.txt | awk '{print $2}'`sqlstat=`grep slave_sql_running /tmp/check_repl.txt | awk '{print $2}'`#echo iostat:$iostat and sqlstat:$sqlstatif [ $iostat = no ] || [ $sqlstat = no ];then#mysql is down,return http 503/bin/echo -e http/1.1 503 service unavailable\r\n/bin/echo -e content-type: content-type:text/plain\r\n/bin/echo -e \r\n/bin/echo -e mysql replication is *down*.\r\n/bin/echo -e \r\nelse#mysql is fine,return http 200/bin/echo -e http/1.1 200 ok\r\n/bin/echo -e content-type: content-type:text/plain\r\n/bin/echo -e \r\n/bin/echo -e mysql replication is running.\r\n/bin/echo -e \r\nfi在主机3-6上
