Mycat分布式架构-多实例准备

Mycat分布式架构-多实例准备

1.1环境准备:

两台虚拟机db01和db02

每台机器创建4个mysql实例:3307 ,3308 ,3309 ,3310

1.2删除db01和db02的历史环境,使用一个全新的环境:

[root@db01 ~]# pkill mysqld
[root@db01 ~]# rm -rf /data/330*
[root@db01 ~]# mv /etc/my.cnf /etc/my.cnf.bak
[root@db01 ~]# ls -l /etc/my.cnf

 

[root@db02 ~]# pkill mysqld
[root@db02 ~]# rm -rf /data/330*
[root@db02 ~]# mv /etc/my.cnf /etc/my.cnf.bak

  [root@db02 ~]# ls -l /etc/my.cnf
  ls: 无法访问/etc/my.cnf: 没有那个文件或目录
  [root@db02 ~]# ls -l /etc/my.cnf.bak
  -rw-r--r--. 1 root root 534 2月 27 23:41 /etc/my.cnf.bak

 

1.3分别再db01和db02中创建相关目录初始化mysql实例:

  [root@db01 ~]# mkdir -p /data/33{07..10}/data

[root@db01 ~]# mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/application/mysql
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/application/mysql
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/application/mysql
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --datadir=/data/3310/data --basedir=/application/mysql

 1.4分别在db01和db02准备配置文件:

cat >/data/3307/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
port=3307
log_error=/data/3307/mysql.log
log_bin=/data/3307/mysql-bin
binlog_format=row
skip-name-resolve
server_id=7
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF

cat >/data/3308/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3308/data
port=3308
socket=/data/3308/mysql.sock
log_error=/data/3308/mysql.log
log_bin=/data/3308/mysql-bin
binlog_format=row
skip-name-resolve
server_id=8
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF

cat >/data/3309/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
port=3309
log_error=/data/3309/mysql.log
log_bin=/data/3309/mysql-bin
binlog_format=row
skip-name-resolve
server_id=9
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3310/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3310/data
socket=/data/3310/mysql.sock
port=3310
log_error=/data/3310/mysql.log
log_bin=/data/3310/mysql-bin
binlog_format=row
skip-name-resolve
server_id=10
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3307/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
port=3307
log_error=/data/3307/mysql.log
log_bin=/data/3307/mysql-bin
binlog_format=row
skip-name-resolve
server_id=17
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF

cat >/data/3308/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3308/data
port=3308
socket=/data/3308/mysql.sock
log_error=/data/3308/mysql.log
log_bin=/data/3308/mysql-bin
binlog_format=row
skip-name-resolve
server_id=18
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF

cat >/data/3309/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
port=3309
log_error=/data/3309/mysql.log
log_bin=/data/3309/mysql-bin
binlog_format=row
skip-name-resolve
server_id=19
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3310/my.cnf<<EOF
[mysqld]
basedir=/application/mysql
datadir=/data/3310/data
socket=/data/3310/mysql.sock
port=3310
log_error=/data/3310/mysql.log
log_bin=/data/3310/mysql-bin
binlog_format=row
skip-name-resolve
server_id=20
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF

1.5分别在db01和db02准备启动脚本(脚本一样):

cat > /etc/systemd/system/mysqld3307.service <<EOF
[Unit]
Description=Mysql Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
LimitNOFILE = 5000
EOF

cat > /etc/systemd/system/mysqld3308.service <<EOF
[Unit]
Description=Mysql Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
LimitNOFILE = 5000
EOF cat > /etc/systemd/system/mysqld3309.service <<EOF
[Unit]
Description=Mysql Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf
LimitNOFILE = 5000
EOF cat > /etc/systemd/system/mysqld3310.service <<EOF
[Unit]
Description=Mysql Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf
LimitNOFILE = 5000
EOF

 1.6分别给db01和db02的mysql用户和用户组赋予权限并启动多实例:

[root@db01 system]# chown -R mysql.mysql /data/*
[root@db01 system]# systemctl start mysqld3307.service
Warning: mysqld3307.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@db01 system]# systemctl daemon-reload
[root@db01 system]# systemctl start mysqld3307.service
[root@db01 system]# systemctl start mysqld3308.service
[root@db01 system]# systemctl start mysqld3309.service
[root@db01 system]# systemctl start mysqld3310.service
[root@db01 system]# netstat -lnp|grep 330

 1.7分别验证db01和db02的登录:

[root@db01 system]# mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 7     |
+---------------+-------+
[root@db01 system]# mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 8     |
+---------------+-------+
[root@db01 system]# mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 9     |
+---------------+-------+
[root@db01 system]# mysql -S /data/3310/mysql.sock -e "show variables like 'server_id'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 10    |
+---------------+-------+
[root@db01 system]# 

 

上一篇:通过MyCat中间件去理解分库分表


下一篇:shardingJdbc和Mycat对比,用于分库分表