linux下高可用mysql
作者 佚名技术
来源 Linux系统
浏览
发布时间 2012-04-07
MySQL主从双向复制(脚本实现) 1主服务器的主机名为:master,从服务器的主机名为:slave 2安装MYSQL包 # rpm –ivh mysql-5.0.77-4.2.1.AXS3.i386.rpm 3在主库启动MYSQL #service mysql start 4在主库编辑/etc/my.cnf, #vim /etc/my.cnf 在[mysqld]配置段添加如下字段 server-id=1 log-bin=cjxylog 编辑好my.cnf后重启mysql #service mysqld restart 5主库增加用户,用于从库读取主库日志 >grant replication slave on *.* to ''slave''@''10.10.10.52'' identified by ''slave''; 启动后用show master status查看主库的日志文件 #mysql >show master status 6启动从库的mysql #service mysqld start 7修改从库/etc/my.cnf,增加选项: #Mysql #vim /etc/my.cnf 添加如下内容 server-id=2 master-host=10.10.10.51 master-user=slave master-password=slave master-port=3306 master-connect-retry=60 编辑完后重启mysql #service mysqld restart 8重启后用show命令查看从库slave的运行情况 #mysql >stop slave; >start slave; >show slave statusG; 9测试 主库创建名为cjxy的数据库并用show databases;命令查看 #mysql >start master >create database cjxy; >show databases; 从库只须用show命令查看即可 #mysql >show databases; 10单向复制成功,编写脚本,实现主从双向复制和故障自动切换角色 ,从而实现MYSQL数据库高可用性. 在两台MYSQL服务器上配置3份MYSQL服务配置文件 分别为: /etc/my.cnf /etc/my.cnf.master /etc/my.cnf.slave 其中,原主库服务器(IP地址:10.10.10.51)配置文件内容如下: 拥有帝国一切,皆有可能。欢迎访问phome.net /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql server-id=1 log-bin=cjxylog # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 # Disabling symbolic-links is recommended to prevent assorted security risks; # to do so, uncomment this line: # symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid /etc/my.cnf.master [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql server-id=1 log-bin=cjxylog # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 # Disabling symbolic-links is recommended to prevent assorted security risks; # to do so, uncomment this line: # symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid /etc/my.cnf.slave [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql server-id=2 master-host=10.10.10.52 master-user=slave master-password=slave master-port=3306 master-connect-retry=60 # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwords=1 # Disabling symbolic-links is recommended to prevent assorted security risks; # to do so, uncomment this |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: Linux思莱培训下一篇: linux下多线程下载工具prozilla
关于linux下高可用mysql的所有评论