免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: chaoshine
打印 上一主题 下一主题

RedHat_Linux下MySQL的负载均衡问题! [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-05-21 16:45 |只看该作者
mysql主从复制
(一)安装mysql(主从服务器皆相同) 先创建用户 useradd mysql -s /sbin/nologin
tar zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45
./configure --prefix=/usr/local/mysql --localstatedir=/opt/data --with-extra-charsets=utf8,gb2312,gbk --with-pthread --enable-thread-safe-client
注:配置过程指定数据文件的位置及另加的字符集.
make
make install
cp support-files/my-large.cnf   /etc/my.cnf
cd /usr/local/mysqlchgrp -R mysql .

生成基本的数据库和表:
/usr/local/mysql/bin/mysql_install_db --user=mysql

成功执行后察看数据目录/opt/data,看是否有文件或目录生成.
chown -R mysql:mysql /opt/data

记得给每个数据库设置root密码.

(二)修改配置文件不同的地方就是server-id,主服务器配置文件不用修改,从服务器的配置文件server-id=10.其他的内容基本相同.

(三)启动服务/usr/local/mysql/bin/mysqld_safe --user=mysql& 这个过程主辅服务器都相同.

(四)授权(在主服务器上进行)GRANT REPLICATION SLAVE ON *.* to [url=mailto:]'rep1'@'192.168.8.100 identified by 'mylqs';

(五)查询主数据库状态(主服务器上进行)mysql> show master status;+------------------+----------+--------------+------------------+
| File   | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 |   235 |   |   |
+------------------+----------+--------------+------------------+记下file及position的值,后面做从服务器操作的时候需要用.

(六)配置从服务器 mysql> change master to master_host='192.168.8.101', master_user='rep1', master_password='mysql', master_log_file='mysql-bin.000003', master_log_pos=235;

正确执行后再执行:
mysql> start slave;
就启用了复制功能.这里我们运行一下 mysql> show slave status\G 来检查一下,一个正常的输出结果应该如下面的形式:

mysql> show slave statusG
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.8.101
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 235
Relay_Log_File: -relay-bin.000009
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 235
Relay_Log_Space: 235
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
请注意:slave_IO进程及slave_SQL进程都必须正常运行,在状态输出重表现为: Slave_IO_Running: Yes 及Slave_SQL_Running: Yes 否则都是不正确的状态(如一个值Yes,另外一个是NO则不行).

论坛徽章:
0
12 [报告]
发表于 2009-05-23 09:52 |只看该作者
原帖由 chaoshine 于 2009-5-17 05:44 发表
原来只有1台Linux服务器,现在增加了1台,两台服务器里都有MySQL数据库,请问如何实现双服务器里数据库的负载均衡?(本人对MySQL了解不深,只知道\s是查看负载的,所以恳请高手最好能把命令写的详细一些,在此 ...


memcached

论坛徽章:
0
13 [报告]
发表于 2009-05-23 15:07 |只看该作者

回复 #1 chaoshine 的帖子

主从设置,调整程序的不同模块,从服务器为读。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP