创建目录
mkdir -p /data/330{7,8,9}/data
生成各自实例数据存储目录
准备配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| cat > /data/3307/my.cnf <<EOF [mysqld] basedir=/application/mysql #软件目录 datadir=/data/3307/data #本实例数据目录 socket=/data/3307/mysql.sock #本实例socket文件 log_error=/data/3307/mysql.log port=3307 server_id=7 log_bin=/data/3307/mysql-bin EOF
cat > /data/3308/my.cnf <<EOF [mysqld] basedir=/application/mysql datadir=/data/3308/data socket=/data/3308/mysql.sock log_error=/data/3308/mysql.log port=3308 server_id=8 log_bin=/data/3308/mysql-bin EOF
cat > /data/3309/my.cnf <<EOF [mysqld] basedir=/application/mysql datadir=/data/3309/data socket=/data/3309/mysql.sock log_error=/data/3309/mysql.log port=3309 server_id=9 log_bin=/data/3309/mysql-bin EOF
|
各自实例初始化三套数据
1 2 3 4
| mv /etc/my.cnf /etc/my.cnf.bak mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/application/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/application/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/application/mysql
|
systemd管理多实例
1 2 3 4
| cd /etc/systemd/system cp mysqld.service mysqld3307.service cp mysqld.service mysqld3308.service cp mysqld.service mysqld3309.service
|
1 2
| vim mysqld3307.service ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
|
1 2
| vim mysqld3308.service ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
|
1 2
| vim mysqld3309.service ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf
|
授权
chown -R mysql.mysql /data/*
启动
1 2 3
| systemctl start mysqld3307.service systemctl start mysqld3308.service systemctl start mysqld3309.service
|
验证多实例
1 2 3 4
| netstat -lnp|grep 330 mysql -S /data/3307/mysql.sock -e "select @@server_id" mysql -S /data/3308/mysql.sock -e "select @@server_id" mysql -S /data/3309/mysql.sock -e "select @@server_id"
|