一:环境准备
yum -y install make gcc gcc-c++ ncurses-devel bison openssl-devel
(1)添加组
groupadd mysql
(2)添加用户
useradd -g mysql mysql
二:下载mysql 源码包
mkdir -p /data/packages/srccd /data/packages/wget http://distfiles.macports.org/cmake/cmake-3.9.6.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21.tar.gz
三:创建mysql目录
mkdir -p /usr/local/mysql/data
四:编译安装cmake mysql
cd /data/packages/src
tar -zxvf ../cmake-3.9.6.tar.gz
cd cmake-3.9.6/
./bootstrap
gmake
make install
cd ../
tar xf mysql-5.7.21.tar.gz
cd mysql-5.7.21
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc \
-DWITH_SSL=bundled -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/usr/local/mysql/data \-DWITH_BOOST=/usr/local/boost
make && make install
安装中出现的问题:
CMake Error at cmake/boost.cmake:81 (MESSAGE): You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
解决办法是:
1.在/usr/local下创建一个名为boost的文件夹
mkdir -p /usr/local/boost
2.进入这个新创建的文件夹然后下载boost wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz --no-check-certificate3.解压
tar -xvzf boost_1_59_0.tar.gz
4.继续cmake,添加一下内容
-DWITH_BOOST=/usr/local/boost \
5.继续cmake,添加一下内容
五:初始化数据库表
cd /usr/local/mysql
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
六:添加环境变量, 注册成系统服务
vim /root/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
source /root/.bash_profile
注册成系统服务
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig mysqld on
service mysqld start/stop/restart/status
#五:添加开机启动脚本
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
七:空密码登陆,设置密码
cd /usr/local/mysql/bin
mysql -u root
set password for 'root'@'localhost' = PASSWORD('root');
八:远端telnet 3306端口
telnet host 3306
出现下列异常:
Host is not allowed to connect to this MySQL server
解决办法:
在装有MySQL的机器上登录MySQL mysql -u root -p密码执行use mysql;执行update user set host = '%' where user = 'root';这一句执行完可能会报错,不用管它。
执行FLUSH PRIVILEGES;
九:主主配置
(1)在172.16.32.25 上:
mysql> grant replication slave on *.* to 'repl'@'172.16.32.%' identified by 'repl';Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
(2):在172.16.32.173上
mysql> grant replication slave on *.* to 'repl'@'172.16.32.%' identified by 'repl';Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
查看主库状态:
(1)在172.16.32.25 上:
mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+----------+--------------+------------------+------------------------------------------+| mysql-bin.000003 | 643 | | | 8c1d4f3a-76af-11e8-a117-fa163e373959:1-5 |
+------------------+----------+--------------+------------------+------------------------------------------+
(2)在172.16.32.173上
mysql> show master status -> ;
+------------------+----------+--------------+------------------+------------------------------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+----------+--------------+------------------+------------------------------------------+| mysql-bin.000002 | 1803 | | | 87090287-76b2-11e8-b161-fa163e5210ea:1-5 |+------------------+----------+--------------+------------------+------------------------------------------+
配置同步信息
(1):在172.16.32.25 上:
mysql> change master to master_host='172.16.32.173',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000002',master_log_pos=1803 FOR CHANNEL 'master-2';
mysql> start slave;
(2):在172.16.32.173上
mysql> change master to master_host='172.16.32.25',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000003',master_log_pos=643 FOR CHANNEL 'master-1';
mysql> start slave;
十:配置GIt
在my.cnf 文件加入下列这三行配置:
gtid_mode = onenforce_gtid_consistency = 1
log_slave_updates = 1
客户端执行下列命令:
change master to master_host='172.16.32.173',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000002',master_log_pos=154;
报错:ERROR 1776 (HY000): Parameters MASTER_LOG_FILE, MASTER_LOG_POS, RELAY_LOG_FILE and RELAY_LOG_POS cannot be set when MASTER_AUTO_POSITION is active.
解决办法:
mysql> change master to master_auto_position=0;Query OK, 0 rows affected (0.10 sec)
mysql> change master to master_host='172.16.32.173',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000002',master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.88 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
my.cnf配置:
主1 (172.16.32.25 上的my.cnf文件内容):
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
basedir=/usr/local/mysql
port=3306
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=/usr/local/mysql/data/mysql.pid
log-error=/usr/local/mysql/data/mysql.err
server-id = 1
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1
auto_increment_offset = 1
auto_increment_increment = 2
log-bin = mysql-bin
binlog-format=ROW
#binlog-row-p_w_picpath=minimal
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=0
sync_binlog=0
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
max_binlog_size=1024M
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
replicate-ignore-db = zabbix
max_connections = 3000
max_connect_errors = 30
skip-character-set-client-handshake
init-connect='SET NAMES utf8'
character-set-server=utf8
wait_timeout=1800
interactive_timeout=1800
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 10M
bulk_insert_buffer_size = 8M
query_cache_type = 1
query_cache_size = 128M
query_cache_limit = 4M
key_buffer_size = 256M
read_buffer_size = 16K
skip-name-resolve
slow_query_log=1
long_query_time = 6
slow_query_log_file=slow-query.log
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
主2 (172.16.32.173 上的my.cnf文件内容):
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
basedir = /usr/local/mysql
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysql.pid
log-error = /usr/local/mysql/data/mysql.err
server-id = 2
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1
auto_increment_offset = 2
auto_increment_increment = 2
log-bin = mysql-bin
binlog-format=ROW
#binlog-row-p_w_picpath=minimal
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=0
sync_binlog=0
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
max_binlog_size=1024M
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
replicate-ignore-db = zabbix
max_connections = 3000
max_connect_errors = 30
skip-character-set-client-handshake
init-connect='SET NAMES utf8'
character-set-server=utf8
wait_timeout=1800
interactive_timeout=1800
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 10M
bulk_insert_buffer_size = 8M
query_cache_type = 1
query_cache_size = 128M
query_cache_limit = 4M
key_buffer_size = 256M
read_buffer_size = 16K
skip-name-resolve
slow_query_log=1
long_query_time = 6
slow_query_log_file=slow-query.log
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
主从配置
从:(在172.16.32.163上的my.cnf文件内容):
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
basedir = /usr/local/mysql
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysql.pid
log-error = /usr/local/mysql/data/mysql.err
server-id = 3
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1
#auto_increment_offset = 2
#auto_increment_increment = 2
log-bin = mysql-bin
binlog-format=ROW
#binlog-row-p_w_picpath=minimal
log-slave-updates=true
read_only=1
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=0
sync_binlog=0
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
max_binlog_size=1024M
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = test
replicate-ignore-db = zabbix
max_connections = 3000
max_connect_errors = 30
skip-character-set-client-handshake
init-connect='SET NAMES utf8'
character-set-server=utf8
wait_timeout=1800
interactive_timeout=1800
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 10M
bulk_insert_buffer_size = 8M
query_cache_type = 1
query_cache_size = 128M
query_cache_limit = 4M
key_buffer_size = 256M
read_buffer_size = 16K
skip-name-resolve
slow_query_log=1
long_query_time = 6
slow_query_log_file=slow-query.log
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
和主主配置中1-8 相同
11:同步日志配置
mysql> change master to master_host='172.16.32.25',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000003',master_log_pos=643 FOR CHANNEL 'master-1';
mysql> start slave;