mysql雙機熱備的配置步驟

來源:互聯網
上載者:User

標籤:雙機熱備   雙主   配置步驟   mysql   

設定雙機熱備:

首先要在兩台機器上建立同步處理的使用者:

grant replication slave on *.* to ‘repdcs‘@‘192.168.21.39‘ identified by ‘123456‘;   
grant all privileges on *.* to ‘repdcs‘@‘192.168.21.39  identified by ‘123456‘;
FLUSH PRIVILEGES;
grant replication slave on *.* to ‘repdcs‘@‘192.168.21.106‘ identified by ‘123456‘;   
grant all privileges on *.* to ‘repdcs‘@‘192.168.21.106 identified by ‘123456‘;
FLUSH PRIVILEGES;

庫1
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
port=3306
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
lower_case_table_names=1
default-character-set=utf8
default-storage-engine=innodb
max_connect_errors = 100000
innodb_buffer_pool_size= 8G
max_connections = 500
default-character-set=utf8
 
server-id=2
#log-bin=mysqlbin
innodb_flush_log_at_trx_commit=1
sync_binlog=1
init_connect=‘SET NAMES utf8‘
log-bin=mysqlbin
master-host=192.168.21.39
master-user=repdcs
master-pass=123456
master-connect-retry=60
replicate-do-db=dcs
master-port=3306
slave-net-timeout=60
庫2
[mysqld]
#datadir=/var/lib/mysql
datadir=/home/data/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/home/data/mysql/mysql.sock
user=mysql
port=3306
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
default-character-set=utf8
init_connect = ‘SET NAMES utf8‘
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
server-id=1
log-bin=mysqlbin
innodb_flush_log_at_trx_commit=1
sync_binlog=1
init_connect=‘SET NAMES utf8‘
log-bin=mysqlbin
master-host=192.168.21.106
master-user=repdcs
master-pass=123456
master-connect-retry=60
replicate-do-db=dcs
master-port=3306
slave-net-timeout=60
#replicate-do-db=dcs
back_log = 512
key_buffer_size = 8M
max_allowed_packet = 4M
sort_buffer_size = 6M
read_buffer_size = 4M
join_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 64
query_cache_size = 0M
tmp_table_size = 96M
max_connections = 500
table_cache= 1024
innodb_additional_mem_pool_size= 16M
innodb_log_buffer_size= 64M
read_rnd_buffer_size= 16M
innodb_buffer_pool_size= 1G
innodb_log_file_size = 256M
max_heap_table_size = 96M
innodb_data_file_path = ibdata1:200M:autoextend
default-storage-engine=innodb
max_connect_errors = 100000
long_query_time = 1
 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 
[client]
default-character-set=utf8

標紅的話主要兩台機器的不同部分。

重啟如果出問題
show slave status \G
Last_Error: Error ‘Can‘t create database ‘dcs‘; database exists‘ on query. Default database: ‘dcs‘. Query: ‘cr
查詢從庫發現需要建立的資料庫已經存在,所以可以跳過這個建庫的命令.
使用set global sql_slave_skip_counter=1;
start slave sql_thread;
flush privileges

server-id=n //設定資料庫id預設主伺服器是1可以隨便設定但是如果有多台從伺服器則不能重複。
master-host=192.168.21.39 //主伺服器的IP地址或者網域名稱
master-port=3306 //主要資料庫的連接埠號碼
master-user=repdcs //同步資料庫的使用者
master-password=123456 //同步資料庫的密碼
master-connect-retry=60 //如果從伺服器發現主伺服器斷掉,重新串連的時間差

report-host=db-slave.mycompany.com //報告錯誤的伺服器



然後重啟兩個機器的資料庫,基本就沒問題了,大致步驟給主從差不多,可以參考我的部落格 mysql主從的參數配置與步驟


mysql雙機熱備的配置步驟

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.