mysql主从复制
Master:cmkae-2.8.6.tar.gz mysql-5.5.22.tar.gz
Slave1:cmkae-2.8.6.tar.gz mysql-5.5.22.tar.gz
Slave2:cmkae-2.8.6.tar.gz mysql-5.5.22.tar.gz
1.搭建yum安装时间同步
yum -y install ntp
2.配置NTP
vim /etc/ntp.conf //添加如下两行
server 127.127.1.0
fudge 127.127.1.0 stratum 8
3.重启服务
service ntpd restart
4、在从节点上进行时间同步
yum -y install ntpdate
/usr/sbin/ntpdate 1.1.1.1 //IP为master的ip
rpm -e mysql mysql-server --nodeps
5.安装mysql数据库,在master,slave1,slave2上安装
yum -y install ncurses-devel gcc*
tar zxvf cmake-2.8.6.tar.gz -C /usr/src/
cd /usr/src/cmake-2.8.6/
./configure
gmake && gmake install
useradd -M -s /sbin/nologin mysql
tar zxvf 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
6.优化调整
[root@localhost mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
. /etc/profile
7.初始化数据库
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
8.启动mysql服务
service mysqld start
chkconfig mysqld on
mysqladmin -u root password 'qq'
配置mysql Mater 主服务器,在/etc/my.cnf中修改或增加下面内容
vim /etc/my.cnf
server-id = 1 主备不一样
log-bin=master-bin 修改
log-slave=updates=ture 增加
service mysqld restart //重启mysql程序,给从服务器授权
mysql -u root -pqq
grant replication slave on *.* to 'myslave'@'192.168.1.%' identified by '123456'; //192.168.1.1 为amoeba ip地址
flush privileges;
show mater status;
复制File和Position的值
9.配置从服务器
在/etc/my.cnf中修改或者增加如下内容
server-id = 2 //跟主服务器ID不能一样
relay-log=relay-log-bin //增加
relay-log-index=slave-relay-bin.index //增加
重启mysqld
service mysqld restart
mysql -u root -pqq
change master to master_host='192.168.1.101',master_user='myslave',myster_password='12346'.'mysql-bin.000001'master_log_pos=443;
//master_host为主masterIP地址,
启动同步
start slave; ( stop slave; reset slave; )
show slave status\G; //查看slave状态,确保2个值为yes
mysql读写分离
Amoba:amoba-mysql-binary-2.2.0.tar.gz jdk-6u14-linux-x64.bin
首先查看java和javac是否为1.5或1.6版本,因为amoeba是基于1.5开发的。
用 java -version查询版本信息 which java查看java路径。
./jdk-6u14-linux-x64.bin
mv jdk1.6.0_14/ /usr/local/jdk
vim /etc/profile
export JAVA_HOME=/usr/local/jdk
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
//在最后一行,增加如上5行
export JAVA_HOME=/usr/local/jdk
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
//在最后一行,增加如上5行
source /etc/profile
java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
Java 环境配置成功
安装并配置amoeba软件
mkdir /usr/local/amoeba
tar zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
chmod -R 755 /usr/local/amoeba/
/usr/local/amoeba/bin/amoeba
amoeba start|stop //显示内容说明amoeba安装成功
chmod -R 755 /usr/local/amoeba/
/usr/local/amoeba/bin/amoeba
amoeba start|stop //显示内容说明amoeba安装成功
配置amoeba读写分离,两个slave读负载均衡。
主 grant all on *.* test@'192.168.1.%' identified by '123';
vim /usr/local/amoeba/conf/amoeba.xml
amoeba
123
123
1500
master
vim /usr/local/amoeba/confdbServers.xml
test
1.1.1.1
1.1.1.2
1.1.1.3
1
slave1,slave2
master
vim /usr/local/amoeba/confdbServers.xml
test
1.1.1.1
1.1.1.2
1.1.1.3
1
slave1,slave2
bin/amoeba start&
看到 amoeba 8066端口
看到 amoeba 8066端口
在客户端上验证:
mysql -u amoeba -p123456 -n 192.168.1.1 -P8066 IP地址为amoeba地址
0
我 执行/usr/local/amoeba/bin/amoeba start一直报这个错误,这个你遇到过吗?
The stack size specified is too small, Specify at least 228k
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
we14578 发表于 2016-5-17 21:56
jdk不能直接用wget下载,你最好是在windows下载好
我 执行/usr/local/amoeba/bin/amoeba start一直报这个错误,这个你遇到过吗?
The stack size specified is too small, Specify at least 228k
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
0
直接yum也可以
渐行渐远 发表于 2016-5-18 10:12
我 执行/usr/local/amoeba/bin/amoeba start一直报这个错误,这个你遇到过吗?
The stack size specif ...
直接yum也可以
编辑回复