需求:
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),新田企業(yè)網(wǎng)站建設(shè),新田品牌網(wǎng)站建設(shè),網(wǎng)站定制,新田網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,新田網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
由于要使用saltstack,部署環(huán)境,先手動(dòng)搭建了下主從環(huán)境,發(fā)現(xiàn)原來的word資料都找不到了,所以這次趕緊的記錄到博客當(dāng)中!!
環(huán)境:
兩臺(tái)設(shè)備,ip地址分別為:
node1:192.168.56.11
node2:192.168.56.12
系統(tǒng):Centos7
軟件包:使用系統(tǒng)自帶的yum 來安裝的mariadb
==========================================================================================
安裝:
分別在兩臺(tái)設(shè)備上安裝數(shù)據(jù)庫mariadb,使用yum來安裝的,可以更換成過內(nèi)的yum源來操作
命令:yum install -y mariadb mariadb-server
配置:
先配置node1上的master配置
[root@salt-node1 ~]# vim /etc/my.cnf [MySQLd] innodb_file_per_table=NO log-bin=/var/lib/mysql/master-bin #這里如果不指定路徑默認(rèn)是在datadir下面生成 binlog_format=mixed server-id = 11#這個(gè)主節(jié)點(diǎn)一定要是唯一的 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 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 mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
重啟node1上的mysql服務(wù)
systemctl restart mariadb.service
登錄mysql:
mysql -uroot -p 我這里測(cè)試就沒有設(shè)置密碼
創(chuàng)建帳號(hào)并賦予replication的權(quán)限。從庫,主從庫復(fù)制數(shù)據(jù)時(shí)需要使用這個(gè)帳號(hào)進(jìn)行
grant replication slave on *.* to 'root'@'192.168.56.%' identified by '123456';
加鎖:
實(shí)際工作中,需要禁止數(shù)據(jù)庫的寫入,要給數(shù)據(jù)庫上鎖
FLUSH TABLES WITH READ LOCK;
記錄主庫的binlog日志文件和位置信息(這個(gè)信息,要在從庫配置的時(shí)候用到)
MariaDB [(none)]> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-bin.000001 | 398 | | | +-------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
備份主庫的數(shù)據(jù):
mysqldump -uroot -p --all-databases > /tmp/db.sql
==========================================================================================
下面開始配置從庫:
導(dǎo)入數(shù)據(jù)到從庫當(dāng)中
mysql -uroot -p </tmp/db.sql
修改配置文件my.cnf:
[root@salt-node2 ~]# cat /etc/my.cnf [mysqld] innodb_file_per_table=NO #log-bin=mysql-bin binlog_format=mixed server-id = 12 relay-log = /var/lib/mysql/relay-bin #log_slave_updates = 1 read_only = on datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 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 mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
重啟服務(wù):
systemctl restart mariadb.service
登錄mysql
mysql -uroot -p
設(shè)置主從服務(wù)配置
CHANGE MASTER TO MASTER_HOST='192.168.56.11',MASTER_USER='root', MASTER_PASSWORD='123456', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS= 398;
開啟主從服務(wù):
start slave;
查看從庫狀態(tài):
MariaDB [(none)]> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.56.11 Master_User: root Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 485 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 617 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 485 Relay_Log_Space: 905 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 11 1 row in set (0.00 sec) ERROR: No query specified
Slave_IO_Running: Yes #這里必須為yes,如果不是,需要排查故障 Slave_SQL_Running: Yes #這里必須為yes,如果不是,需要排查故障
主從驗(yàn)證,
#主庫創(chuàng)建數(shù)據(jù)庫 MariaDB [(none)]> create database jiayou ; Query OK, 1 row affected (0.00 sec) #從庫查看是否同步過來這個(gè)數(shù)據(jù)庫 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | gg | | jiayou | | kk | | mysql | | performance_schema | | salt | | test | +--------------------+ 8 rows in set (0.00 sec)
有時(shí)候會(huì)有一些故障問題,可以參考下面這個(gè)博客,自己懶的寫了
http://blog.csdn.net/mingliangniwo/article/details/54606894?locationNum=8&fps=1
新聞標(biāo)題:centos7maiadb主從復(fù)制搭建
文章起源:http://vcdvsql.cn/article12/pdeigc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、域名注冊(cè)、用戶體驗(yàn)、App開發(fā)、網(wǎng)站導(dǎo)航、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)