Galera/mysql集群备忘(四)

2014-11-24 13:50:18 · 作者: · 浏览: 3
rver process #$mysqld_pid is not running!" rm "$mysqld_pid_file_path" fi

# Delete lock for RedHat / SuSE if test -f "$lock_file_path" then rm -f "$lock_file_path" fi exit $return_value else log_failure_msg "MySQL server PID file could not be found!" fi ;;

'restart') # Stop the service and regardless of whether it was # running or not, start it again. if $0 stop $other_args; then $0 start $other_args else log_failure_msg "Failed to stop running server, so refusing to try to start." exit 1 fi ;;

'reload'|'force-reload') if test -s "$mysqld_pid_file_path" ; then read mysqld_pid < "$mysqld_pid_file_path" kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL" touch "$mysqld_pid_file_path" else log_failure_msg "MySQL PID file could not be found!" exit 1 fi ;; 'status') # First, check to see if pid file exists if test -s "$mysqld_pid_file_path" ; then read mysqld_pid < "$mysqld_pid_file_path"

if kill -0 $mysqld_pid 2>/dev/null ; then log_success_msg "MySQL running ($mysqld_pid)" exit 0 else log_failure_msg "MySQL is not running, but PID file exists" exit 1 fi else # Try to find appropriate mysqld process mysqld_pid=`pidof $libexecdir/mysqld`

# test if multiple pids exist pid_count=`echo $mysqld_pid | wc -w` if test $pid_count -gt 1 ; then log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)" exit 5 elif test -z $mysqld_pid ; then if test -f "$lock_file_path" ; then log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists" exit 2 fi log_failure_msg "MySQL is not running" exit 3 else log_failure_msg "MySQL is running but PID file could not be found" exit 4 fi fi ;; 'configtest') # Safeguard (relative paths, core dumps..) cd $basedir echo $echo_n "Testing MySQL configuration syntax" daemon=$bindir/mysqld if test -x $libexecdir/mysqld then daemon=$libexecdir/mysqld elif test -x $sbindir/mysqld then daemon=$sbindir/mysqld elif test -x `which mysqld` then daemon=`which mysqld` else log_failure_msg "Unable to locate the mysqld binary!" exit 1 fi help_out=`$daemon --help 2>&1`; r=$ if test "$r" != 0 ; then log_failure_msg "$help_out" log_failure_msg "There are syntax errors in the server configuration. Please fix them!" else log_success_msg "Syntax OK" fi exit $r ;; 'bootstrap') # Bootstrap the cluster, start the first node # that initiate the cluster echo $echo_n "Bootstrapping the cluster" $0 start $other_args --wsrep-new-cluster ;; *) # usage basename=`basename "$0"` echo "Usage: $basename {start|stop|restart|reload|force-reload|status|configtest|bootstrap} [ MySQL server options ]" exit 1 ;; esac

exit 0

启动每一台数据库

service mysql5 start

在每台数据库中建立下面用户, 用于 sst 认证

GRANT USAGE ON *.* to tt@'%' IDENTIFIED BY 'tt123';
GRANT ALL PRIVILEGES on *.* to tt@'%';
GRANT USAGE ON *.* to tt@'localhost' IDENTIFIED BY 'tt123';
GRANT ALL PRIVILEGES on *.* to tt@'localhost';
flush privileges;


关闭所有数据库

service mysql5 stop


创建并加入集群

集群中第一个节点启动 (192.168.200.163)
创建软链接,并启动集群,集群启动过程中会自动启动 mariadb

ln -s /usr/local/mysql/bin/ /usr/local/mysql/sbin
cd /usr/local/
./mysql-galera -g  gcomm://  start

测试是否成功启动方法, 查询是否会自动启动 4567 端口

[root@db2 local]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:4567                0.0.0.0:*                   LISTEN

登录 mysql 之后,查询当前是否启用 galery 插件

MariaDB [(none)]> show status like 'wsrep_ready';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wsrep_ready   | ON    |
+---------------+-------+
1 row in set (0.00 sec)


注,on 为已经启动插件状态


关闭方法

cd /usr/local
./mysql-galera stop


其他节点加入集群方法

第一台 (192.168.200.163) 节点已经启动成功
第二台 (192.168.200.171) 需要加入集群

cd /usr/local/
./mysql-gale