Heim  >  Artikel  >  Datenbank  >  在Linux系统中做MySQL数据库主从服务器

在Linux系统中做MySQL数据库主从服务器

WBOY
WBOYOriginal
2016-06-07 17:34:021058Durchsuche

在Linux系统中做MySQL数据库主从服务器 1.网络配置服务器A:[root@CentOS mysql-5.0.40]# ifconfig eth0 eth0 Link encap:E

在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主从复制,,单台服务器上实施

linux

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:Oracle数据库 ORA-01555 快照过旧Nächster Artikel:Oracle分区表迁移