本人通过虚拟机配置mysql以及mysql-mmm,遇到一些问题,记录下以便以后查询
1)虚拟机 eth0 网卡无效问题
通过克隆产生的虚机,eth0网卡会失效,需要执行 sudo rm /etc/udev/rules.d/70-persistent-net.rules
2) 更改hostname
vi /etc/sysconfig/network
networking=yes
hostname=db2.localdomain
vi /etc/sysconfig/network-scripts/ifcfg-eth0
vi etc/resolv.conf
3) 先检查是否安装gcc,没有就需要安装
yum -y install gcc
yum -y install gcc-c++
4)mysql安装
tar xvf mysql-5.5.23-linux2.6-x86_64.tar.gz
cp -r mysql-5.5.23-linux2.6-x86_64 /usr/local/
cd /usr/local
ln -s mysql-5.5.23-linux2.6-x86_64 mysql
5)增加mysql用户和用户组,设置访问权限
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql/
6) 设置mysql配置
mysql文件夹下
cp support-files/my-medium.cnf /etc/my.cnf
7)编辑my.cnf
db1,db2,db3的server_id设置成不同的值1,2,3。
vi /etc/my.cnf
#add
default-storage-engine = innodb
replicate-ignore-db = mysql
binlog-ignore-db = mysql
log-bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-bin.relay
relay_log_index = /var/log/mysql/mysql-bin.relay.index
expire_logs_days = 10
max_binlog_size = 100M
skip-name-resolve
log_slave_updates
因为在这里把log文件配置到了/var/log/mysql下,而mysql默认的目录是在/var/lib/mysql,所以首先要新建mysql文件夹,然后用chown -R mysql.mysql mysql命令将mysql的所有者修改为用户mysql。其次要保证,mysql文件夹的权限755(即-rwxr-xr-x)
8)建立数据存储路径
mkdir -p /data/mysql/db
chown -R mysql:mysql /data/mysql/
9)初始化数据库
需要设置mysql/bin下权限
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/db --basedir=/usr/local/mysql
10)将mysqld服务加入开机启动项
首先需要将scripts/mysql.server服务脚本复制到/etc/init.d,并重命名mysqld
cp support-files/mysql.server /etc/init.d/mysqld
通过chkconfig命名将mysqld服务加入到自启动服务中
chkconfig --add mysqld
检查是否启动 netstat -anp|grep mysqld
直接手动启动 service mysqld start
11)把mysql命令加入环境变量中
vi /etc/profile
MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
12)设置root密码
/usr/local/mysql/bin/mysqladmin -u root password 'qwpassword'
13)登录mysql,设置权限
mysql -uroot –p
grant replication slave on *.* to 'slave'@'%' identified by 'slave';
grant all privileges on *.* to 'root'@'%' identified by 'root';
grant replication client,process,super on *.* to 'mmm_agent'@'%' identified by 'mmm_agent';
grant replication client on *.* to 'mmm_monitor'@'%' identified by 'mmm_monitor';
grant replication client,reload,super on *.* to 'mmm_tools'@'%' identified by 'mmm_tools';
flush privileges;
14) 设置主从配置
change master to master_host='192.168.0.112',master_user='slave',master_password='slave',master_port=3306,master_log_file='mysql-bin.000001',master_l og_pos=0,master_connect_retry=10;
start slave;
show slave status\G;
stop slave;停止slave
15) mysql-mmm安装 需要的perl
在 db1,db2,db3上都安装如下perl库(mysql-agent需求的perl库)
yum -y install wget perl* (有问题,V5.10.0这个版本没有问题)
db上均安装perl需要的插件
perl -MCPAN -e shell
cpan> install Algorithm::Diff
cpan> install DBI
cpan> install Log::Dispatch
cpan> install Log::Log4perl
cpan> install Mail::Send
cpan> install Net::ARP
cpan> install Proc::Daemon
cpan> install Time::HiRes
cpan> install DBD::mysql
cpan> install File::stat
cpan> install File::Basename
cpan> install Class::Singleton
cpan> install Thread::Queue
16) 安装mysql-mmm
tar -zxvf mysql-mmm-2.2.1.tar.gz
cd mysql-mmm-2.2.1
make install
17)防火墙配置
3306为默认mysql端口,9989为mysql-mmm监控端口。
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9989 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
service iptables restart
18)MYSQL-MMM使用的目录和存放文件简介
/usr/lib/mysql-mmm MMM的脚本插件
/usr/sbin MMM的命令保存路径
/var/log/mysql-mmm MMM的日志保存路径
/etc/mysql-mmm MMM配置文件保存的路径,优先级最高
/etc/init.d/ agentd和monitor的启动关闭脚本
/usr/lib/mysql-mmm权限设置一下755
19)配置myql-mmm配置项
cd /etc/mysql-mmm/
编辑 vi mmm_common.conf
active_master_role writer
<host default>
cluster_interface eth0
pid_path /var/run/mmm_agentd.pid
bin_path /usr/lib/mysql-mmm/
replication_user slave
replication_password slave
agent_user mmm_agent
agent_password mmm_agent
mysql_port 3306
</host>
<host db1>
ip 192.168.0.111
mode master
peer db2
</host>
<host db2>
ip 192.168.0.112
mode master
peer db1
</host>
<host db3>
ip 192.168.0.113
mode slave
</host>
<role writer>
hosts db1, db2
ips 192.168.0.200
mode exclusive
</role>
<role reader>
hosts db1, db2, db3
ips 192.168.0.201, 192.168.0.202, 192.168.0.203
mode balanced
</role>
编辑mmm_agent.conf
include mmm_common.conf
this db1
编辑mmm_mon.conf
include mmm_common.conf
<monitor>
ip 127.0.0.1
pid_path /var/run/mmm_mond.pid
bin_path /usr/lib/mysql-mmm/
status_path /var/lib/misc/mmm_mond.status
ping_ips 192.168.0.111, 192.168.0.112, 192.168.0.113
auto_set_online 10
</monitor>
<host default>
monitor_user mmm_monitor
monitor_password mmm_monitor
</host>
debug 0
20)启动mysql-mmm服务
在数据库服务器上启动代理程序
cd /etc/init.d
chkconfig mysql-mmm-agent on
service mysql-mmm-agent start
在管理服务器上启动监控程序
cd /etc/init.d
chkconfig mysql-mmm-monitor on
service mysql-mmm-monitor start
启动不成功,可以设置权限 chmod 640 /etc/mysql-mmm/*
mmm_control status
mmm_control set_online db3
mmm_control set_offline db1
mmm_control show