本篇內容介紹了“自動(dòng)安裝腳本分享”的有關(guān)知識,在實(shí)際案例的操作過(guò)程中,不少人都會(huì )遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學(xué)有所成!
環(huán)境要求:centos:6.8
MySQL:5.7.20
MySQL安裝文件名:mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
MySQL源文件路徑:/usr/local/src
MYSQL腳本文件:/usr/local/src/install_mysql.sh
1、腳本如下:
#/bin/sh
#px 2017-11-29
#mysql install
#email:kitten-pan@163.com & 752684428
#version 2.0
#mysql-version mysql5.7.20
source_path=/usr/local/src
install_path=/usr/local/mysql
install_name=mysql-5.7.20-linux-glibc2.12-x86_64
##檢測本機環(huán)境
env_fun()
{
echo "============檢測本機環(huán)境,please wait ..."
username=`cat /etc/passwd |grep mysql|cut -c 1-5`
if [ "$username" = "mysql" ];then
echo "MySQL account is exits..."
return 10
else
echo "mysql account is not exits,ready add..."
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
return 12
fi
}
##判斷MySQL是否安裝
check_fun()
{
rpm_name=`rpm -aq |grep mysql-server`
echo $rpm_name
if [ ! $rpm_name ];then
echo "begin check the source install,please wait for a moment..."
if [ -d $install_path ];then
echo "source install is exist,quit..."
exit 0
else
echo "本機未安裝MySQL,稍后為你安裝..."
install_fun
op_fun
fi
else
echo -n "rpm MySQL已經(jīng)安裝,是否刪除?[yes|no]"
read select
if [ $select = yes ];then
rpm -e $rpm_name --nodeps
rm -rf /var/log/mysqld.log
check_fun
else
exit 0
fi
fi
}
###安裝MySQL
install_fun()
{
read -p "Input a mysql version:" -t 30 mysql_version
read -p "Input a mysql port:" -t 30 mysql_port
read -p "Input a mysql_server_id:" -t 30 mysql_server_id
cd $source_path && echo "解壓中,please waiting..."
tar -zxvf ${install_name}.tar.gz && mv $install_name $install_path
##創(chuàng )建數據目錄
mkdir -pv /data/mysqldata
###給MySQL目錄的MySQL賬號權限
cd /usr/local && chown mysql.mysql mysql
chown -R mysql.mysql /data/mysqldata
cd $install_path && bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata
cd support-files && cp -rf mysql.server /etc/init.d/mysqld
sed -i 's#datadir\=\/usr\/local\/mysql\/data#\datadir\=\/data\/mysqldata#g' /etc/init.d/mysqld
cat > /etc/my.cnf << EOF
[client]
port = 3309
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
##mysql-version=5.7.20
port = 3309
socket = /tmp/mysql.sock
datadir = /data/mysqldata
basedir = /usr/local/mysql
pid-file = /data/mysqldata/mysqld.pid
user = mysql
server-id = 1
lower_case_table_names = 1
character-set-server = utf8
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 0
query_cache_size = 2M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = row
expire_logs_days = 30
log-error=/data/mysqldata/mysqld.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysqldata/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default-time_zone = '+8:00'
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_file_path = ibdata1:300M:autoextend
innodb_open_files = 5000
innodb_buffer_pool_size = 2048M
innodb_write_io_threads = 4
innodb_read_io_threads = 8
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 128M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 300
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
echo "export PATH=/$PATH:/usr/local/mysql/bin">>/etc/profile
echo 'export MYSQL_PS1="(\u@\h:\p) [\d]>"' >> /etc/profile
source /etc/profile
service mysqld restart
}
op_fun()
{
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 345 mysqld on
}
main(){
echo "###==================================================###"
echo "###welcome to make install mysql with this script###"
echo "###copyright 2013 by px###"
echo "###==================================================###"
sleep 5
env_fun
re=$?
if [ re = 10 ];then
check_fun
else
check_fun
fi
}
main
exit 0
2、執行自動(dòng)安裝腳本
需要填寫(xiě)MySQL的版本信息、端口信息、serverid信息等
點(diǎn)擊(此處)折疊或打開(kāi)
sh install_mysql.sh
###==================================================###
###welcome to make install mysql with this script###
###copyright 2013 by px###
###==================================================###
============檢測本機環(huán)境,please wait ...
mysql account is not exits,ready add...
begin check the source install,please wait for a moment...
本機未安裝MySQL,稍后為你安裝...
Input a mysql version:5.7.20
Input a mysql port:3309
Input a mysql_server_id:1
解壓中,please waiting...
3、自動(dòng)安裝完畢 啟動(dòng)
# service mysqld restart
MySQL server PID file could not be found! [FAILED]
Starting MySQL............. [ OK ]
4、登入MySQL 修改密碼
點(diǎn)擊(此處)折疊或打開(kāi)
[root@ct562 mysqldata]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
(root@localhost:mysql.sock) [(none)]>
(root@localhost:mysql.sock) [(none)]>
(root@localhost:mysql.sock) [(none)]>
(root@localhost:mysql.sock) [(none)]>
(root@localhost:mysql.sock) [(none)]>
(root@localhost:mysql.sock) [(none)]>set password for root@'localhost' =PASSWORD('sysdba@321')
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站