mysql多实例安装脚本

2018-06-17 22:54:57来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

#! /bin/bash
# v.mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
# only install master mysql
# time:2016-08-15

# pkg dir
pkg_dir=`pwd`

# mysql base dir
data_dir="/data/mysql_root/mysql"
base_dir="/usr/local/mysql"

# create MySQL group and user
echo "start create mysql group and user" >> ${pkg_dir}/install.log

groupadd mysql
useradd -g mysql mysql  -s /sbin/nologin

echo "end mysql group and user" >> ${pkg_dir}/install.log

# mysql datafile path
# install mysqld 
# grant privileges
mkdir -p ${data_dir}/data 2>/dev/null
chown -R mysql:mysql ${data_dir}/data
# un_tar.gz and install mysql programmer
echo "start un_tar.gz..." >> ${pkg_dir}/install.log
cd ${pkg_dir} && tar -xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz  -C /usr/local && cd /usr/local && mv mysql-5.6.30-linux-glibc2.5-x86_64 mysql;

echo "end install mysql"  >> ${pkg_dir}/install.log

echo "set mysql my.cnf params" >> ${pkg_dir}/install.log

# stored mysqld multi execute log
mkdir -p ${base_dir}/multi_log 2>/dev/null

# comm parameter of my.cnf 
cat<<EOF > ${base_dir}/my.cnf
# The mysqld multi instance
[mysqld_multi]
mysqld = ${base_dir}/bin/mysqld_safe
mysqladmin = ${base_dir}/bin/mysqladmin
log =${base_dir}/multi_log/mysqld_multi.log

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

EOF

# other my.cnf parameter part 
pre_install_mysqld(){
cat<<EOF >> ${base_dir}/my.cnf
# The MySQL server
[mysqld${port:2}]
port		= ${port} 
socket		= ${data_dir}/data${port}/mysql.socket
max-connections = 800
skip-name-resolve
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 1073M 
table_open_cache = 512
sort_buffer_size = 512K 
read_buffer_size = 512K
read_rnd_buffer_size = 512K
join_buffer_size = 128K
myisam_sort_buffer_size = 64M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
tmp_table_size = 64M
max_heap_table_size = 64M

basedir=${base_dir}
datadir=${data_dir}/data${port}

pid-file = ${data_dir}/data${port}/mysql.pid
log_error = ${data_dir}/data${port}/mysql.err

# set binary logging is required for replication
log-bin=mysql-bin
binlog_cache_size = 32M

# event_scheduler shutoff in mysqld slave
event_scheduler = 1 
binlog_format=row
expire_logs_days = 3

# set slow log
slow_query_log = 1
long_query_time = 2

#set 字符
character_set_server = utf8

#set 大小写敏感

lower_case_table_names=1

# set mysqld server_id
server-id	= ${port}

# set innodb params
innodb_data_home_dir = ${data_dir}/data${port} 
innodb_log_group_home_dir = ${data_dir}/data${port} 
innodb_buffer_pool_size = 5972M
innodb_additional_mem_pool_size = 10M
innodb_log_file_size = 512M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 2 
innodb_flush_method = O_DIRECT
innodb_file_per_table = 1
innodb_lock_wait_timeout = 10
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_stats_on_metadata = 0
innodb_purge_threads = 1
innodb_read_io_threads = 12
innodb_write_io_threads = 12
innodb_purge_threads = 1
innodb_open_files = 500
innodb_thread_concurrency = 0
innodb_io_capacity = 600

[client]
default-character-set = utf8

EOF
# initizal mysql Db 
chmod +x ${base_dir}/scripts/mysql_install_db
${base_dir}/scripts/mysql_install_db --basedir=${base_dir} --datadir=${data_dir}/data${port} --user=mysql --defaults-file=${base_dir}/my.cnf >> ${pkg_dir}/install.log
echo "end mysqld install." >> ${pkg_dir}/install.log
}

# mysql datafile path
for port in 2016 3017 4018 5019 6020 
do
        # check mysql base and data dir folder
        if [ ! -d ${data_dir}/data${port} ];then
                mkdir -p ${data_dir}/data${port}
                # function mysqld_install to mysql programmer
                pre_install_mysqld $port
        else
                pre_install_mysqld $port
        fi
done

#mysql data
chown -R mysql:mysql ${data_dir}/data
chown -R mysql:mysql ${base_dir}/data

#环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>  /etc/profile
source /etc/profile

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:总结:如何使用redis缓存加索引处理数据库百万级并发

下一篇:How to return dictionary keys as a list in Python 3.3