CentOS7.5源码安装MySQL5.7.28多实例

由于环境的需要,一个实例所有表要区分大小表,另一个实例不区分。部署过来也参数了很多资料,也遇到些坑,这里将我的部署记录下来,以便大家参考,操作过程如有不当之处,还请指点,谢谢!!
具体部署过程记录如下:

  1. 安装环境准备
    1.1 主机环境准备
    1.1.1. HOST
    配置每台主机的hosts(/etc/hosts),添加host_ip $hostname到/etc/hosts文件中。

[[email protected]~]# echo " 192.168.8.100 multidb" >> /etc/hosts

1.1.2. 关闭selinux

[[email protected]~]# sed -i ‘s/SELINUX=enforcing/SELINUX=permissive/g‘ /etc/selinux/config
[[email protected]~]# setenforce 0

1.1.3. 系统主机时间、时区、系统语言
? 修改时区

[[email protected]~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

? 修改系统语言环境

[[email protected]~]# echo ‘LANG="en_US.UTF-8"‘ >> /etc/profile
[[email protected]~]# source /etc/profile

? 配置主机NTP时间同步

[[email protected]~]# yum -y install ntp
[[email protected]~]# systemctl enable ntpd
[[email protected]~]# systemctl start ntpd
[[email protected]~]# echo ‘server ntp1.aliyun.com‘ >> /etc/ntp.conf
[[email protected]~]# echo ‘server ntp2.aliyun.com‘ >> /etc/ntp.conf
  1. Mysql安装部署
    2.1 环境清理

    [[email protected]~]# rpm -e --nodeps mariadb-libs-*
    [[email protected]~]# rpm -e mysql*
    [[email protected]~]# yum list installed | grep mariadb     ---确认已经清理干净
    [[email protected]~]# yum list installed | grep mysql       ---确认已经清理干净
    [[email protected]~]# mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak

    2.2 安装依赖包

[[email protected]~]# yum -y install bzr zlib-devel gcc-c++ ncurses ncurses-devel libev make cmake gcc autoconf automake zlib libxml libgcrypt libtool bison perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL perl-Digest-MD5 rsync perl-Data-Dumper net-tools wget vim openssl openssl-devel

2.3 创建用户

[[email protected]~]# groupadd mysql
[[email protected]~]# useradd mysql -g mysql -s /sbin/nologin -M

2.4 配置系统内核参数

[[email protected]~]# vi /etc/sysctl.conf
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
vm.swappiness = 0
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
kernel.shmmax = 25769803774
kernel.shmmni = 4096
kernel.shmall = 16777216
kernel.sem = 1010 129280 1010 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 6815744
[[email protected]~]# modprobe br_netfilter
[[email protected]~]# sysctl -p

2.5 修改系统资源限制

[[email protected]~]# vi /etc/security/limits.conf
mysql  soft    nproc   65535
mysql  hard    nproc   65535
mysql  soft    nofile  65535
mysql  hard    nofile  65535
mysql  soft    stack   10240

2.6 修改环境变量

[[email protected]~]# vi /etc/profile
if [ $USER = "mysql" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
[[email protected]~]# source /etc/profile

2.7 安装mysql多实例
2.7.1. 创建软件安装目录(部署路径请根据实际修改)

[[email protected]~]# mkdir -pv /data/mysql/{3306,3307}
[[email protected]~]# mkdir -v /data/mysql/3306/{logs,data,binlog}
[[email protected]~]# mkdir -v /data/mysql/3307/{logs,data,binlog}

2.7.2. boost源码包下载

[[email protected]~]# cd /opt
[[email protected]~]# wget -c  http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
[[email protected]~]# tar zxvf boost_1_59_0.tar.gz
[[email protected]~]# mv boost_1_59_0 /usr/local/boost

2.7.3. 下载并编译安装MySQL5.7.28
[[email protected]~]# cd /opt```

[[email protected]~]# wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz
[[email protected]~]# tar zxvf mysql-boost-5.7.28.tar.gz
[[email protected]~]# cd mysql-5.7.28
[[email protected]~]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
DMYSQL_DATADIR=/usr/local/mysql/data \
DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
DDEFAULT_CHARSET=utf8 \
DDEFAULT_COLLATION=utf8_bin \
DEXTRA_CHARSETS=all \
DENABLED_LOCAL_INFILE=ON \
DWITH_INNOBASE_STORAGE_ENGINE=1 \
DWITH_FEDERATED_STORAGE_ENGINE=1 \
DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
DWITH_FAST_MUTEXES=1 \
DWITH_SSL=system \
DWITH_ZLIB=bundled \
DWITH_EDITLINE=bundled \
DWITH_BOOST=/usr/local/boost \
DENABLED_LOCAL_INFILE=1 \
DWITH_READLINE=1 \
DWITH_EMBEDDED_SERVER=1 \
DWITH_DEBUG=0
[[email protected]~]# make
[[email protected]~]# make install

2.7.4.  配置MySQL环境变量

[[email protected]~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ >> /etc/profile
[[email protected]~]# tail -1 /etc/profile
[[email protected]~]# source /etc/profile

2.7.5.  MySQL参数配置
(1)server_id=3306与server_id=3307数值请根据实际配置,注意配置的id值与局域网内其他各实例所配置的数值不可以冲突;
(2)max_connections=1000配置MySQL数据库的最大连接数,根据实际需要配置;
(3)以下参数仅供参考,部署时根据实际需要添加配置,两份配置文件全部内容如下
**3306配置文件内容:**

[[email protected]~]# vim /data/mysql/3306/my3306.cnf
[client]
port = 3306
socket = /data/mysql/3306/mysql3306.sock

[mysql]
prompt="\[email protected] \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
user = mysql
port = 3306
symbolic-links = 0
basedir = /usr/local/mysql
datadir = /data/mysql/3306/data/
socket = /data/mysql/3306/mysql3306.sock
pid-file = /data/mysql/3306/mysqld3306.pid
server_id = 3306
character_set_server = utf8
max_connections = 1000
skip_name_resolve = 1
open_files_limit = 65536
thread_cache_size = 64
table_open_cache = 4096
table_definition_cache = 1024
table_open_cache_instances = 64
max_prepared_stmt_count = 1048576
explicit_defaults_for_timestamp = true
log_timestamps = system

binlog_format = row
log_bin = /data/mysql/3306/binlog/mysql-bin
binlog_rows_query_log_events = on
expire_logs_days = 7
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
sync_binlog = 1

slow_query_log = on
slow_query_log_file = /data/mysql/3306/data/slow.log
log-error = /data/mysql/3306/logs/error.log
#log_queries_not_using_indexes = on
long_query_time = 1.000000

gtid_mode = on
enforce_gtid_consistency = on

default_storage_engine = innodb
default_tmp_storage_engine = innodb
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_temp_data_file_path = ibtmp1:12M:autoextend
innodb_buffer_pool_filename = ib_buffer_pool
innodb_log_files_in_group = 3
innodb_log_file_size = 512M
innodb_online_alter_log_max_size = 1024M
innodb_open_files = 4096
innodb_page_size = 32k
innodb_thread_concurrency = 0
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_print_all_deadlocks = on
innodb_lock_wait_timeout = 20
innodb_spin_wait_delay = 128
innodb_autoinc_lock_mode = 2
innodb_io_capacity = 200
innodb_io_capacity_max = 2000
#innodb_flush_neighbors =
innodb_log_buffer_size = 8M
innodb_flush_log_at_timeout = 1
innodb_flush_log_at_trx_commit = 2
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 4
autocommit = 1
innodb_buffer_pool_dump_pct = 25
innodb_buffer_pool_dump_at_shutdown = ON
innodb_buffer_pool_load_at_startup = ON

[mysqldump]
quick
max_allowed_packet = 32M


**3307配置(有添加lower_case_table_names)文件内容:**

[[email protected]~]# vim /data/mysql/3307/my3307.cnf
[client]
port = 3307
socket = /data/mysql/3307/mysql3307.sock

[mysql]
prompt="\[email protected] \R:\m:\s [\d]> "
no-auto-rehash

[mysqld]
user = mysql
port = 3307
symbolic-links = 0
lower_case_table_names = 1
basedir = /usr/local/mysql
datadir = /data/mysql/3307/data/
socket = /data/mysql/3307/mysql3307.sock
pid-file = /data/mysql/3307/mysqld3307.pid
server_id = 3307
character_set_server = utf8
max_connections = 1000
skip_name_resolve = 1
open_files_limit = 65536
thread_cache_size = 64
table_open_cache = 4096
table_definition_cache = 1024
table_open_cache_instances = 64
max_prepared_stmt_count = 1048576
explicit_defaults_for_timestamp = true
log_timestamps = system

binlog_format = row
log_bin = /data/mysql/3307/binlog/mysql-bin
binlog_rows_query_log_events = on
expire_logs_days = 7
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
sync_binlog = 1

slow_query_log = on
slow_query_log_file = /data/mysql/3307/data/slow.log
log-error = /data/mysql/3307/logs/error.log
#log_queries_not_using_indexes = on
long_query_time = 1.000000

gtid_mode = on
enforce_gtid_consistency = on

default_storage_engine = innodb
default_tmp_storage_engine = innodb
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_temp_data_file_path = ibtmp1:12M:autoextend
innodb_buffer_pool_filename = ib_buffer_pool
innodb_log_files_in_group = 3
innodb_log_file_size = 512M
innodb_online_alter_log_max_size = 1024M
innodb_open_files = 4096
innodb_page_size = 32k
innodb_thread_concurrency = 0
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_print_all_deadlocks = on
innodb_lock_wait_timeout = 20
innodb_spin_wait_delay = 128
innodb_autoinc_lock_mode = 2
innodb_io_capacity = 200
innodb_io_capacity_max = 2000
#innodb_flush_neighbors =
innodb_log_buffer_size = 8M
innodb_flush_log_at_timeout = 1
innodb_flush_log_at_trx_commit = 2
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 4
autocommit = 1
innodb_buffer_pool_dump_pct = 25
innodb_buffer_pool_dump_at_shutdown = ON
innodb_buffer_pool_load_at_startup = ON

[mysqldump]
quick
max_allowed_packet = 32M
[[email protected]~]# chown -R mysql:mysql /data
[[email protected]~]# chown -R mysql:mysql /usr/local/mysql

2.7.6.  dbone实例初始化
?   操作实例初始化

[[email protected]~]# mysqld --defaults-file=/data/mysql/3306/my3306.cnf --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/3306/data/

?   生成ssl文件

[[email protected]~]# mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data

?   启动dbone实例

[[email protected]~]# mysqld_safe --defaults-file=/data/mysql/3306/my3306.cnf --user=mysql &

?   修改root密码

[[email protected]~]# less /data/mysql/3306/logs/error.log|grep ‘A temporary password‘
[[email protected]~]# mysql -uroot -p -S /data/mysql/3306/mysql3306.sock
Enter password:
mysql> alter user ‘root‘@‘localhost‘ identified by ‘密码‘;
mysql> flush privileges;
mysql> exit;

?   通过tcp/ip协议登陆mysql验证

[[email protected]~]# mysql -uroot -p -S /data/mysql/3306/mysql3306.sock

?   停止dbone实例

[[email protected]~]# mysqladmin -uroot -p -S /data/mysql/3306/mysql3306.sock shutdown
Enter password:

2.7.7.  dbtwo实例初始化
?   操作实例初始化

[[email protected]~]# mysqld --defaults-file=/data/mysql/3307/my3307.cnf --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/3307/data/

?   生成ssl文件

[[email protected]~]# mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/3307/data

?   启动dbtwo实例

[[email protected]~]# mysqld_safe --defaults-file=/data/mysql/3307/my3307.cnf --user=mysql &

?   修改root密码

[[email protected]~]# less /data/mysql/3307/logs/error.log|grep ‘A temporary password‘
[[email protected]~]# mysql -uroot -p -S /data/mysql/3307/mysql3307.sock
Enter password:
mysql> alter user ‘root‘@‘localhost‘ identified by ‘密码‘;
mysql> flush privileges;
mysql> exit;

?   通过tcp/ip协议登陆mysql验证

[[email protected]~]# mysql -uroot -p -S /data/mysql/3307/mysql3307.sock

?   停止dbtwo实例

[[email protected]~]# mysqladmin -uroot -p -S /data/mysql/3307/mysql3307.sock shutdown
Enter password:

2.7.8.  配置多实例系统启动脚本
?   配置实例3306系统服务脚本

[[email protected]~]# vim /etc/init.d/dbone
#!/bin/sh
#chkconfig: 2345 80 90
#Simple dbone mysql init.d script conceived to work on Linux systems

SOCK="/data/mysql/3306/mysql3306.sock"
CNF="/data/mysql/3306/my3306.cnf"
MYSQL_USER="mysql"
MYSQL_PWD="密码"
CmdPath="/usr/local/mysql/bin"

#startup function
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=${CNF} --user=${MYSQL_USER} 2>&1 > /dev/null &
}

#stop function
function_stop_mysql()
{
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${MYSQL_USER} -p${MYSQL_PWD} -S ${SOCK} shutdown
}

#restart function
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}

case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: dbone {start|stop|restart}\n"
esac

?   配置实例3307系统服务脚本

[[email protected]~]# vim /etc/init.d/dbtwo
#!/bin/sh
#chkconfig: 2345 81 92
#Simple dbtwo mysql init.d script conceived to work on Linux systems

SOCK="/data/mysql/3307/mysql3307.sock"
CNF="/data/mysql/3307/my3307.cnf"
MYSQL_USER="mysql"
MYSQL_PWD="密码"
CmdPath="/usr/local/mysql/bin"

#startup function
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=${CNF} --user=${MYSQL_USER} 2>&1 > /dev/null &
}

