• Mycat-多实例


    基础环境准备

    环境准备

    主机 实例 端口 数据目录
    db01 mysql3307 3307 /data/3307/data
    db02 mysql3308 3308 /data/3308/data
      mysql3309 3309 /data/3309/data
      mysql3310 3310 /data/3310/data
    • 两台虚拟机:db01、db02

    • 每台创建四个MySQL实例:3307、3308、3309、3310

    删除历史环境

    pkill mysqld
    rm -rf /data/33{07..10} 
    mv /etc/my.cnf /etc/my.cnf.bak

    创建相关目录初始化数据

    mkdir /data/33{07..10}/data -p
    chown -R mysql.mysql /data/*
    mysqld --initialize-insecure  --user=mysql --datadir=/data/3307/data --basedir=/app/database/mysql
    mysqld --initialize-insecure  --user=mysql --datadir=/data/3308/data --basedir=/app/database/mysql
    mysqld --initialize-insecure  --user=mysql --datadir=/data/3309/data --basedir=/app/database/mysql
    mysqld --initialize-insecure  --user=mysql --datadir=/data/3310/data --basedir=/app/database/mysql

    准备配置文件和脚本

    • db01配置文件和启动文件
    #db01配置文件
    cat >/data/3307/my.cnf<<EOF
    [mysqld]
    basedir=/app/database/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=/app/database/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=/app/database/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=/app/database/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
    
    #db01启动文件
    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=/app/database/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=/app/database/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=/app/database/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=/app/database/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf
    LimitNOFILE = 5000
    EOF
    • db02配置文件和启动文件
    #配置文件
    cat >/data/3307/my.cnf<<EOF
    [mysqld]
    basedir=/app/database/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=/app/database/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=/app/database/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=/app/database/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
    
    #启动文件
    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=/app/database/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=/app/database/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=/app/database/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=/app/database/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf
    LimitNOFILE = 5000
    EOF

    修改权限,启动多实例

    chown -R mysql.mysql /data/*
    systemctl start mysqld3307
    systemctl start mysqld3308
    systemctl start mysqld3309
    systemctl start mysqld3310
    netstat -lntup
    
    mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'"
    mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"
    mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"
    mysql -S /data/3310/mysql.sock -e "show variables like 'server_id'"
  • 相关阅读:
    C#中委托和事件的区别
    Linux centos7 计划任务与日志的管理
    linux shell检查字符串是否是IP
    Linux脚本中$#、$0、$1、$@、$*、$$、$?
    Linux命令学习之shift命令
    CentOS7编写systemd服务脚本
    java数据类型转换
    centos7 升级openssh到openssh-8.3p1版本
    oracle的簇的创建
    oracle 分区表的维护
  • 原文地址:https://www.cnblogs.com/Mercury-linux/p/12431238.html
Copyright © 2020-2023  润新知