代码改变世界

MySQL二进制包安装脚本及批量安装

2016-01-06 11:43  ndzj  阅读(382)  评论(0编辑  收藏  举报

#!/bin/bash

###需要部署数据库的IP列表###
#ip192.168.1.10
#ip192.168.1.11
#ip192.168.1.12
#ip192.168.1.13
#ip192.168.1.14
#ip192.168.1.15


######执行脚本前,请确认已通外网,YUM源可用####
cd /root
myb=mysql-5.6.24-linux-glibc2.5-x86_64.tar.gz
ml=`echo $myb|cut -d"t" -f1|cut -d"." -f1,2,3,4`
#wget http://dev.mysql.com/get/Downloads/MySQL-5.6/$myb
mysql1=/opt/mysql
mysqldir=/usr/local
mysqldata=/data/mysql/mysql3306
mkdir $mysql1
cd $mysql1
tar xvf /root/$myb -C $mysql1
groupadd mysql && useradd -g mysql -s /sbin/nologin -d /usr/local/mysql mysql
cd $mysqldir
rm -fr /usr/local/mysql
/bin/ln -s /opt/mysql/$ml mysql
chown -R mysql:mysql mysql/
mkdir -p $mysqldata
cd $mysqldata && mkdir data logs tmp
chown -R mysql:mysql $mysqldata
mv /etc/my.cnf /etc/my.cnf.bak && :>/etc/my.cnf

########################################################mysql_profiles#####################################################

cat >>/etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock

# The MySQL server
[mysqld]
# Basic
port = 3306
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
tmpdir = /data/mysql/mysql3306/tmp
socket = /tmp/mysql.sock

log-bin = /data/mysql/mysql3306/logs/mysql-bin
log-error = error.log
slow-query-log-file = slow.log
skip-external-locking
skip-name-resolve
log-slave-updates

###############################
# FOR Percona 5.6
#extra_port = 3345
gtid-mode = 0
#thread_handling=pool-of-threads
#thread_pool_oversubscribe=8
explicit_defaults_for_timestamp
###############################

server-id =3306
character-set-server = utf8
slow-query-log
binlog_format = row
max_binlog_size = 128M
binlog_cache_size = 1M
expire-logs-days = 5
back_log = 500
long_query_time=1
max_connections=1100
max_user_connections=1000
max_connect_errors=1000
wait_timeout=100
interactive_timeout=100
connect_timeout = 20
slave-net-timeout=30
max-relay-log-size = 256M

# InnoDB
innodb_data_home_dir = /data/mysql/mysql3306/data
innodb_log_group_home_dir = /data/mysql/mysql3306/logs
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 8
#innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 200M

innodb_purge_threads=1
innodb_purge_batch_size = 32
innodb_old_blocks_pct=75
innodb_change_buffering=all
innodb_stats_on_metadata=OFF
[mysqldump]
quick
max_allowed_packet = 128M
#myisam_max_sort_file_size = 10G
[mysql]
no-auto-rehash
max_allowed_packet = 128M
prompt = '(product)\u@\h [\d]> '
default_character_set = utf8


[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 512k
read_buffer = 2M
write_buffer = 2M


[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
#malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so
EOF
#############################################################################################################################




cd /usr/local/mysql
yum -y install libaio
./scripts/mysql_install_db --defaults-file=/etc/my.cnf >$mysqldir/install.txt
sleep 10
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
echo "export PATH=PATH:mysqldir/mysql/bin">>/etc/profile
sed -i 's#PATH:mysqldir#$PATH:$mysqldir#g' /etc/profile
source /etc/profile


/etc/init.d/mysql start && echo "/etc/init.d/mysql start" >>/etc/rc.local

=========================================

批量安装脚本

!#/bin/bash

mkdir /root/ipdir #存放本次操作服务器脚本目录
sl=`cat /root/mysqlinstall.sh |grep "#ip"|wc -l` #IP数量
for i in `seq 1 $sl` ;do
ip=`cat /root/mysqlinstall.sh |grep "#ip"|cut -d"p" -f2|sed -n "$i"p`#获取本次操作IP
cp -r /root/mysqlinstall.sh /root/ipdir#把安装脚本拷贝到本次操作服务器脚本目录
sid=`echo $ip|cut -d"." -f4`#截取本次操作IP最后一位数
osid=`cat /root/mysqlinstall.sh |grep server-id`
sed -r "s/$osid/server-id ="$sid"3306/g" /root/ipdir/mysqlinstall.sh#设置server-id
scp -r /root/ipdir/mysqlinstall.sh "$ip":/tmp#拷贝修改好的脚本到远程服务器
ssh $ip 'chmod +x /tmp/mysqlinstall.sh && sh /tmp/mysqlinstall.sh &'
done

 

#@_@ 欢迎交流!联系人 广西宾阳 阿桂 qq149951292