这样master 就有了CDN库的数据结构。
Slave一样。这样不再重复
2设置主服务器Master的my.cnf,启动Mysql服务
Master# vi/etc/my.cnf
在[mysqld]添加或修改以下的
[mysqld]
log-bin = /home/data/mysql/data/binlog/binlog#打开logbin选项以能写到slave的 I/O线程;
server-id=1 #表示是本机的序号为1,一般来讲就是master的意思.
binlog-do-db= cdn #表示同步cdn数据库;
PS:提供的My。Cnf 比较详细。
然后把Master主服务器的Mysql重启。
Master# servicemysqld restart
4、修改Slave服务器的my.cnf
Slave# vi/etc/my.cnf
在[mysqld]添加或修改以下的
master-host=192.19.13.15
master-user=slaverep
master-password=linuxtone.org
master-port=3306
server-id=10
master-connect-retry=60
replicate-do-db=cdn [要更新的数据库]
log-slave-updates
5、删除Slave端数据库目录中的master.info
Slave# rm -fmaster.info
6、重启动Slave的slave start。
Slave#servicemysqld restart
7、测试先检测两个Mysql数据库中的cdn是否正常。正常情况应该是Master和Slave 中的Mysql 都有相同的cdn 数据库,并且里面的数据都一样。然后测试replication 功能是否起用。在Master中的reptest数据库添加一笔数据:
Master#mysql –u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 5.1.51
Type 'help;'or '\h' for help. Type '\c' to clear the buffer.
mysql>use cdn;
Database changed
mysql> INSERT INTO rep_table VALUES ('test1', '4321', 'T',24);
Query OK, 1 row affected (0.00 sec)
mysql>
然后查看Slave机器的reptest数据库:
Slave#mysql–u root –p
Enterpassword:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 5.1.49
Type 'help;'or '\h' for help. Type '\c' to clear the buffer.
mysql>use cdn;
Database changed
mysql>select * from reptable;;
+------+------+------+------+
| id | name| sex | age |
+------+------+------+------+
| test1|4321 | T | 24 |
+------+------+------+------+
1 row in set(0.00 sec)
为mysql 添加TCMalloc库降低系统负载
TCMalloc(Thread-CachingMalloc)是google开发的开源工具──“google-perftools”中的成员。与标准的glibc库的malloc相比,TCMalloc在内存的分配上效率和速度要高得多,可以在很大程度上提高MySQL服务器在高并发情况下的性能,降低系统负载。
1、64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。
wget
tar zxvf libunwind-0.99.tar.gz
cd libunwind-0.99/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
2、安装google-perftools:
wget
tar zxvf google-perftools-1.6.tar.gz
cd google-perftools-1.6/
./configure
make && make install
echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
3、修改MySQL启动脚本(根据你的MySQL安装位置而定):
vi /usr/local/mysql/bin/mysqld_safe
在# executingmysqld_safe的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
保存后退出,然后重启MySQL服务器。
4、使用lsof命令查看tcmalloc是否起效: lsof -n | grep tcmalloc
如果发现以下信息,说明tcmalloc已经起效:
mysqld 10847 mysql mem REG 8,5 1203756 20484960/usr/local/lib/libtcmalloc.so.0.0.0
四.安装配置Bind-DLZ 及相关脚本
1.安装bind
#mkdir /usr/local/src/bind-dlz
#cd /usr/local/src/bind-dlz
#wget
#tar zxvf bind-9.6.0-P1.tar.gz
#cd bind-9.6.0-P1
#./configure --with-dlz-mysql --enable-largefile --enable-threads=no--prefix=/usr/local/bind
#make –j4 && make install
2.创建相关配置文件
cd /usr/local/bind/etc
../sbin/rndc-confgen >rndc.conf
tail -n10 rndc.conf | head -n9 | sed -e s/#\//g >named.conf
# vilocalhost.zone
ttl 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
1 IN PTR localhost.
# dig >named.root
#vi named.conf 在后面加入如下:
include"/usr/local/bind/etc/cnc_acl.conf"; //网通ACL
include "/usr/local/bind/etc/telecom_acl.conf"; //电信ACL
include "/usr/local/bind/etc/edu_acl.conf"; //教育网ACL
include "/usr/local/bind/etc/view.conf"; //DLZ相关的配
3、配置DNSTSIG
1、使用dnssec-keygenfunction 产生加密密钥,一个为public key,另一
个为private key,本文假设应用服务器存在CNC,TELECOM,EDU,ANY
(1)产生加密金钥
#cd /usr/local/bind/sbin
#./dnssec-keygen -a hmac-md5 -b 128 -n HOSTcnc
#./dnssec-keygen -a hmac-md5 -b 128 -n HOSTtelecom
#./dnssec-keygen -ahmac-md5 -b 128 -n HOST edu
#./dnssec-keygen -a hmac-md5 -b 128 -n HOST any
(2)查看生成的密钥文件
# cat Kcnc.+157+24406.private //以网通为例.
Private-key-format: v1.2
Algorithm: 157 (HMAC_MD5)
Key: YTjTOw00PzeEaasA16/Rvw==
Bits: AAA=
将:YTjTOw00PzeEaasA16/Rvw== 加入到named.conf,其它同例。
详细请参照named.conf配置文件
2、配置named.conf
#vi /usr/local/bind/etc/named.conf
key "rndc-key" {
algorithm hmac-md5;
secret "5PubnjGuAWeH9F2dIUYd6g==";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys {"rndc-key"; };
};
#
options {
directory "/usr/local/bind/etc";
pid-file "named.pid";
};
#TSIG-key
key "cnc" {
algorithm hmac-md5;
secret "YTjTOw00PzeEaasA16/Rvw==";
};
key "telecom" {
algorithm hmac-md5;
secret"pUcQGLpSH2tQgVZ9ZHU6Yg==";
};
key "edu"{
algorithm hmac-md5;
secret"Bzo6MTzrzbRFQbONYTS1Cw==";
};
key "any"{
algorithm hmac-md5;
secret"DHpPfGJdMLv91OygBf9H6w==";
};
#acl
acl"dns-ip-list"{
172.19.3.15; #masterDNS IP
172.19.1.3; #slaveDNS IP
};
#acl include
include"/usr/local/bind/etc/cnc_acl.conf"; //网通ACL
include"/usr/local/bind/etc/telecom_acl.conf"; //电信 ACL
include"/usr/local/bind/etc/edu_acl.conf"; //教育网ACL
include"/usr/local/bind/etc/view.conf"; //bind-view部分
3.Bind 启动脚本
#!/bin/sh
# powered bydz
case"$1" in
start)
if [ -x/usr/local/bind/sbin/named ]; then
/usr/local/bind/sbin/named-c /usr/local/bind/etc/named.conf -u bind
echo"BIND9-named server started"
fi
;;
stop)
kill `cat/usr/local/bind/etc/named.pid` && echo . && echo 'BIND9 serverstopped'
;;
restart)
echo .
echo"Restart BIND9 server"
$0 stop
sleep 10
$0 start
;;
reload)
/usr/local/bind/sbin/rndcreload
;;
status)
/usr/local/bind/sbin/rndcstatus
;;
*)
echo"$0 start | stop | restart |reload |status"
;;
esac
./bind9 start 启动bind;./bind9 stop停止bind;
./bind9 reload #重载配置文件
剩余文档见打包的bind-dlz.tar.gz。里面很详细。部署的master时候用tar zvxf bind-dlz-tar.gz –C /usr/local/bind/etc覆盖即可,剩下的slave在部署bind还是将配置文件解压到/usr/local/bind/etc/即可,将rndc-key 和dnssec重新配置一遍就可以用了!
部署DNS,防火墙和路由器要设置清楚,我部署的时候就是因为黑洞防火墙没有对master和slave服务器开放tcp和udp53端口,造成不能解析域名。需要大家切记!
MYSQL Master info