#stop function
function_stop_mysql()
{
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${MYSQL_USER} -p${MYSQL_PWD} -S ${SOCK} shutdown
}

#restart function
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}

case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: dbtwo {start|stop|restart}\n"
esac

?   配置授权添加系统服务

[[email protected]~]# chmod +x /etc/init.d/dbone
[[email protected]~]# chmod +x /etc/init.d/dbtwo
[[email protected]~]# chkconfig --add dbone
[[email protected]~]# chkconfig –add dbtwo
[[email protected]~]# chkconfig --list dbone
[[email protected]~]# chkconfig --list dbtwo


?   启动两个db服务

[[email protected]~]# service dbone start
[[email protected]~]# service dbtwo start

?   停止两个db服务

[[email protected]~]# service dbone stop
[[email protected]~]# service dbtwo stop

?   查看两个db服务进程

[[email protected]~]# netstat -tnlp|grep 3306
[[email protected]~]# netstat -tnlp|grep 3307

2.7.9.  数据导入
第一个实例创建库与用户密码:

[[email protected]~]# mysql -uroot -p -S /data/mysql/3306/mysql3306.sock
Enter password:
mysql> create database testone default character set utf8 collate utf8_bin;
mysql> grant select,insert,update,delete,create,execute on testone.* to ‘testone‘@‘%‘ identified by ‘密码‘;
mysql> set global log_bin_trust_function_creators=TRUE;
mysql> flush privileges;
mysql> exit
[[email protected]~]# mysql -uroot -p -S /data/mysql/3306/mysql3306.sock testone < /data/test.sql

