首页 > 数据库 > > MariaDB主从节点配置
yum下载安装 yum -y install mariadb mariadb-server
建立数据存储路径
cd /opt && mkdir mysql
迁移数据存储路径到/opt下面
cp -r /var/lib/mysql/* /opt/mysql/
修改配置文件
vim /etc/my.cnf.d/mariadb-server.cnf
{{image.png}}
标红位置为重点配置
授权mysql 用户
chown -R mysql:mysql /opt/mysql/
启动mariadb
systemctl start mariadb
加入开机自启
systemctl enable mariadb
登录mysql初始化
UPDATE mysql.user SET password = PASSWORD('maysqlpassword') WHERE USER = 'root';
FLUSH PRIVILEGES;
加入开机自启
systemctl enable mariadb
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld/mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
datadir=/opt/mysql
socket=/opt/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld/mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
datadir=/opt/mysql
socket=/opt/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
# 服务唯一id 最好跟内网IP最后保持一致
server-id=186
# 开启二进制文件地址
log-bin=/opt/mysql/maste-log
# 同步二进制日志文件
sync_binlog = 1
# 由replication机制的SQL线程读取relay-log而执行的SQL语句记录到bin-log
log-slave-updates=true
[client]
port=3306
socket=/opt/mysql/mysql.sock
复制代码
CREATE USER 'slave'@'%' IDENTIFIED BY 'maysqlpassword';
GRANT REPLICATION SLAVE ON . TO 'slave'@'%';
flush privileges;
reset master;
show master status \G;
{{image.png}}
红框信息需记住,从库配置需要用
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld/mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
datadir=/opt/mysql
socket=/opt/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
server-id=187
# 开启二进制文件
log-bin=mysql-bin
log-slave-updates=true
[client]
port=3306
socket=/opt/mysql/mysql.sock
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
复制代码
stop slave;
reset slave all;
CHANGE MASTER TO MASTER_HOST='***.40.64.***',
MASTER_USER='slave', ---主节点设置得用户名
MASTER_PASSWORD='maysqlpassword', ---主节点设置得用户名密码
MASTER_LOG_FILE='maste-log.000002', ---主节点master设置得master file
MASTER_LOG_POS=313; ---主节点master设置得MASTER_LOG_POS
复制代码
``` show slave status \G; ```
复制代码
start slave;
#### 这俩参数为yes 及配置成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69999831/viewspace-3149357/ ,如需转载,请注明出处,否则将追究法律责任。