说明:由于audit实验需要 做了一份容器安装MySQL待用 为了减少容器打包容量大小innodb_log_file_size = 100M
安装环境: 已安装 Docker 的 CentOS8.4.2105
##准备一个干净的linux容器镜像
docker search centos
docker pull centos
-----------关于centos镜像环境这里不做改造打包了 缺什么临时yum一下吧------------------------------
##新容器要用来做一个新的MySQL8.0.27的商业版关于Audit的测试 我们有必要将原linux镜像改下名字好识别
[root@CentOS8-4-2105 Jaylon]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 2 months ago 231MB
[root@CentOS8-4-2105 Jaylon]# docker tag 5d0da3dc9764 mysql-commercial:8.0.27
[root@CentOS8-4-2105 Jaylon]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql-commercial 8.0.27 5d0da3dc9764 2 months ago 231MB
##添加一个新的网桥来指定容器局域网内特定ip段
docker network create --driver bridge --subnet=10.0.0.0/24 --gateway=10.0.0.254 mynetwork
##删除网桥
docker network rm mynetwork
[root@CentOS8-4-2105 Jaylon]# docker network ls
NETWORK ID NAME DRIVER SCOPE
45cd5461c017 bridge bridge local
c68a5ff3e244 host host local
4b4efc6eeddf mynetwork bridge local
a361a611bcc9 none null local
##用镜像名称+标签的方式取代镜像id 启动一个新容器 并添加好主机映射端口
docker run -it -d --name audit --net mynetwork --hostname audit --ip 10.0.0.10 -p 3327:3306 -p 33027:33061 -v /etc/localtime:/etc/localtime mysql-commercial:8.0.27
[root@CentOS8-4-2105 Jaylon]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20bc2e216261 mysql-commercial:8.0.27 "/bin/bash" 4 seconds ago Up 3 seconds 0.0.0.0:3327->3306/tcp, :::3327->3306/tcp, 0.0.0.0:33027->33061/tcp, :::33027->33061/tcp audit
######################################################################################################################################################################################################################
##将安装文件复制到容器 进入容器配置好MySQL8.0.27
docker cp mysql8 audit:/usr/local/
docker exec -it audit /bin/bash
yum -y install vim
alias ll='ls -lt'1
##尾行添加解决乱码
vim /etc/vimrc
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
set enc=utf8
set fencs=utf8,gbk,gb2312,gb18030
vim /etc/my.cnf
#
## my.cnf for 8.0版本
## 本配置文件主要适用于MySQL 8.0版本
#
[client]
port = 3306
socket = /usr/local/mysql8/data/mysql.sock
[mysql]
prompt = "\u@audit \R:\m:\s [\d]> "
no_auto_rehash
[mysqld]
user = mysql
port = 3306
#主从复制或MGR集群中,server_id记得要不同
#另外,实例启动时会生成 auto.cnf,里面的 server_uuid 值也要不同
#server_uuid的值还可以自己手动指定,只要符合uuid的格式标准就可以
server_id = 3306
basedir = /usr/local/mysql8
datadir = /usr/local/mysql8/data
socket = /usr/local/mysql8/data/mysql.sock
pid_file = audit.pid
character_set_server = UTF8MB4
skip_name_resolve = 1
#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
default_time_zone = "+8:00"
#启用admin_port,连接数爆满等紧急情况下给管理员留个后门
admin_address = '127.0.0.1'
admin_port = 33062
#performance setttings
lock_wait_timeout = 3600
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
#log settings
log_timestamps = SYSTEM
log_error = /usr/local/mysql8/data/error.log
log_error_verbosity = 3
slow_query_log = 1
log_slow_extra = 1
slow_query_log_file = /usr/local/mysql8/data/slow.log
long_query_time = 0.1
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_bin = /usr/local/mysql8/data/mybinlog
binlog_format = ROW
sync_binlog = 1 #MGR环境中由其他节点提供容错性,可不设置双1以提高本地节点性能
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
binlog_rows_query_log_events = 1
binlog_expire_logs_seconds = 604800
#MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行
binlog_checksum = CRC32
gtid_mode = ON
enforce_gtid_consistency = TRUE
#myisam settings
key_buffer_size = 32M
myisam_sort_buffer_size = 128M
#replication settings
relay_log_recovery = 1
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 64 #可以设置为逻辑CPU数量的2倍
binlog_transaction_dependency_tracking = WRITESET
slave_preserve_commit_order = 1
slave_checkpoint_period = 2
#mgr settings
loose-plugin_load_add = 'mysql_clone.so'
loose-plugin_load_add = 'group_replication.so'
loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
#MGR本地节点IP:PORT,请自行替换
loose-group_replication_local_address = "10.0.0.10:33061"
#MGR集群所有节点IP:PORT,请自行替换
loose-group_replication_group_seeds = "10.0.0.10:33061,10.0.0.11:33062,10.0.0.12:33063"
loose-group_replication_start_on_boot = OFF
loose-group_replication_bootstrap_group = OFF
loose-group_replication_exit_state_action = READ_ONLY
loose-group_replication_flow_control_mode = "DISABLED"
loose-group_replication_single_primary_mode = ON
#innodb settings
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 1434M
innodb_buffer_pool_instances = 4
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 1 #MGR环境中由其他节点提供容错性,可不设置双1以提高本地节点性能
innodb_log_buffer_size = 32M
innodb_log_file_size = 100M #如果线上环境的TPS较高,建议加大至1G以上,如果压力不大可以调小
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 4G
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_open_files = 65535
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_print_ddl_logs = 1
innodb_status_file = 1
#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快
innodb_status_output = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 67108864
innodb_adaptive_hash_index = OFF
#innodb monitor settings
innodb_monitor_enable = "module_innodb"
innodb_monitor_enable = "module_server"
innodb_monitor_enable = "module_dml"
innodb_monitor_enable = "module_ddl"
innodb_monitor_enable = "module_trx"
innodb_monitor_enable = "module_os"
innodb_monitor_enable = "module_purge"
innodb_monitor_enable = "module_log"
innodb_monitor_enable = "module_lock"
innodb_monitor_enable = "module_buffer"
innodb_monitor_enable = "module_index"
innodb_monitor_enable = "module_ibuf_system"
innodb_monitor_enable = "module_buffer_page"
#innodb_monitor_enable = "module_adaptive_hash"
#pfs settings
performance_schema = 1
#performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'
[mysqldump]
quick
##根据配置文件准备好对应目录权限等 //由于都在默认安装目录下 没有新增目录 data会在初始化的时候生成
useradd mysql
chown -R mysql:mysql /usr/local/mysql8 /etc/my.cnf
##准备好系统环境变量
/*
关于各种缺lib 每个人的环境不通 错误的原因也各不同 综合下来常见主因为i686和386的包问题 以及linux版本不通用包后缀名的问题
这个是上次centos7.4所用
yum -y install gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses ncurses-deve numactl
本次8.4所用
yum -y install gcc gcc-c++ openssl openssl-devel libaio libaio-devel.x86_64 ncurses* numactl
*/
##初始化
/usr/local/mysql8/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql &
##启动
1、服务方式启动 --systemctl服务制作略
2、命令启动
/*
全局命令变量添加
echo "export PATH=$PATH:/usr/local/mysql8/bin" >> /etc/profile
echo "source /etc/profile" >> /root/.bashrc
source /etc/profile
*/
/usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
#查看启动 可以看到mysqld_safe 和 mysqld 两个进程
[root@audit data]# /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
[1] 680
[root@audit data]# 2021-11-18T07:27:02.541197Z mysqld_safe Logging to '/usr/local/mysql8/data/error.log'.
2021-11-18T07:27:02.581623Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql8/data
[root@audit data]# ps -ef |grep mysql
root 680 33 1 07:27 pts/1 00:00:00 /bin/sh /usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql
mysql 2089 680 20 07:27 pts/1 00:00:01 /usr/local/mysql8/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data --plugin-dir=/usr/local/mysql8/lib/plugin --user=mysql --log-error=/usr/local/mysql8/data/error.log --open-files-limit=65535 --pid-file=audit.pid --socket=/usr/local/mysql8/data/mysql.sock --port=3306
root 2143 33 0 07:27 pts/1 00:00:00 grep --color=auto mysql
基本初始化
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxx';
use mysql
select host, user, authentication_string, plugin from mysql.user;
update user set host='%' where user='root';
FLUSH PRIVILEGES;
ALTER USER 'root'@'%' IDENTIFIED BY 'xxx' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxx';
FLUSH PRIVILEGES;
MySQL环境准备完毕
将以上镜像打包制作
docker commit -a "Jaylon" -m "audit" 5d0da3dc9764 mysql8:audit
######################################################################################################################################################################################################################
浙公网安备 33010602011771号