banner
NEWS LETTER

Mysql双主部署

Scroll down

本文作者:丁辉

部署 Mysql 双主

Mysql-Rpm文件下载

部署

双节点都执行以下操作

  1. 下载 Mysql Rpm 文件

    1
    2
    yum install -y wget
    wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
  2. 安装 MySQL

    1
    2
    yum install -y mysql80-community-release-el7-7.noarch.rpm
    yum -y install mysql-community-server --enablerepo=mysql80-community --nogpgcheck
  3. 启动 MySQL Server

    1
    2
    3
    systemctl start mysqld
    systemctl enable mysqld
    systemctl status mysqld

配置

  1. 查看临时密码

    1
    grep 'temporary password' /var/log/mysqld.log
  2. 修改临时密码并配置允许远程登录

    1
    2
    3
    4
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
    USE mysql;
    UPDATE user SET host = '%' WHERE user = 'root';
    FLUSH PRIVILEGES;

Mysql 1号主节点配置

  1. 停止数据库

    1
    systemctl stop mysqld

    备份并编辑配置文件

    1
    2
    cp /etc/my.cnf /etc/my.cnf.bak
    vi /etc/my.cnf
    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
    [mysqld]
    pid-file=/var/run/mysqld/mysqld.pid
    socket=/var/lib/mysql/mysql.sock
    datadir=/var/lib/mysql
    log-error=/var/log/mysqld.log
    secure-file-priv=NULL
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    # 服务端默认utf8编码
    character-set-server=utf8mb4
    # 默认存储引擎
    default-storage-engine=INNODB


    # 主从配置
    log-bin=binlog
    server-id=121
    gtid-mode=on
    enforce-gtid-consistency=on
    log-slave-updates=on
    expire_logs_days=14

    # Compatible with versions before 8.0
    default_authentication_plugin=mysql_native_password
    skip-host-cache
    skip-name-resolve

    [client]
    #设置客户端编码
    default-character-set=utf8mb4
    [mysql]
    # 设置mysql客户端默认编码
    default-character-set=utf8mb4
  2. 重新启动

    1
    systemctl start mysqld
  3. 登录数据库授权

    1
    2
    3
    4
    CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
    GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
    flush privileges;
    SHOW MASTER STATUS; #此信息记录等会配置另外一台节点需要用

Mysql 2号主配置

  1. 停止数据库

    1
    systemctl stop mysqld

    备份并编辑配置文件

    1
    2
    cp /etc/my.cnf /etc/my.cnf.bak
    vi /etc/my.cnf
    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
    [mysqld]
    pid-file=/var/run/mysqld/mysqld.pid
    socket=/var/lib/mysql/mysql.sock
    datadir=/var/lib/mysql
    log-error=/var/log/mysqld.log
    secure-file-priv=NULL
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    # 服务端默认utf8编码
    character-set-server=utf8mb4
    # 默认存储引擎
    default-storage-engine=INNODB


    # 主从配置
    log-bin=binlog
    server-id=122
    gtid-mode=on
    enforce-gtid-consistency=on
    log-slave-updates=on
    expire_logs_days=14

    # Compatible with versions before 8.0
    default_authentication_plugin=mysql_native_password
    skip-host-cache
    skip-name-resolve

    [client]
    #设置客户端编码
    default-character-set=utf8mb4
    [mysql]
    # 设置mysql客户端默认编码
    default-character-set=utf8mb4
  2. 重新启动

    1
    systemctl start mysqld
  3. 登录数据库授权

    1
    2
    3
    4
    CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
    GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
    flush privileges;
    SHOW MASTER STATUS; #此信息记录等会配置另外一台节点需要用

Mysql 1号主节点配置

  1. 开启同步

    1
    2
    3
    4
    5
    6
    7
    CHANGE MASTER TO
    MASTER_HOST='', #IP地址
    MASTER_USER='slave',
    MASTER_PASSWORD='password', #密码
    MASTER_PORT=3306,
    MASTER_LOG_FILE='binlog.000002', #节点2 binlog 信息
    MASTER_LOG_POS=821; #节点2 log_pos信息
  2. 开启主从同步

    1
    start slave;
  3. 查看同步状态

    1
    show slave status\G;

Mysql 2号主节点配置

  1. 开启同步

    1
    2
    3
    4
    5
    6
    7
    CHANGE MASTER TO
    MASTER_HOST='', #IP地址
    MASTER_USER='slave',
    MASTER_PASSWORD='password', #密码
    MASTER_PORT=3306,
    MASTER_LOG_FILE='binlog.000002', #节点1 binlog 信息
    MASTER_LOG_POS=821; #节点1 log_pos信息
  2. 开启主从同步

    1
    start slave;
  3. 查看同步状态

    1
    show slave status\G;

Mysql 配置密码等级

1
2
3
4
5
set global validate_password.policy=0;
set global validate_password.mixed_case_count=0;
set global validate_password.number_count=0;
set global validate_password.special_char_count=0;
set global validate_password.length=3;

1.修改密码强度等级为0,即是LOW;
2.修改密码至少要包含的大写字母和小写字母的个数为0;
3.修改密码至少要包含的数字个数为0;
4.修改密码至少要包含的特殊字符的个数为0;
5.修改密码的长度最小个数为3;

I'm so cute. Please give me money.

其他文章
cover
Keepalived部署
  • 70/01/01
  • 00:00
  • Linux-资源安装
cover
Nexus忘记密码
  • 70/01/01
  • 00:00
  • Linux-资源安装
目录导航 置顶
  1. 1. 部署 Mysql 双主
    1. 1.1. 部署
    2. 1.2. 配置
      1. 1.2.1. Mysql 1号主节点配置
      2. 1.2.2. Mysql 2号主配置
      3. 1.2.3. Mysql 1号主节点配置
      4. 1.2.4. Mysql 2号主节点配置
    3. 1.3. Mysql 配置密码等级
请输入关键词进行搜索