----------------时间同步-------------
主服务器设置:192.168.252.130:
yum install ntp -y
vim /etc/ntp.conf
server 127.127.252.0 //本地是时钟源//(添加)
fudge 127.127.252.0 stratum 8 //设置时间层级为8(限制在15内)//(添加)
service ntpd start
service iptables stop
setenforce 0
节点服务器设置:192.168.252.147
yum install ntp ntpdate -y
systemctl start ntpd.service
systemctl stop firewalld.service
setenforce 0
/usr/sbin/ntpdate 192.168.252.130 //进行时间同步//
另一台节点服务器192.168.252.148进行同样操作
-------------------------安装mysql---------------------------
三个服务器上同时配置:
tar zxvf mysql-5.5.24.tar.gz -C /opt/
确认安装 gcc 、 gcc-c++ 、make、cmake
ncurses-devel、
bison、
libaio-devel的软件包
yum install gcc gcc-c++ make cmake ncurses-devel bison libaio-devel -y
---------------添加mysql用户并加入到mysql组----------------
useradd -s /sbin/nologin mysql
mkdir /usr/local/mysql
cd /opt/mysql-5.5.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS=all
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/home/mysql
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
make && make install
chown -R mysql.mysql /usr/local/mysql
export PATH=$PATH:/usr/local/mysql/bin/ *开机时刷新*\
或者可选择vi /etc/profile 在最后一行加入后 运行source /etc/profile
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld --level 35 on
--------------初始化数据库------------------------------------------------
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
ln -s /var/lib/mysql/mysql.sock /home/mysql/mysql.sock /直接建立软连接/
vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
service mysqld start
mysqladmin -u root password '123456'
----------------------------mysql主服务器配置-------------------------------------
vim /etc/my.cnf
server-id = 11
log-bin=master-bin //主服务器日志文件//修改
log-slave-updates=true //从服务器更新二进制日志//添加
systemctl restart mysqld
mysql -u root -p
GRANT REPLICATION SLAVE ON . TO 'myslave'@'192.168.126.%' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000002 | 339 | | |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
--------------------------mysql从服务器配置-----------------------------
vim /etc/my.cnf
server-id = 22
relay-log=relay-log-bin //从主服务器上同步日志文件记录到本地//
relay-log-index=slave-relay-bin.index //定义relay-log的位置和名称//
systemctl restart mysqld
mysql -u root -p
change master to master_host='192.168.126.129',master_user='myslave',master_password='123456',master_log_file='master-bin.000001',master_log_pos=4391;
start slave;
show slave status\G; //查看状态//
-----------------------验证主从同步----------------------------
主服务器上 create database db_test;
去从服务器上 show databases;
-------------------------amoeba服务器---------------------------------
service iptables stop
setenforce 0
cp jdk-6u14-linux-x64.bin /usr/local/
cd /usr/local
./jdk-6u14-linux-x64.bin
按enter
输入 yes
mv jdk1.6.0_14/ /usr/local/jdk1.6
vi /etc/profile //添加到末行
export JAVA_HOME=/usr/local/jdk1.6
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
source /etc/profile
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说明安装成功
在三台mysql上添加权限开放给amoeba访问
grant all on . to test@'192.168.126.%' identified by '123.com';
回到amoeba服务器
cd /usr/local/amoeba
vim conf/amoeba.xml
---30行--
----32行---------
115
---117-去掉注释-
vi conf/dbServers.xml
-23行注释
-26-29--去掉注释--
-----42-主服务器地址---
--52-从服务器主机名-
--55-从服务器地址-
复制6yy
--末尾--
/usr/local/amoeba/bin/amoeba start&
netstat -anpt | grep java
----测试用客户端------
yum install -y mysql
mysql -u amoeba -p123456 -h 192.168.126.132 -P8066
----在MASTER上---------
#mysql -u root -p
use zhang;
create table zang (id int(10),name varchar(10),address varchar(20));
---在两台从上-----
stop slave;
----在主服务器上---内容不会同步
insert into zang values('1','zhang','this_is_master');
----从服务器1----
use zhang;
insert into zang values('2','zhang','this_is_slave1');
----从服务器2----
use zhang;
insert into zang values('3','zhang','this_is_slave2');
------在客户端上测试----第一次会向从服务器1读数据-第二次会各从2读取
use zhang;
select * from zang;
-------------在通过客户端连接数据库后写入的数据只有主会记录,然后同步给从-从服务器不会记录,从而实现了读写分离。----
insert into zang values('5','zhang','write_test');
-----看不到新插入的数据--因为同步没有开启-----只有主服务器上有数据。
select * from zang;