MySQL-Jira雙機熱備

來源:互聯網
上載者:User

標籤:ids   位置   second   show   font   ica   rem   cipher   實現   

主伺服器:192.168.1.23

從伺服器:192.168.1.243

 

一、主伺服器Master配置1. 建立同步帳號、賦權

在主伺服器上為從伺服器建立一個連線帳戶,此處用root,該帳戶必須授予REPLICATION SLAVE許可權。因為從mysql版本3.2以後就可以通過REPLICATION對其進行雙機熱備的功能操作。

mysql> grant replication slave on *.* to ‘root‘@‘192.168.1.243‘ identified by ‘123456‘;mysql> flush privileges;

建立好同步連線帳戶後,我們可以通過在從伺服器(Slave)上用replicat帳戶對主伺服器(Master)資料庫進行訪問下,看下是否能串連成功。

在從伺服器(Slave)上輸入如下指令:

[[email protected] ~]# mysql -h192.168.1.23 -uroot -p123456

2. 修改Mysql設定檔

找到mysql配置所有在目錄,一般在安裝好mysql服務後,都會將設定檔複製一一份出來放到/ect目錄下面,並且設定檔命名為:my.cnf。即設定檔準確目錄為/etc/my.cnf

項目裡的mysql設定檔在/opt/product/mysql目錄下。

[mysqld]server-id = 1log-bin=mysql-bin               binlog-do-db = jirabinlog-ignore-db = mysql
3. 重啟mysql服務

/etc/init.d/myslq restart

4. 查看主伺服器狀態
mysql> flush tables with read lock;mysql> show master status \G;*************************** 1. row ***************************             File: mysql-bin.000002         Position: 1290     Binlog_Do_DB: jira Binlog_Ignore_DB: mysqlExecuted_Gtid_Set:1 row in set (0.00 sec)ERROR:No query specified

注意看裡面的參數,特別前面兩個File和Position,在從伺服器(Slave)配置主從關係會有用到的。

註:這裡使用了鎖表,目的是為了產生環境中不讓進新的資料,好讓從伺服器定位同步位置,初次同步完成後,記得解鎖。

mysql> unlock tables;

 

二、從伺服器Slave配置1.修改設定檔

因為這裡面是以主-從方式實現mysql雙機熱備的,所以在從伺服器就不用在建立同步帳戶了,直接開啟設定檔my.cnf進行修改即可,道理還是同修改主伺服器上的一樣,只不過需要修改的參數不一樣而已。如下:

[mysqld]server-id = 2log-bin=mysql-binreplicate-do-db = jirareplicate-ignore-db = mysql,information_schema,performance_schema
2.重啟mysql服務

修改完設定檔後,儲存後,重啟一下mysql服務,如果成功則沒問題。

3.用change mster 語句指定同步位置

這步是最關鍵的一步了,在進入mysql操作介面後,輸入如下指令:

//先停步slave服務線程,這個是很重要的,如果不這樣做會造成以下操作不成功。mysql>stop slave;          mysql>change master to master_host=‘192.168.1.23‘,master_user=‘root‘,master_password=‘123456‘,master_log_file=‘ mysql-bin.000002 ‘,master_log_pos=1290;
mysql>start slave;

註:master_log_file, master_log_pos由主伺服器(Master)查出的狀態值中確定。也就是上面剛剛叫注意的。master_log_file對應File, master_log_pos對應Position。Mysql 5.x以上版本已經不支援在設定檔中指定主伺服器相關選項。

遇到的問題,如果按上面步驟之後還出現如下情況:

4.查看從伺服器(Slave)狀態
mysql> show slave status\G;*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 192.168.1.14                  Master_User: root                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysql-bin.000002          Read_Master_Log_Pos: 1290               Relay_Log_File: ha-db-relay-bin.000002                Relay_Log_Pos: 1453        Relay_Master_Log_File: mysql-bin.000002             Slave_IO_Running: Yes            Slave_SQL_Running: Yes              Replicate_Do_DB: jira          Replicate_Ignore_DB: mysql,information_schema,performance_schema           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: 1290              Relay_Log_Space: 1626              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: 0Master_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: 1                  Master_UUID: 08337b95-6e04-11e7-a595-000c2994f6ec             Master_Info_File: /opt/product/mysql/data/master.info                    SQL_Delay: 0          SQL_Remaining_Delay: NULL      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it           Master_Retry_Count: 86400                  Master_Bind:      Last_IO_Error_Timestamp:     Last_SQL_Error_Timestamp:               Master_SSL_Crl:           Master_SSL_Crlpath:           Retrieved_Gtid_Set:            Executed_Gtid_Set:                Auto_Position: 01 row in set (0.00 sec)ERROR:No query specified

查看下面兩項值均為Yes,即表示設定從伺服器成功。

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

 

三、測試同步

 

 

參考:http://blog.csdn.net/huaweitman/article/details/50853075

MySQL-Jira雙機熱備

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.