该脚本简单实现MySQL5.7.21的自动化安装,比较简单,但是基本能实现本公司MySQL的快速部署(滑稽脸)
#!/bin/bash
# author:颜海航
# version:1.0
# date:2019-04-25
echo "############################# MySQL installing..........########################"
echo "-----config my.cnf-----"
mv /etc/my.cnf /etc/my.cnf_`date +%Y%m%d`
SERVER_ID=`ifconfig eth0 |grep inet |awk '{print $2}'|awk -F. '{print $3$4}'`
Mem=`free -m |grep Mem |awk '{print $2}'`
SIZE=$[Mem*1/2]
cat >>/etc/my$ipaddr.cnf<<EOF
[mysql]
default-character-set=utf8
[client]
port = 3306
socket = /server/mysql_data/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
character-set-server = utf8
socket = /server/mysql_data/mysql.sock
pid-file = /server/mysql_data/mysql.pid
basedir = /usr/local/mysql
datadir = /server/mysql_data/
log-error =/server/mysql_data/error.log
skip-name-resolve
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
server-id = $SERVER_ID
log-bin = mysql-bin
binlog_format = row
#binlog-ignore-db = mysql
#binlog-ignore-db = information_schema
#binlog-ignore-db = performance_schema
#binlog-ignore-db = test
sync-binlog = 1
#slave-skip-errors = all
log-output = FILE
# slow query log
slow_query_log = 1
long-query-time = 1
slow_query_log_file =/server/mysql_data/slow.log
#log-queries-not-using-indexes
innodb_buffer_pool_size = ${SIZE}M
innodb_buffer_pool_instances = 2
innodb_data_home_dir = /server/mysql_data/
innodb_data_file_path = ibdata1:512M:autoextend
innodb_log_buffer_size = 512M
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_group_home_dir = /server/mysql_data/
innodb_file_per_table = 1
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
innodb_flush_log_at_trx_commit = 1
max_connections=4000
back_log=200
innodb_io_capacity=5000
innodb_write_io_threads=8
innodb_read_io_threads=8
wait_timeout=1800
interactive_timeout=1800
expire_logs_days = 15
#time
log_timestamps = SYSTEM
#gtid
#gtid_mode=on
#log_slave_updates=1
#enforce_gtid_consistency=1
#skip-external-locking
table_open_cache = 512
max_allowed_packet = 512M
sort_buffer_size = 8M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
#myisam_sort_buffer_size = 64M
thread_cache_size = 8
# Try number of CPU's*2 for thread_concurrency
#thread_concurrency = 8
tmp_table_size = 512M
max_heap_table_size = 512M
[mysql]
#auto-rehash
#user=zabbix
#password=zabbix
#socket=/server/mysql_data/tmp/mysql.sock
EOF
echo "-----create group and user:mysql-----"
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
echo "----- install dependent package -----"
yum -y install numactl libaio lrzsz wget
echo "-----Download MySQL-----"
if [ -d /soft ];then
echo "software dir is exist! Please check!"
else
mkdir -p /soft
fi
cd /soft
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
echo "-----Unzip MySQL-----"
tar zxvf /soft/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mv /soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
echo "-----create datadir and change owner of dir-----"
mkdir -p /server/mysql_data
chown -R mysql.mysql /etc/my.cnf
chown -R mysql.mysql /usr/local/mysql/
chown -R mysql.mysql /server/mysql_data/
echo "-----config profile-----"
echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile
source /etc/profile
echo "-----initialize MySQL-----"
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/server/mysql_data/
echo "-----start MySQL-----"
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
#!/bin/bash
# author:颜海航
# version:1.0
# date:2019-04-25
echo "############################# MySQL installing..........########################"
echo "-----config my.cnf-----"
mv /etc/my.cnf /etc/my.cnf_`date +%Y%m%d`
SERVER_ID=`ifconfig eth0 |grep inet |awk '{print $2}'|awk -F. '{print $3$4}'`
Mem=`free -m |grep Mem |awk '{print $2}'`
SIZE=$[Mem*1/2]
cat >>/etc/my$ipaddr.cnf<<EOF
[mysql]
default-character-set=utf8
[client]
port = 3306
socket = /server/mysql_data/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
character-set-server = utf8
socket = /server/mysql_data/mysql.sock
pid-file = /server/mysql_data/mysql.pid
basedir = /usr/local/mysql
datadir = /server/mysql_data/
log-error =/server/mysql_data/error.log
skip-name-resolve
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
server-id = $SERVER_ID
log-bin = mysql-bin
binlog_format = row
#binlog-ignore-db = mysql
#binlog-ignore-db = information_schema
#binlog-ignore-db = performance_schema
#binlog-ignore-db = test
sync-binlog = 1
#slave-skip-errors = all
log-output = FILE
# slow query log
slow_query_log = 1
long-query-time = 1
slow_query_log_file =/server/mysql_data/slow.log
#log-queries-not-using-indexes
innodb_buffer_pool_size = ${SIZE}M
innodb_buffer_pool_instances = 2
innodb_data_home_dir = /server/mysql_data/
innodb_data_file_path = ibdata1:512M:autoextend
innodb_log_buffer_size = 512M
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_group_home_dir = /server/mysql_data/
innodb_file_per_table = 1
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
innodb_flush_log_at_trx_commit = 1
max_connections=4000
back_log=200
innodb_io_capacity=5000
innodb_write_io_threads=8
innodb_read_io_threads=8
wait_timeout=1800
interactive_timeout=1800
expire_logs_days = 15
#time
log_timestamps = SYSTEM
#gtid
#gtid_mode=on
#log_slave_updates=1
#enforce_gtid_consistency=1
#skip-external-locking
table_open_cache = 512
max_allowed_packet = 512M
sort_buffer_size = 8M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
#myisam_sort_buffer_size = 64M
thread_cache_size = 8
# Try number of CPU's*2 for thread_concurrency
#thread_concurrency = 8
tmp_table_size = 512M
max_heap_table_size = 512M
[mysql]
#auto-rehash
#user=zabbix
#password=zabbix
#socket=/server/mysql_data/tmp/mysql.sock
EOF
echo "-----create group and user:mysql-----"
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
echo "----- install dependent package -----"
yum -y install numactl libaio lrzsz wget
echo "-----Download MySQL-----"
if [ -d /soft ];then
echo "software dir is exist! Please check!"
else
mkdir -p /soft
fi
cd /soft
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
echo "-----Unzip MySQL-----"
tar zxvf /soft/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mv /soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
echo "-----create datadir and change owner of dir-----"
mkdir -p /server/mysql_data
chown -R mysql.mysql /etc/my.cnf
chown -R mysql.mysql /usr/local/mysql/
chown -R mysql.mysql /server/mysql_data/
echo "-----config profile-----"
echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile
source /etc/profile
echo "-----initialize MySQL-----"
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/server/mysql_data/
echo "-----start MySQL-----"
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
#!/bin/bash
# author:颜海航
# version:1.0
# date:2019-04-25
echo "############################# MySQL installing..........########################"
echo "-----config my.cnf-----"
mv /etc/my.cnf /etc/my.cnf_`date +%Y%m%d`
SERVER_ID=`ifconfig eth0 |grep inet |awk '{print $2}'|awk -F. '{print $3$4}'`
Mem=`free -m |grep Mem |awk '{print $2}'`
SIZE=$[Mem*1/2]
cat >>/etc/my$ipaddr.cnf<<EOF
[mysql]
default-character-set=utf8
[client]
port = 3306
socket = /server/mysql_data/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
character-set-server = utf8
socket = /server/mysql_data/mysql.sock
pid-file = /server/mysql_data/mysql.pid
basedir = /usr/local/mysql
datadir = /server/mysql_data/
log-error =/server/mysql_data/error.log
skip-name-resolve
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
server-id = $SERVER_ID
log-bin = mysql-bin
binlog_format = row
#binlog-ignore-db = mysql
#binlog-ignore-db = information_schema
#binlog-ignore-db = performance_schema
#binlog-ignore-db = test
sync-binlog = 1
#slave-skip-errors = all
log-output = FILE
# slow query log
slow_query_log = 1
long-query-time = 1
slow_query_log_file =/server/mysql_data/slow.log
#log-queries-not-using-indexes
innodb_buffer_pool_size = ${SIZE}M
innodb_buffer_pool_instances = 2
innodb_data_home_dir = /server/mysql_data/
innodb_data_file_path = ibdata1:512M:autoextend
innodb_log_buffer_size = 512M
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_group_home_dir = /server/mysql_data/
innodb_file_per_table = 1
innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G
innodb_flush_log_at_trx_commit = 1
max_connections=4000
back_log=200
innodb_io_capacity=5000
innodb_write_io_threads=8
innodb_read_io_threads=8
wait_timeout=1800
interactive_timeout=1800
expire_logs_days = 15
#time
log_timestamps = SYSTEM
#gtid
#gtid_mode=on
#log_slave_updates=1
#enforce_gtid_consistency=1
#skip-external-locking
table_open_cache = 512
max_allowed_packet = 512M
sort_buffer_size = 8M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
#myisam_sort_buffer_size = 64M
thread_cache_size = 8
# Try number of CPU's*2 for thread_concurrency
#thread_concurrency = 8
tmp_table_size = 512M
max_heap_table_size = 512M
[mysql]
#auto-rehash
#user=zabbix
#password=zabbix
#socket=/server/mysql_data/tmp/mysql.sock
EOF
echo "-----create group and user:mysql-----"
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
echo "----- install dependent package -----"
yum -y install numactl libaio lrzsz wget
echo "-----Download MySQL-----"
if [ -d /soft ];then
echo "software dir is exist! Please check!"
else
mkdir -p /soft
fi
cd /soft
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
echo "-----Unzip MySQL-----"
tar zxvf /soft/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mv /soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
echo "-----create datadir and change owner of dir-----"
mkdir -p /server/mysql_data
chown -R mysql.mysql /etc/my.cnf
chown -R mysql.mysql /usr/local/mysql/
chown -R mysql.mysql /server/mysql_data/
echo "-----config profile-----"
echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile
source /etc/profile
echo "-----initialize MySQL-----"
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/server/mysql_data/
echo "-----start MySQL-----"
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
echo "-----init password of MySQL-----"
OLD_PWD=`cat /server/mysql_data/error.log | grep password |awk -F: '{print $5}' |awk '{print $1}'`
echo 'old password:$OLD_PWD'
NEW_PWD=`openssl rand -base64 9`
echo 'set password for 'root'@'localhost' =password('$NEW_PWD');'