tar zxvf mariadb-10.1.22-linux-x86_64.tar.gz
mv mariadb-10.1.22-linux-x86_64 /usr/local/
cd /usr/local/
ln -s mariadb-10.1.22-linux-x86_64 mariadb
cd mariadb
useradd mariadb
chown root:root -R .
chown mariadb:mariadb -R data
cp support-files/my-large.cnf my.cnf
vim my.cnf
// 修改配置文件
user = mariadb
port = 3308
socket = /var/run/mariadb.sock
basedir = /usr/local/mariadb
datadir = /usr/local/mariadb/data
log_error = /var/log/mariadb/error.log
slow_query_log = 1
slow_query_log_file = /var/log/mariadb/slow.log
long_query_time = 3
skip-name-resolve
#thread_concurrency = 8 // 已废弃
innodb_data_home_dir = /usr/local/mariadb/data
innodb_log_group_home_dir = /usr/local/mariadb/data
#innodb_additional_mem_pool_size = 20M // 已废弃
innodb_use_sys_malloc = 1 // 系统分配
// 修改配置文件结束
mkdir /var/log/mariadb
chown mariadb /var/log/mariadb
cp support-files/mysql.server /etc/init.d/mariadb
vim /etc/init.d/mariadb
// 修改启动文件
# chkconfig: 2345 65 37 // 在原数字上加1,与mysqld分开
basedir=/usr/local/mariadb
datadir=/usr/local/mariadb/data
lock_file_path="$lockdir/mariadb"
extra_args="-c $basedir/my.cnf" // 改成-c即配置文件,跳过/etc/my.cnf
$bindir/mysqladmin --defaults-file=$basedir/my.cnf ping >/dev/null 2>&1; then // 指定配置文件
$bindir/mysqld_safe --defaults-file=$basedir/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &
// 修改启动文件结束
/etc/init.d/mariadb start
chkconfig add mariadb
安装完成了,之前的项目用的mysql,1主3从,新项目准备用mariadb,2主2从
103和105做主数据库,互为主从,既103和104的数据源是105,105和202的数据源是103
先修改103和105的配置文件,修改自增量步长和开启二进制日志
server-id = 103
auto_increment_increment= 2
auto_increment_offset = 1
sync_binlog = 1
log-bin = mysql-bin
binlog_format = mixed
expire_logs_days = 10
log_slave_updates = 1
server-id = 105
auto_increment_increment= 2
auto_increment_offset = 2
sync_binlog = 1
log-bin = mysql-bin
binlog_format = mixed
expire_logs_days = 10
log_slave_updates = 1
启动数据库,在两台主数据库上创建同步账号:
CREATE USER 'repl'@'192.168.1.%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.%';
flush privileges;
SHOW MASTER STATUS; // 记录二进制日志名和偏移量
在从数据库上执行命令:
CHANGE MASTER TO
MASTER_HOST='192.168.1.103',//主数据库的IP
MASTER_PORT=3308,//主数据库的端口
MASTER_USER='repl',//主数据库的同步账号
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000015',//主数据库的二进制日志名
MASTER_LOG_POS=343;//主数据库的二进制日志偏移量