日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Mysql的master,slave的配置

 Frank__Library 2014-10-10
MYSQLmaster,slave環(huán)境的搭建
試驗(yàn)環(huán)境:
Linux5.5(32bit)
撰寫人:hx10
日期:2010/7/3  hangzhou
Blog:http://hi.baidu.com/hx10
試驗(yàn)環(huán)境:
Master:10.80.11.203
Slave1:10.80.11.204
Slave2:10.80.11.205
 
安裝mysql
 
cd /usr/local
tar -zxvf mysql-5.1.48-linux-i686-glibc23.tar.gz
mv mysql-5.1.48-linux-i686-glibc23  mysql
groupadd mysql
useradd -g mysql mysql
cd /usr/local/mysql
chown -R root /usr/local/mysql
chgrp -R mysql /usr/local/mysql
chown -R mysql /usr/local/mysql/data
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
 
增加環(huán)境變量
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile
 
主節(jié)點(diǎn):     
首先在master上建立2個(gè)數(shù)據(jù)庫和表
#service mysqld start
#mysql
mysql>create database www;
mysql>use www;
mysql>create table www(id int);
mysql>insert into www values(1);
mysql> select * from www;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.01 sec)
 
 
mysql>create database blog;
mysql>use blog;
mysql>create table blog(id int);
mysql>insert into blog values(1);
mysql> select * from blog;
+------+
| id   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)
 
 
1.vim /etc/my.cnf
注意一下2個(gè)參數(shù),這一段在[mysqld]節(jié)點(diǎn)中添加
log-bin=mysql-bin       //日志為2進(jìn)制,不需要更改
server-id    =1         //1就是Master,不需要更改
binlog-do-db=blog        //要同步的庫
binlog-do-db=www         //要同步的庫
binlog-ignore-db=mysql,test,information_schema   //是不要記錄日志的數(shù)據(jù)庫名,多個(gè)數(shù)據(jù)庫中間用逗號(hào)(,)隔開
 
 
然后把innodb前面的#去掉,結(jié)果如下
innodb_data_home_dir = /usr/local/mysql/data/      //innodb的表空間位置
innodb_data_file_path = ibdata1:50M:autoextend     //表空間的名字,開始50M
innodb_log_group_home_dir = /usr/local/mysql/data/ 
innodb_buffer_pool_size = 256M                     //為系統(tǒng)內(nèi)存的50-80%
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
 
 
 
然后啟動(dòng)數(shù)據(jù)庫,讓配置文件生效
#service mysqld restart
 
2.master服務(wù)器添加要從slave服務(wù)器訪問master服務(wù)器的有權(quán)限的賬號(hào)
 
#mysql -u root -p
mysql>grant replication slave on *.* to repluser@'10.80.11.204' identified by '123456';
mysql>grant replication slave on *.* to repluser@'10.80.11.205' identified by '123456';
mysql>flush privileges;
 
 
格式:GRANT REPLICATION SLAVE ON *.* TO '賬號(hào)'@'從服務(wù)器IP或主機(jī)名' IDENTIFIED BY '密碼';
 
3.備份master數(shù)據(jù)庫數(shù)據(jù)
mysql> flush tables with read lock;  //不要退出這個(gè)終端,否則這個(gè)鎖就不生效了。從服務(wù)器的數(shù)據(jù)庫建好后。在主服務(wù)器執(zhí)行解鎖
 
同時(shí)要記錄下mysql-bin.0000031271
mysql> show master status;
+------------------+----------+--------------+-------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB              |
+------------------+----------+--------------+-------------------------------+
| mysql-bin.000002 |      106 | blog,www     | mysql,test,information_schema |
+------------------+----------+--------------+-------------------------------+
1 row in set (0.01 sec)
取得快照并記錄日志名和偏移量
 
開啟另一個(gè)終端對主服務(wù)器數(shù)據(jù)目錄做快照。
#cd /usr/local/mysql/data
#tar -zcvf backup.tar.gz www blog
 
此時(shí)在主庫解開table的鎖定
mysql> unlock tables;
 
 
從節(jié)點(diǎn):
 
安裝mysql方法同主節(jié)點(diǎn)
1. vim /etc/my.cnf   增加以下幾項(xiàng)
server-id  = 2
master-host     =   10.80.11.203
master-user     =   repluser
master-password =   123456
master-port     =  3306
master-connect-retry=60
replicate-do-db=www   //告訴slave只做www數(shù)據(jù)庫的更新 
replicate-do-db=blog  //告訴slave只做blog數(shù)據(jù)庫的更新 
log-slave-updates
 
3.把從主數(shù)據(jù)庫服務(wù)器備份出來的數(shù)據(jù)庫導(dǎo)入到從服務(wù)器中
先用scp把主服務(wù)器上的backup.tar.gz拷貝過來,解壓到/usr/local/mysql/data目錄
#cd /usr/local/mysq/data
#tar -zxvf backup.tar.gz
 
 
 
啟動(dòng)從庫服務(wù)器
#service mysqld start
停止slave服務(wù),設(shè)置主服務(wù)器的各種參數(shù)
#mysql
mysql>slave stop;
然后敲入以下代碼,一行一行的復(fù)制
change master to
MASTER_HOST='10.80.11.203',
MASTER_USER='repluser',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000002',
MASTER_LOG_POS=106;
mysql> slave start;
 
然后在master上插入記錄,會(huì)發(fā)現(xiàn)在slave上也會(huì)出現(xiàn)
 
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.80.11.203
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 1271
               Relay_Log_File: squid2-relay-bin.000004
                Relay_Log_Pos: 617
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: www,blog
          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: 1271
              Relay_Log_Space: 773
              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:
1 row in set (0.01 sec)
 
從節(jié)點(diǎn)2的配置跟從節(jié)點(diǎn)1的配置一樣,只是server-id  改成3
 
 
最重要是以下三點(diǎn):
 
Slave_IO_Running
是否要從 Master Server 復(fù)製 Binary Log 資料,必須為 Yes。
 
Slave_SQL_Running
是否要執(zhí)行從 Master Server 復(fù)製過來的 Binary Log 資料,必須為 Yes。
 
Seconds_Behind_Master
Slave 的資料落后了 Master 多少秒,執(zhí)行一段時(shí)間后應(yīng)該會(huì)是零。
然后在master上更新數(shù)據(jù),會(huì)發(fā)現(xiàn)在2臺(tái)slave上都能查詢到數(shù)據(jù),本實(shí)驗(yàn)測試成功。

本文出自 “無云安全技術(shù)站” 博客,請務(wù)必保留此出處http://hx100.blog.51cto.com/44326/343390

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多