本文僅爲記錄本人的安裝過程mysql
系統:centos7.4linux
MYSQL:5.7.21sql
一、關掉服務器(主備兩臺)的selinux數據庫
vim /etc/selinux/config
將其中的SELINUX的值,修改成:disabled,如:vim
二、關閉防火牆centos
主備兩臺都要關閉服務器
systemctl stop firewalld.service systemctl disable firewalld.service
若是是能夠聯網的話,能夠經過在線安裝,沒有聯網的,能夠下載rpm的集合包來安裝,如下以在線方式安裝socket
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm rpm -ivh mysql57-community-release-el7-11.noarch.rpm
(2)安裝mysqlide
yum -y install mysql-server
內容以下:優化
[client]
port = 3306
socket = /work/mysql/mysql.sock
[mysqld]
datadir=/work/mysql
socket=/work/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/work/mysql/mysqld.log
pid-file=/work/mysql/mysqld.pid
# config master for replication start.
log-bin = /work/mysql/binlog/mysql-bin.log
server-id = 128
binlog_format = ROW
binlog-row-image = FULL
binlog_cache_size = 4M
max_binlog_size = 1G
max_binlog_cache_size = 2G
sync_binlog = 0
slave-skip-errors = 1062
expire_logs_days = 3
slave_parallel_workers = 4
# config master for replication end.
將絕色部分替換成你本身的數據目錄 便可。
配置最後一段是主從數據中主數據的配置,server-id是用來標識惟一性的,最好直接取當前主機ip的最後幾個位數字,這樣能夠避免server-id重複。
備庫的配置以下:
# config slave for replication start. server-id=131 relay-log = /work/mysql/binlog/relaylog max_relay_log_size = 1G relay_log_purge = 1 relay_log_recovery = 1 binlog_checksum = CRC32 slave_allow_batching = 1 master_verify_checksum = 1 binlog_rows_query_log_events = 1 master_info_repository = TABLE relay_log_info_repository = TABLE log_slave_updates sync_binlog = 0 # config slave for replication end.
其它配置同主庫同樣,也能夠本身去調整,一般備庫主要用來讀,不會去寫數據。
mysqld --initialize --datadir=/work/program/mysql --user=mysql
主備數據庫都須要先初始化數據庫。
datadir是我本身mysql數據庫將要放置的目錄,你也能夠修改本身的目錄。
初始化完成後,會在mysql的日誌文件中輸出一個臨時密碼,日誌大體是這個樣子:
[Note] A temporary password is generated for root@localhost: o:uEY62ecdc*
這個密碼要記住,第六步須要登陸使用,而後修改成本身的密碼
systemctl start mysqld.service
執行命令以下
mysql -uroot -p //回車後會提示輸入密碼,然第四步中的密碼粘貼過來,而後回車便可 mysql>set password=password('your password'); mysql>quit; //而後用新密碼登陸便可
在master的服務器上增長一個用於備機同步的數據庫用戶
GRANT REPLICATION SLAVE ON *.* to 'rep1'@'10.0.30.114' identified by 'rep1';
10.0.30.114是備機的ip地址。增長了同步用戶rep1,密碼爲rep1。
(1)查看master的狀態
show master status;
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000005 | 11958906 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
上面顯示當前bin-log的名字爲mysql-bin.000005,當前bindlog的位置position是:11958906
(2)設置slave
mysql> change master to -> master_host='10.0.30.81', -> master_user='rep1', -> master_password='rep1', -> master_port=3306, -> master_log_file='mysql-bin.000005', -> master_log_pos=11958906, -> master_connect_retry=10; mysql> start slave; mysql>set global read_only=1;
設置master的信息,並設置slave爲read_only的狀態
(3)查看slave的狀態
這個版本的配置主要是針對配置8G內存的優化方案,僅供參考
https://files.cnblogs.com/files/cw2030/mysql-master-slve.zip