一.关闭防火墙和SElinux:

systemctl stop firewalld.service 
setenforce 0

二.准备环境: 两台虚拟机安装mysql IP:192.168.43.176 IP2:192.168.43.213

三.下载解压mysql:

unzip AliSQL-AliSQL-5.6.32-9.zip

下载依赖包:

yum -y install cmake bison git ncurses-devel gcc gcc-c++

添加用户:

groupadd mysql
useradd -g mysql mysql

下载并解压perl:

 wget http://repo.openfusion.net/centos7-x86_64//perl-Data-Dumper-2.154-1.of.el7.x86_64.rpm
rpm -ivh http://repo.openfusion.net/centos7-x86_64//perl-Data-Dumper-2.154-1.of.el7.x86_64.rpm

编译安装

cmake -DCMAKE_INSTALL_PREFIX=/data/server/mysql -DMYSQL_UNIX_ADDR=/data/server/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/server/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DENABLE_DOWNLOADS=1

make && make install 

修改目录主权限:

chown -R mysql:mysql /data/server/mysql

复制文件给权限:

cd /data/server/mysql  
cp support-files/my-default.cnf  ./my.cnf 
chown -R  mysql:mysql my.cnf

配置文件:

vim my.cnf
basedir = /data/server/mysql
datadir = /data/server/mysql/data
socket = /data/server/mysql/mysql.sock
log-error = /dat/server/mysql/data/error.log
pid-file = /data/server/mysql/data/mysql.pid
user = mysql
tmpdir = /tmp

数据库初始化:

scripts/mysql_install_db  --defaults-file=./my.cnf --user=mysql 

进到support-files中启动数据库:

./mysql.server start

报错PID解决办法

rm -rf /etc/my.cnf
cd /data/server/mysql
rm -rf my.cof
cd data
rm -rf *
cd /data/server/mysql/
scripts/mysql_install_db  --defaults-file=./my.cnf --user=mysql 
cd support-files
./mysql.server start

进入mysql下的bin目录中,重新启动数据库

cd /data/server/mysql/bin
./mysql -uroot -p 

MYSQL 启动完成。

NTP时间服务同步器 准备两台虚拟机 服务端IP:192.168.43.213 客户端IP:192.168.43.176 服务端配置 安装ntp服务

yum install ntp ntpdate -y

修改ntp.conf配置文件

vim /etc/ntp.conf

启动NTP服务

service ntpd start

为了使服务可以在系统引导的时候自动启动,执行

  service ntpd startchkconfig ntpd on

检查时间服务器是否正确同步

ntpq -p

客户端配置 关闭防火墙:

systemctl stop firewalld
setenforce 0

客户端安装ntp服务

yum install ntp ntpdate -y

配置ntp.conf文件

vim /etc/ntp.conf

手动同步时间

ntpdate 192.168.124.133

NTP时间同步实现

主从复制 master主库配置

vim /mysql/my.cnf

 [mysqld] server-id=1  log-bin=mysql-bin

重启MySQL:cd /data/server/mysql/support-files

./mysql.server restart

新建用于主从同步的用户hong,允许登录的从库是'192.168.43.176'

create user 'hong'@'192.168.43.176' identified by '123';

给从库账号授权,说明给hong从库复制的权限,在192.168.43.176机器上复制

grant replication slave on *.* to 'hong'@'192.168.43.176';

检查主库创建的复制账号

select user,host from mysql.user;

检查授权账号的权限

show grants for hong@'192.168.43.176';

检查主库的状态:

show master status;

slave从库配置 设置server-id值并关闭binlog功能参数 修改Slave的/etc/my.cnf,写入

vim /etc/my.cnf
[mysqld]
server-id=3

重启数据库

cd /data/server/mysql/support-files
./mysql.server restart

检查Slava从数据库的各项参数

show variables like 'log_bin';
show variables like 'server_id';

配置复制的参数,Slave从库连接Master主库的配置

change master to master_host='192.168.43.213',(主库的ip)
master_user='hong',(主库的用户名)
master_password=123',(主库用户的密码)
master_log_file='mysql-bin.000001',(主库的配置参数)
master_log_pos=265;(主库的状态值)

启动从库的同步开关,测试主从复制的情况

start slave;

查看复制状态

show slave status\G;