网站首页 > 教程文章 正文
对于多台服务器安装mysql数据库,采用手工安装,是非常繁琐的,如果采取脚本批量安装,就非常的方便了,具体操作方法如下:
创建目录
mkdir -p /apps
mkdir -p /data
上传安装包
上传执行脚本
授权脚本执行权限
Chmod +x ./installMysql5.7.32
执行脚本
./installMysql5.7.32.sh
登录mysql数据库
脚本信息
脚本内容
#!/bin/bash
port=`ss -tanl | grep 3306 |wc -l`
if [ $port -eq 1 ]; then
echo "3306 is exists please kill 3306!!"
exit
fi
if [ ! -d "/apps/" ];then
echo "The Directory:/apps/ no exist"
exit
fi
if [ ! -f "/apps/mysql-5.7.32-el7-x86_64.tar.gz" ];then
echo "The Directory:/apps/ No mysql-5.7.32-el7-x86_64.tar.gz please mysql-5.7.32-el7-x86_64.tar.gz to /apps/"
exit
fi
if [ ! -f "/apps/installMysql5.7.32.sh" ];then
echo "The Directory:/apps/ No installMysql5.7.32.sh please copy installMysql5.7.32.sh to /apps/"
exit
fi
if [ ! -d "/data/" ];then
echo "The Directory:/data/ no exist please mkdir /data"
exit
fi
echo "<---------------------begin--------------------->"
cd /apps/
tar -zxvf mysql-5.7.32-el7-x86_64.tar.gz
mv mysql-5.7.32-el7-x86_64 mysql
echo 'export PATH=/apps/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
source /etc/profile
rm -rf /data/*
mkdir /data/mysql
mkdir /data/mysql/data
mkdir /data/mysql/tmp
mkdir /data/mysql/var
mkdir /data/mysql/log
touch /data/mysql/log/slow.log
touch /data/mysql/log/mysqld.log
i=`cat /etc/passwd | cut -f1 -d':' | grep -w mysql -c`
if [ $i -le 0 ]; then
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql
fi
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /apps/mysql
chown mysql:mysql /apps/mysql
if [ -f "/etc/my.cnf" ];then
rm -f /etc/my.cnf
fi
server_id=`date +%Y%m%d%H%M%S`
cat > /etc/my.cnf << 'EOF'
[mysqld]
############# GENERAL #############
autocommit = ON
character_set_server = utf8
collation_server = utf8_general_ci
explicit_defaults_for_timestamp = ON
lower_case_table_names = 1
port = 3306
#read_only = ON
transaction_isolation = READ-COMMITTED
user =mysql
innodb_file_per_table = 1
#skip-grant-tables
############### PATH ##############
basedir = /apps/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql/tmp
socket = /data/mysql/var/mysql.sock
pid_file = /data/mysql/var/mysql.pid
innodb_data_home_dir = /data/mysql/data
log_error = /data/mysql/log/error.log
general_log_file = /data/mysql/log/general.log
slow_query_log_file = /data/mysql/log/slow.log
#log_bin = /data/mysql/log/mysql-bin
#log_bin_index = /data/mysql/log/mysql-bin.index
relay_log = /data/mysql/log/relay-log
relay_log_index = /data/mysql/log/relay-log.index
############# INNODB #############
innodb_flush_method = O_DIRECT
innodb_buffer_pool_size = 30G
innodb_log_file_size = 1G
innodb_log_files_in_group = 4
innodb_flush_log_at_trx_commit = 2
innodb_support_xa = ON
innodb_strict_mode = ON
innodb_data_file_path = ibdata1:256M;ibdata2:256M:autoextend
innodb_temp_data_file_path = ibtmp1:512M:autoextend
innodb_lock_wait_timeout = 5
innodb_undo_tablespaces = 3
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 5120M
innodb_lock_wait_timeout = 50
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_io_capacity = 1200
innodb_io_capacity_max = 2400
innodb_lru_scan_depth = 512
####### CACHES AND LIMITS #########
interactive_timeout = 86400
wait_timeout = 86400
lock_wait_timeout = 50
max_allowed_packet = 256M
max_connect_errors = 2000
max_connections = 2000
max_user_connections = 2000
join_buffer_size = 4M
sort_buffer_size = 4M
#table_definition_cache = 5000
#table_open_cache = 8000
#table_open_cache_instances = 4
#thread_cache_size = 9
#thread_stack = 256K
tmp_table_size = 32M
max_heap_table_size = 32M
binlog_cache_size = 1M
############# SAFETY ##############
#local_infile = OFF
#{$validate_password_enable}plugin-load = validate_password.so
#skip_name_resolve = ON
#sql_mode = STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY
############# LOGGING #############
#general_log = 0
log_queries_not_using_indexes = OFF
log_throttle_queries_not_using_indexes = 0
log_slow_admin_statements = ON
log_error_verbosity = 3
long_query_time = 3
slow_query_log = ON
log_timestamps = SYSTE
############# REPLICATION #############
#binlog_checksum = CRC32
#master_verify_checksum = ON
#slave_sql_verify_checksum = ON
binlog_format = ROW
binlog_rows_query_log_events = ON
expire_logs_days = 3
max_binlog_size = 256M
enforce_gtid_consistency = ON
gtid_mode = ON
log_slave_updates = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
server_id=000001
#skip_slave_start = ON
#slave_net_timeout = 4
sync_binlog = 100
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
slave_parallel_workers = 4
slave_parallel_type = LOGICAL_CLOCK
relay_log_recovery = ON
slave_skip_errors = all
[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/var/mysqld.pid
[client]
#default-character-set=utf8
[mysql]
default-character-set=utf8
EOF
sed -i "s/server_id=000001/server_id=$server_id/g" /etc/my.cnf
cd /apps/mysql/bin
mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/mysql/data
mysql_ssl_rsa_setup --datadir=/data/mysql/data
mysqld_safe > /dev/null 2>&1 &
sleep 15
ln -s /apps/mysql/bin/msql /usr/bin
passwd1=`cat /data/mysql/log/error.log | grep password | awk -F "root@localhost:" '{print $2}'| awk -F " " '{print $1}'`
echo "initial password:"$passwd1
passwd2="'test123'"
passwd3="test123"
echo "<---------------modify passwd------------------>"
mysql -uroot -h127.0.0.1 -p${passwd1} --connect-expired-password -e "alter user 'root'@'localhost' identified by ${passwd2}"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "grant all privileges on *.* to root@'%' identified by ${passwd2};"
echo "The root password has been changed:"$passwd3
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "grant replication slave,replication client on *.* to replic_user identified by 'test123';"
echo "The cluster user name have been created:replic_user"
echo "The cluster password have been created:test123"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "FLUSH PRIVILEGES;"
echo "<---------------end------------------>"
备注
脚本内容可以根据自己的数据库版本进行调整,此脚本已在安装生产环境使用过,数据库的参数,可以根据自己的服务器配置进行调整。
猜你喜欢
- 2025-01-11 免费零代码平台一键Docker云安装,快速搭建应用
- 2025-01-11 Linux 下安装最新版 MySQL
- 2025-01-11 超详细的linux部署mysql5.7实战
- 2025-01-11 Mysql 使用中常见的错误
- 2025-01-11 【Docker】部署Jira&Confluence
- 2025-01-11 Mysql:下载、安装、部署、修改密码步骤
- 2025-01-11 修改编码格式MySQL
- 2025-01-11 erpnext V15安装
- 2025-01-11 MySQL常见错误处理方法
- 2025-01-11 MySQL5.7升级到8.0过程详解
- 最近发表
-
- 网络安全干货知识 | 手把手搭建 k8s docker 漏洞环境
- docker+k8s 报错(k8s docker login)
- K8s 集群运行时:从 Docker 升级到 Containerd
- 轻松掌握k8s安装(使用docker)知识点
- 什么是 k8s(Kubernetes)?Docker 与 Kubernetes选择哪一个?
- 从 Docker 到 K8s:初学者常见的误区盘点
- Docker容器是什么?K8s和它有什么关系呢?
- Docker 是什么? 它与K8S之间是什么关系?
- Docker是什么?K8s是什么?如何从0到1实现Docker与K8s全流程部署
- K8S与Docker的区别(k8s与docker的区别是啥)
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- mybatis plus page (35)
- vue @scroll (38)
- 堆栈区别 (33)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)
- redis aof rdb 区别 (33)
- 302跳转 (33)
- http method (35)
- js array splice (33)