标签:ntp服务器 三台 virtual utf8 art roo pool dde mysql主从
一、概述1)不支持高并发数
2)单点故障
3)数据丢失情况
实现过程
1)当写服务器有数据写入时,数据将对应写入操纵完毕后,再将所有写入操作写入本地日志文件中(源码:/usr/local/mysql/data、RPM:/var/lib/mysql)
2)在读服务器中,一直有两个线程(I/O线程:拿取写服务器新增的日志文件内容到本地日志文件;SQL线程:从本地新增的本地日志文件中进入数据库进行重放操作)
3)读服务器的I/O线程去查询写服务器是否有新增日志文件内容,如有则将新增日志内容放在读服务器本地日志文件中
4)读服务器的SQL线程检查本地日志是否有新内容产生,如有则进行重放(将日志文件中的SQL语句都执行一次)操作
5)读服务器同步完毕后,通知写服务器,写服务器通知代理服务器,代理转告Web,Web告知客户端写入完毕
实现过程
1)客户端访问Web,如需要数据库操作,Web将请求转发到代理服务器(Amoeba)
2)代理服务器通过配置,判断为读还是为写,如为读,将请求转发到读的服务器
3)读服务器收到请求后,拿取用户所需数据返回给代理服务器,代理再转交给Web,Web再交由客户端
4)如判断为写的操作,将请求转发到写的服务器
5)写服务器收到后,写入用户所需数据后,读服务器从写服务器同步数据,同步完毕后,写服务器回应代理服务器写入完毕
6)代理服务器回应Web,Web回应客户端写入完毕
实现方式:
代码层次:由开发人员内嵌分离代码,由Web服务器中网页做判断,是读还是写
实验环境:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.30
NETMASK=255.255.255.0
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
mount /dev/cdrom /mnt
yum -y install ntp ncurses-devel cmake
vim /etc/ntp.conf
server 127.127.1.0 //指定本地作为NTP服务器
fudge 127.127.1.0 stratum 8 //指定本地优先级大于网络同步NTP
/etc/init.d/ntpd restart && chkconfig --level 35 ntpd on
tar zxvf /root/mysql-5.5.22.tar.gz -C /usr/src/
cd /usr/src/mysql-5.5.22/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/
make &&make install
cp /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
cp /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld && chkconfig --level 35 mysqld on
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile && source /etc/profile
useradd -M -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
/etc/init.d/mysqld start
vim /etc/my.cnf
50 log-slave-updates=true //允许从服务器同步
58 server-id=10 //标识符,三台不能一样
/etc/init.d/mysqld restart
mysql -u root -p
mysql> grant replication slave on *.* to ‘slave‘@‘192.168.1.%‘ identified by ‘123‘; //新建同步用户,专用于同步
mysql> flush privileges;
mysql> show master status; ##记住File的及Position的值,此处为master-bin.000001和337
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
mount /dev/cdrom /mnt
yum -y install ntp ncurses-devel cmake
ntpdate 192.168.1.30
tar zxvf /root/mysql-5.5.22.tar.gz -C /usr/src/
cd /usr/src/mysql-5.5.22/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/
make &&make install
cp /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
cp /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld && chkconfig --level 35 mysqld on
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile && source /etc/profile
useradd -M -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
/etc/init.d/mysqld start
vim /etc/my.cnf
50 relay-log=relay-log-bin //指定从服务器日志文件名
51 relay-log-index=slave-relay-bin.index //指定从服务器索引文件名
59 server-id=20
/etc/init.d/mysqld restart
mysql -u root -p
mysql> change master to master_host=‘192.168.1.30‘,master_user=‘slave‘,master_password=‘123‘,master_log_file=‘master-bin.000001‘,master_log_pos=333;
选项
master_host:指定主服务器IP
master_user:指定连接主服务器用户
master_password:指定连接主服务器用户的密码
master_log_file:指定主服务器日志文件名;主服务器show master status;查看
master_log_pos:指定主服务器的偏移值;主服务器show master status;查看
mysql> start slave;
mysql> show slave status \G;
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.20
NETMASK=255.255.255.0
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
mount /dev/cdrom /mnt
yum -y install ntp ncurses-devel cmake
ntpdate 192.168.1.30
tar zxvf /root/mysql-5.5.22.tar.gz -C /usr/src/
cd /usr/src/mysql-5.5.22/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/
make &&make install
cp /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf
cp /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld && chkconfig --level 35 mysqld on
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile && source /etc/profile
useradd -M -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
/etc/init.d/mysqld start
vim /etc/my.cnf
50 relay-log=relay-log-bin
51 relay-log-index=slave-relay-bin.index
59 server-id=30
/etc/init.d/mysqld restart
mysql -u root -p
mysql> change master to master_host=‘192.168.1.30‘,master_user=‘slave‘,master_password=‘123‘,master_log_file=‘master-bin.000001‘,master_log_pos=333;
mysql> start slave;
mysql> show slave status \G;
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.254
NETMASK=255.255.255.0
yum -y erase java-*
chmod +x jdk-6u14-linux-x64.bin
./jdk-6u14-linux-x64.bin
mv jdk1.6.0_14/ /usr/local/jdk1.6
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba
export PATH=$PATH:$AMOEBA_HOME/bin
source /etc/profile && java -version
mkdir /usr/local/amoeba
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod -R 755 /usr/local/amoeba/
mysql -u root -p
mysql> grant all on *.* to haha@‘192.168.1.%‘ identified by ‘123‘;
vim /usr/local/amoeba/conf/amoeba.xml
30 <property name="user">hehe</property> //设置连接Amoeba用户
32 <property name="password">123</property> //设置连接Amoeba用户
115 <property name="defaultPool">master</property>
117 <property name="writePool">master</property> 注意删除<!-- -->的注释
118 <property name="readPool">slaves</property> //定义读服务器池
vim /usr/local/amoeba/conf/dbServers.xml
25 <!-- mysql user -->
26 <property name="user">haha</property> //设置连接Mysql的用户
28 <property name="password">123</property> //设置连接mysql的密码
**注意删除<!-- -->的注释**
43 <dbServer name="master" parent="abstractServer">
44 <factoryConfig>
45 <!-- mysql ip -->
46 <property name="ipAddress">192.168.1.10</property> //定义写服务器IP
47 </factoryConfig>
48 </dbServer>
49 <dbServer name="slave1" parent="abstractServer">
50 <factoryConfig>
51 <!-- mysql ip -->
52 <property name="ipAddress">192.168.1.20</property> //定义读服务器IP
53 </factoryConfig>
54 </dbServer>
55 <dbServer name="slave2" parent="abstractServer">
56 <factoryConfig>
57 <!-- mysql ip -->
58 <property name="ipAddress">192.168.1.30</property> //定义读服务器IP
59 </factoryConfig>
61 </dbServer>
62 <dbServer name="slaves" virtual="true">
68 <property name="poolNames">slave1,slave2</property> //定义输入slaves读服务器池的主机
69 </poolConfig>
amoeba start &
netstat -utpln | grep 8066
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
mount /dev/cdrom /mnt
yum -y install mysql
mysql -u hehe -p -h 192.168.1.254 -P 8066
mysql>show databases;
mysql>create dabase hehe;
mysql>show datasbases;
标签:ntp服务器 三台 virtual utf8 art roo pool dde mysql主从
原文地址:http://blog.51cto.com/13770206/2160189