MySQL最新版本 MySQL5.7.11 批量自動化一鍵式安裝(轉)


--背景雲端

以前都喜歡了源碼安裝MySQL,總覺得源碼是高大上的事情,不過源碼也需要時間,特別是make的時候,如果磁盤和cpu差的話,時間很長很長,在虛擬機上安裝mysql尤其甚慢了。

 

現在業務發展了,開始在雲上部署了,需要經常安裝mysql,有的時候一次部署很多台,如果還是源碼安裝一個個去執行,效率就比較差了,所以准備采用更快效率的二進制來實現一鍵式自動化安裝mysql。

 

1,mysql二進制安裝包下載地址

下載地址:http://download.csdn.net/detail/mchdba/9488918,包括

1)  一鍵式自動安裝腳本:auto_install_mysql5.7.sh;

2)  Mysql參數文件my.cnf

3)  Mysql5.7二進制安裝包,在readme_mysql5.7_down_address.txt文件里面有下載地址連接,比mysql官網下載速度快很多倍。

 

PS:下載之后,將腳本已經所有軟件放在同一個目錄比如/soft目錄下面。

 

blog源地址:http://blog.csdn.net/mchdba/article/details/51138063,謝絕轉載。

2,自動化初始化linux服務器腳本

執行bash -x init_linux.sh就開始自動初始化linux服務器了, 自動化安裝腳本init_linux.sh如下,下載地址為http://download.csdn.net/detail/mchdba/9488929:

#1 instal jdk , add tomcat user                                                                               

sh init_jdk.sh

 

useradd tomcat

mkdir -p /usr/local/app/

chown -R tomcat.tomcat /usr/local/app

 

#2 # vim /etc/sudoers

echo "tomcat  ALL=(ALL)       ALL" >> /etc/sudoers

 

#3 set limits.conf

echo "*    soft nofile 65536" >>  /etc/security/limits.conf

echo "*    hard nofile 65536" >> /etc/security/limits.conf

ulimit -a

 

 

 

#4 kernel optimization

grep "net.ipv4.tcp_keepalive_time = 30" /etc/sysctl.conf

if [ $? != 0 ]

  then

cat <<EOF>> /etc/sysctl.conf

net.ipv4.tcp_max_tw_buckets = 6000

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.tcp_tw_recycle = 0

net.ipv4.tcp_tw_reuse = 1

net.core.somaxconn = 262144

net.core.netdev_max_backlog = 262144

net.ipv4.tcp_max_orphans = 262144

net.ipv4.tcp_max_syn_backlog = 262144

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_fin_timeout = 1

net.ipv4.tcp_keepalive_time = 30

net.ipv4.tcp_keepalive_probes = 6

net.ipv4.tcp_keepalive_intvl = 5

net.ipv4.tcp_timestamps = 0

EOF

 

 

sed -i 's/net.bridge.bridge-nf-call-ip6tables = 0/#net.bridge.bridge-nf-call-ip6tables = 0/g' /etc/sysctl.conf

sed -i 's/net.bridge.bridge-nf-call-iptables = 0/#net.bridge.bridge-nf-call-iptables = 0/g' /etc/sysctl.conf

sed -i 's/net.bridge.bridge-nf-call-arptables = 0/#net.bridge.bridge-nf-call-arptables = 0/g' /etc/sysctl.conf

fi

 

sysctl -p

 

#5 selinux disabled

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

sed -i 's/id:5:initdefault:/id:3:initdefault:/g' /etc/inittab

 

#6 stop some services

service iptables stop

sh stopservice.sh

 

#7 see the version

#less /etc/issue

 

#8 set 90-nproc

sed -i 's/*          soft    nproc     1024/#*          soft    nproc     1024/g'   /etc/security/limits.d/90-nproc.conf

sed -i 's/root       soft    nproc     unlimited/*       soft    nproc     unlimited/g'   /etc/security/limits.d/90-nproc.conf

 

#9 system basic lib package install

yum install gcc gcc-c++ ncurses-devel.x86_64 cmake.x86_64 libaio.x86_64 bison.x86_64 gcc-c++.x86_64 bind-utils wget curl curl-devel perl openssh-clients setuptool sysstat -y

yum search rz -y

yum install -y lrzsz.x86_64

 

#10 set shanghai time

cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

hwclock

 

#11 restart the linux server

shutdown -r now

 

 

3,自動化安裝腳本

執行腳本bash  -x auto_install_mysql5.7.sh,開始一鍵式安裝,自動化安裝腳本如下:

# install the basie lib

yum install cmake -y

groupadd mysql

useradd -g mysql mysql 

autoreconf --force --install

libtoolize --automake --force

automake --force --add-missing

yum install -y libtoolize

yum install gcc gcc-c++ -y

yum install -y ncurses-devel.x86_64

yum install -y cmake.x86_64

yum install -y libaio.x86_64

yum install -y bison.x86_64

yum install -y gcc-c++.x86_64

yum install make -y

 

# add mysql account,create the basic directory

mkdir -p /data/mysql/data

cd /data/mysql/data

chown -R mysql.mysql /data

chown -R mysql.mysql /usr/local/mysql5711

mkdir -p /data/mysql/binlog/

chown -R mysql.mysql /data/mysql/binlog/

cd /usr/local/mysql5711/

 

# init databases

rm -rf /data/mysql/data/*

cp my.cnf /usr/local/mysql5711/my.cnf

time bin/mysqld --defaults-file=/usr/local/mysql5711/my.cnf --initialize --user=mysql

 

# set the auto start on linux server started

cp support-files/mysql.server /etc/init.d/mysql

chmod 700 /etc/init.d/mysql

echo "export PATH=$PATH:/usr/local/mysql5711/bin">>/etc/profile

source /etc/profile

chkconfig --add mysql

 

# do a soft link to start mysql

cd /usr/local/

ln -s /usr/local/mysql5711 mysql

 

# remove default my.cnf

mv /etc/my.cnf /tmp/

 

# set the default password

/usr/local/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking &

/usr/local/mysql/bin/mysql -uroot --password='' --socket='/usr/local/mysql/mysql.sock' -e " update mysql.user set authentication_string=password('dns_yuerld') where user='root' and Host = 'localhost'; flush privileges;"

/usr/local/mysql/bin/mysql -uroot --password='dns_yuerld' --socket='/usr/local/mysql/mysql.sock' -e " set PASSWORD=PASSWORD('dns_yuerld'); create database t; create table t1 select 1 as a; select * from t1;"

 

# restart the mysql server

service mysql restart

 

# check the test

/usr/local/mysql/bin/mysql -uroot --password='dns_yuerld' --socket='/usr/local/mysql/mysql.sock' -e " select * from t1;"

 

 

 

4,批量安裝很多mysql實例

將腳本和安裝軟件scp到N台服務器,然后ssh ip地址 " sh /soft/init_linux.sh; sh /soft/install_mysql.sh;",用后台批量進程來安裝。

 

 

 

5,why?采用二進制安裝而不采用源碼安裝

主要是源碼安裝在make環節需要消耗太多時間,一次源碼安裝mysql需要很久,而二進制安裝免去了configure、make、make install這一步驟,大大縮減了安裝時間提升了效率,單台安裝mysql感覺不大,如果一次性安裝成千上萬台,這個差距就是天上地下咯。

 

另外:安裝過程中要實時查看控制台信息,如果有詭異的錯誤信息,要及時排查。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM