在Linux系統中做MySQL資料庫主從伺服器

來源:互聯網
上載者:User

在Linux系統中做MySQL資料庫主從伺服器

1.網路設定
伺服器A:
[root@CentOS mysql-5.0.40]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:56:AA:AA
inet addr:2.2.2.135  Bcast:2.255.255.255  Mask:255.0.0.0
inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:104974 errors:0 dropped:0 overruns:0 frame:0
TX packets:54283 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:66204315 (63.1 MiB)  TX bytes:4929056 (4.7 MiB)
[root@centos mysql-5.0.40]# hostname
centos
[root@centos mysql-5.0.40]# vim /etc/hosts
2.2.2.145 centos1
2.2.2.135 centos

伺服器B:
[root@centos1 ~]# ifconfig  eth0
eth0      Link encap:Ethernet  HWaddr 08:00:27:56:AA:AA
inet addr:2.2.2.145  Bcast:2.2.2.255  Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:96078 errors:0 dropped:0 overruns:0 frame:0
TX packets:52141 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60024368 (57.2 MiB)  TX bytes:34512758 (32.9 MiB)
[root@centos1 ~]# hostname
centos1
[root@centos1 ~]# vim /etc/hosts
2.2.2.135  centos
2.2.2.145  centos1
[root@centos1 ~]# ping -c 2 2.2.2.135
PING 2.2.2.135 (2.2.2.135) 56(84) bytes of data.
64 bytes from 2.2.2.135: icmp_seq=1 ttl=64 time=0.763 ms
64 bytes from 2.2.2.135: icmp_seq=2 ttl=64 time=0.758 ms
--- 2.2.2.135 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1003ms
rtt min/avg/max/mdev = 0.758/0.760/0.763/0.027 ms
[root@centos1 ~]#

2.安裝mysql軟體
伺服器A:
[root@centos mysql-5.0.40]# yum install mysql mysql-server -y    --安裝mysql
[root@centos mysql-5.0.40]# /etc/init.d/mysqld restart    --啟動mysql
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos mysql-5.0.40]# netstat -an |grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                  LISTEN
[root@centos mysql-5.0.40]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database tong;    --建立要共用資料庫
Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on *.* to abc@'*' identified by 'system';  --給資料庫授權
Query OK, 0 rows affected (0.01 sec)
mysql>
[root@centos mysql-5.0.40]# vim /etc/my.cnf  --在mysqld下添加以下
server_id=1
binlog-do-db=tong
binlog-ignore-db=mysql
bin-log=mysql-log
[root@centos mysql-5.0.40]# /etc/init.d/mysqld restart    --啟動成功
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos mysql-5.0.40]#

伺服器B:
[root@centos1 ~]# yum install mysql mysql-server
[root@centos1 ~]# /etc/init.d/mysqld  restart
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos1 ~]# netstat -an |grep 3306
tcp        0      0 127.0.0.1:3306              0.0.0.0:*                  LISTEN
[root@centos1 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database tong;
Query OK, 1 row affected (0.00 sec)
mysql> quit
[root@centos1 ~]# vim /etc/my.cnf
server_id=2
master_host=2.2.2.135
master_user=abc
master_password=system
master-port=3306
replicate_do_db=tong
master_connect_retry=10
log-bin=mysql1-log
[root@centos1 ~]# /etc/init.d/mysqld  restart
Stopping mysqld:                                          [  OK  ]
Starting mysqld:                                          [  OK  ]
[root@centos1 ~]#

推薦閱讀:

Ubuntu下Nginx做負載實現高效能WEB伺服器5---MySQL主主同步

生產環境MySQL主主同步主鍵衝突處理

MySQL主從失敗 錯誤Got fatal error 1236

MySQL主從複製,單台伺服器上實施

  • 1
  • 2
  • 下一頁

相關文章

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.