系统版本:Red Hat Enterprise Linux Server release 7.6 (Maipo)
Mysql版本:mysql-boost-8.0.18.tar.gz
部署主机: 192.168.102.110 、 192.168.102.111
必须依赖包: gcc-9 、 cmake-3
systemctl stop firewalld && \
systemctl disable firewalld && \
setenforce 0 && \
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config && \
for i in adm lp sync shutdown halt news uucp operator games gopher;do userdel $i;done ;
for i in adm lp news uucp games dip pppusers popusers slipusers ;do groupdel $i;done ;
echo '警告!
如果你现在通过非法途径或在未经授权的情况下登录到这台服务器,请立即停止所有操作并退出登录,
因为你对服务器的任何操作都将会受到法律的惩戒!
Warning!
If you log in to this server by illegal means or without authorization, please stop all operations and log out immediately,
because any operation you do to the server will be punished by law!' >> /etc/motd
mkdir /opt/cdrom
mount -o loop /opt/rhel-server-7.6-x86_64-dvd.iso /opt/cdrom
vi /etc/yum.repos.d/local.repo
[local]
name=localhost
baseurl=file:///opt/cdrom
enabled=1
gpgcheck=0
:wq
yum makecache
yum insrall -y httpd
ln -s /opt/cdrom /var/www/html/cdrom
systemctl start httpd
curl http://192.168.102.110/cdrom 可列出cdrom目录中的文件则配置生效
vi /etc/yum.repos.d/local.repo
[localhttp]
name=localhttp
baseurl=http://192.168.102.110/cdrom
enabled=1
gpgcheck=0
:wq
yum makecache
vi /etc/hosts
192.168.102.110 dbserver1
192.168.102.111 dbserver2
:wq
yum install -y cmake3 git gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel bzip2 openssl-devel m4
wget http://ftp.gnu.org/gnu/gcc/gcc-9.1.0/gcc-9.1.0.tar.gz
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
tar -jxf gmp-6.1.0.tar.bz2 && \
cd gmp-6.1.0 && \
mkdir temp && \
cd temp && \
../configure --prefix=/opt/gmp-6.1.0 && \
make -j12 && \
make install
tar -jxf mpfr-3.1.4.tar.bz2 && \
cd mpfr-3.1.4 && \
mkdir temp && \
cd temp && \
../configure --prefix=/opt/mpfr-3.1.4 --with-gmp=/opt/gmp-6.1.0 && \
make -j12 && \
make install
tar -xvzf mpc-1.0.3.tar.gz && \
cd mpc-1.0.3 && \
mkdir temp && \
cd temp/ && \
../configure --prefix=/opt/mpc-1.0.3 --with-gmp=/opt/gmp-6.1.0 --with-mpfr=/opt/mpfr-3.1.4 && \
make -j12 && \
make install
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mpc-1.0.3/lib:/opt/gmp-6.1.0/lib:/opt/mpfr-3.1.4/lib" >> /etc/profile
source /etc/profile
tar -zxvf gcc-9.1.0.tar.gz && \
cd gcc-9.1.0 && \
mkdir temp && \
cd temp && \
../configure --disable-checking --disable-multilib --enable-languages=c,c++ --disable-multilib --prefix=/opt/gcc9 --with-gmp=/opt/gmp-6.1.0 --with-mpfr=/opt/mpfr-3.1.4 --with-mpc=/opt/mpc-1.0.3
// 如果报错 请使用
../configure --disable-multilib --enable-languages=c,c++
make -j12 && \ make install
echo "PATH=/opt/gcc9/bin:/opt/gcc9/lib64:$PATH
LD_LIBRARY_PATH=/opt/gcc9/lib/:$LD_LIBRARY_PATH" >> /etc/profile
gcc --version
wget https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz
tar zxvf cmake-3.12.4.tar.gz && \
cd cmake-3.12.4 && \
./bootstrap
此处若报错:
cp /usr/local/lib64/libstdc++.so.6.0.X /lib64/
cd /lib64/
rm -f libstdc++.so.6
ln -s libstdc++.so.6.0.X libstdc++.so.6
./bootstrap && \
gmake && \
gmake install
/usr/local/bin/cmake --version
yum remove cmake -y
ln -s /usr/local/bin/cmake /usr/bin/
cmake --version
出现版本表示成功!cmake编译完成
tar -zxvf mysql-boost-8.0.18.tar.gz
mkdir -p /mysql/data
cd mysql-8.0.18/ && mkdir builder && cd builder
cmake ../ -DCMAKE_INSTALL_PREFIX=/mysql \
-DMYSQL_DATADIR=/mysql/data \
-DSYSCONFDIR=/mysql \
-DMYSQL_USER=mysql \
-DCMAKE_C_COMPILER=/opt/gcc9/bin/gcc \
-DCMAKE_CXX_COMPILER=/opt/gcc9/bin/g++ \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SYSTEMD=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost
#include
#include
#define gettid() syscall(SYS_gettid)
“os_compare_and_swap_thread_id” 修改为 os_compare_and_swap_lint
“os_compare_and_swap_thread_id” 修改为 os_compare_and_swap_lint
注意: 这里有两处需要替换
make -j12 && make install
注解:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql:MySQL安装的根目录
-DMYSQL_DATADIR=/data/mysql:数据文件所存放的目录
-DSYSCONFDIR=/etc :MySQL配置文件所在目录
-DMYSQL_USER=mysql:MySQL服务的用户名
-DWITH_MYISAM_STORAGE_ENGINE=1:安装MyISAM引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1:安装InnoDB引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1:安装Archive引擎
-DWITH_MEMORY_STORAGE_ENGINE=1:安装Memory引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1:安装Federated引擎
-DWITH_PARTITION_STORAGE_ENGINE=1:安装Partition引擎
-DWITH_READLINE=1:MySQL的readline library
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock:sock文件的路径
-DMYSQL_TCP_PORT=3306 :MySQL的监听端口
-DENABLED_LOCAL_INFILE=1:启用加载本地数据
-DENABLE_DOWNLOADS=1:编译时允许自主下载相关文件
-DEXTRA_CHARSETS=all :使MySQL支持所有的扩展字符
-DDEFAULT_CHARSET=utf8mb4:设置默认字符集为utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci:设置默认字符校对
-DWITH_DEBUG=0:禁用调试模式
-DMYSQL_MAINTAINER_MODE=0:是否启用mysql维护器特定的开发环境
-DDOWNLOAD_BOOST=1:允许在线更新boost库
-DWITH_BOOST=…/boost:指定boost安装路径 -DCMAKE_C_COMPILER=/opt/gcc9/bin/gcc 指定新安装的gcc位置 -DCMAKE_CXX_COMPILER=/opt/gcc9/bin/g++ \指定新安装的g++位置
vi /mysql/my.cnf
[mysqld]
server-id=71 #第二台mysql-bin-72.log
port=3306
character-set-server=utf8mb4
default-time_zone='+8:00'
lower_case_table_names=1
log-bin=mysql-bin
auto_increment_increment=2 #步进值,主节点数量
auto_increment_offset=1 #起始值,一般填写第n台主机mysql,第二台填写2
max_connections=3000
max_connect_errors=100000
default_authentication_plugin=mysql_native_password
datadir=/mysql/data
socket=/mysql/data/mysql.sock
log-error=/mysql/logs/mysqld.log
pid-file=/mysql/mysqld.pid
lower_case_table_names=1
binlog_format=ROW
log_bin=/data/mysql/data/mysql-bin-71.log #第二台mysql-bin-72.log
expire_logs_days=30
long_query_time=1
slow_query_log = 1
slow_query_log_file=/mysql/logs/slow.log
[client]
port=38965
default-character-set=utf8mb4
socket=/mysql/data/mysql.sock
[mysql]
no-auto-rehash
default-character-set=utf8mb4
mkdir /mysql/logs
cd /mysql/bin
./mysqld --initialize --user=mysql --basedir=/mysql/ --datadir=/mysql/data
记住密码输入的密码
echo “PATH=$PATH:$HOME/.local/bin:$HOME/bin” >> /mysql/.bash_profile
source /mysql/.bash_profile
./mysqld --defaults-file=/mysql/my.cnf --datadir=/mysql/data --user=mysql
修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypwd#2019'
create user 'repl'@'192.168.102.%' identified by 'replepassword';
grant replication slave on *.* to 'repl'@'192.168.102.%';
mysql> show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| mysql-bin-72.000007 | 1796 | | | |
+---------------------+----------+--------------+------------------+-------------------+
mysql> change master to
-> master_host='192.168.102.110',
-> master_port=3306,
-> master_user='repl',
-> master_password='Csii@401',
-> master_log_file='mysql-bin-71.000008',
-> master_log_pos=1796;
start slave;
mysql> show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| mysql-bin-72.000008 | 1796 | | | |
+---------------------+----------+--------------+------------------+-------------------+
mysql> change master to
-> master_host='192.168.102.111',
-> master_port=3306,
-> master_user='repl',
-> master_password='Csii@401',
-> master_log_file='mysql-bin-71.000007',
-> master_log_pos=1796;
start slave;
show slave status\G;
主从机 my.cnf分别增加配置:
#GTID
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates = 1
重启MySQL,并执行
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to MASTER_AUTO_POSITION=1;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show processlist\G;
发现已经有binlog dump GTID 的信息则配置成功。
skip-name-resolve #远程客户端登录
character_set_server=utf8
init_connect='SET NAMES utf8'
max_allowed_packet=48M #设置在网络传输中一次消息传输量的最大值
innodb_log_file_size=256M #确定数据日志文件的大小,更大的设置可以提高性能,但也会增加恢复故障数据库所需的时间
max_connections=1000#MySQL允许最大的进程连接数,如果经常出现Too Many Connections的错误提示,则需要增大此值
wait_timeout=60#指定一个请求的最大连接时间
innodb_buffer_pool_size = 4096M #最大内存的70%
innodb_thread_concurrency=8 #CPU核心数
yum install -y pcre-devel openssl-devel popt-devel libnl libnl-devel
tar zxvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure --prefix=/mysql/keepalived
make && make install
mkdir /etc/keepalived/
cp /mysql/keepalived/etc/keepalived/keepalived.conf /etc/keepalived
cp /mysql/keepalived/sbin/keepalived /usr/sbin/
本环境服务器信息
MySQL服务器1: 10.1.13.103
MySQL服务器2: 10.1.13.104
vip: 10.1.13.40
MySQL服务器1: /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id mysql_ha
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_mysql {
script "/etc/keepalived/mysql.sh"
interval 3
weight 3
}
vrrp_instance VI_1 {
state MASTER
interface ens192
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.1.13.40
}
track_script {
chk_mysql
}
}
MySQL服务器2:/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id mysql_ha
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_mysql {
script "/etc/keepalived/mysql.sh"
interval 3
weight 3
}
vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.1.13.40
}
track_script {
chk_mysql
}
}
mysql.sh 脚本内容
#!/bin/bash
A=`ps -C mysqld --no-header | wc -l`
if [ $A -eq 0 ];then
killall keepalived
fi
systemctl start keepalived
systemctl enable keepalived
systemctl status keepalived
ip addr
查看vip
killall keepalived
或
kill mysql_pid
vip 或漂移到另一台MySQL服务器,则切换成功。