第二个实例创建库与用户密码:

[[email protected]~]# mysql -uroot -p -S /data/mysql/3307/mysql3307.sock
Enter password:
mysql> create database testtwo default character set utf8 collate utf8_bin;
mysql> grant select,insert,update,delete,create,execute on testtwo.* to ‘testtwo‘@‘%‘ identified by ‘密码‘;
mysql> flush privileges;
mysql> exit
[[email protected]~]# mysql -uroot -p -S /data/mysql/3307/mysql3307.sock testtwo < /data/testtwo.sql

2.7.10. 防火墙配置
?   根据实际要求,添加开放端口

[[email protected]~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[[email protected]~]# firewall-cmd --zone=public --add-port=3307/tcp --permanent

?   重新载入

[[email protected]~]# firewall-cmd --reload

原文地址:https://blog.51cto.com/8355320/2463218

时间: 2024-09-30 10:32:22

CentOS7.5源码安装MySQL5.7.28多实例的相关文章

CentOS7下源码安装mysql5.6

目录 准备工作 运行环境 确认你的安装版本 下载mysql 安装mysql 准备安装环境 编译和安装 配置mysql 单实例配置      单实例配置方法          添加防火墙          启动mysql          重启mysql 多实例配置          什么是多实例          多实例配置方法          创建启动文件          初始化数据库          配置防火墙          启动mysql          登陆mysql    

Centos下源码安装MySQL5.5(单实例)

1.介质准备 注:由于Mysql5.5源码编译采用的CMAKE方式,所以事先下载cmake的安装包和MySQL5.5的安装包 下载地址如下: http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/ http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz 下载完成之后上传到指定的服务器上. 2.安装依赖包 需要安装的依赖包很多,所以建议采用yum源安装的方式安装,其实有很多包是选装的.(加粗字

CentOS7.5使用mysql_multi方式安装MySQL5.7.28多实例

因使用源码安装的MySQL5.7.28多实例,在导入数据库时会出现问题,所以重新研究使用mysql_multi的方法来管理多实例,经过测试环境验证之后,在各方面使用上特别在备份还原上,没有报MySQL5.7.28多实例的问题,踩了不少坑,这里我将我的部署过程分享下,如果在哪里出问题的,还请多多指正与指导,谢谢!!关于mysql安装部署基础环境与配置可以参考文章:CentOS7.5源码安装MySQL5.7.28多实例https://blog.51cto.com/8355320/2463218本从就

MYSQL Study案例之--RedHat EL55源码安装Mysql-5.6

MYSQL  Study案例之--RedHat EL55源码安装Mysql-5.6 系统环境: 操作系统:RedHat EL55 DB Soft:  Mysql 5.6.4-m7 1.系统环境 [[email protected] Packages]# uname -a Linux rh6 2.6.18-194.el5.xen #1 SMP Tue Jan 29 11:47:41 EST 2013 i386 i686 GNU/Linux [[email protected] Packages]#

CentOS-6.4-minimal版中源码安装MySQL-5.5.38

/** * CentOS-6.4-minimal版中源码安装MySQL-5.5.38 * ---------------------------------------------------------------------------------------------------------------------- * 三种安装方式 * 1)源码安装 * 2)二进制包安装 * 3)rpm或yum安装 * 本文演示的是源码安装,并且,从mysql-5.5开始,源码安装要通过cmake安装

源码安装mysql5.6.20&&mysql主从设置(多实例做多个主从)

一.源码安装mysql5.6.20 1.编译环境安装 yum install wget gcc* make openssl openssl-devel openssl-clients -y && yum groupinstall "Development Libraries" -y 2.源码下载(软件见Linux部署源码包) wget -P /usr/local/src/ http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.

Linux下源码安装Mysql5.5

本文主要介绍了如何在源码安装mysql5.5,所用系统为CentOS6.5 一.安装相应的开发环境 yum install -y ncurses-devel yum install -y libaio yum install -y bison yum install -y gcc-c++ yum install -y openssl-devel 二.安装cmake 跨平台编译器 # tar xf cmake-2.8.8.tar.gz # cd cmake-2.8.8 # ./bootstrap

CentOS 6.5 源码安装MySQL5.6

CentOS 6.5 源码安装MySQL5.6 1:下载安装cmake (mysql5.5以后是通过cmake来编译的) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #http://download.csdn.net/detail/csxuedn/7976005 #wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz # tar -zxv -f /root/cmake-2.8.4.tar.gz

源码安装mysql5.6x启动报错:[ERROR] Can&#39;t find messagefile &#39;/data/mysqldata/3306/english/errmsg.sys&#39;

170502 10:43:40 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data 2017-05-02 10:43:40 0 [Warning] The syntax '--language/-l' is deprecated and will be removed in a future release. Please use '--lc-messages-dir' instead.