溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2020-07-11 21:33:12 來源:網(wǎng)絡(luò) 閱讀:1185 作者:yzy121403725 欄目:MySQL數(shù)據(jù)庫

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

 

現(xiàn)在業(yè)務(wù)發(fā)展了,開始在云上部署了,需要經(jīng)常安裝mysql,有的時候一次部署很多臺,如果還是源碼安裝一個個去執(zhí)行,效率就比較差了,所以準(zhǔn)備采用更快效率的二進(jìn)制來實(shí)現(xiàn)一鍵式自動化安裝mysql。

 

1,mysql二進(jìn)制安裝包下載地址

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

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

2)  Mysql參數(shù)文件my.cnf

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

 

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

 

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

2,自動化初始化linux服務(wù)器腳本

執(zhí)行bash -x init_linux.sh就開始自動初始化Linux服務(wù)器了, 自動化安裝腳本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,自動化安裝腳本

執(zhí)行腳本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;"

 

如果mysqld_safe啟動失敗,可以直接在my.cnf的mysqld選項(xiàng)卡里面添加skip-grant-tables=1,然后重啟mysql,就可以無密碼登陸進(jìn)來。


# 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實(shí)例

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




5why?采用二進(jìn)制安裝而不采用源碼安裝

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

 

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


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI