MySQL Automation deployment (binary)

Source: Internet
Author: User

[email protected] mysql]# cat autoinstall_mysql.sh

#!/bin/bashpath=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/binexport path # check  if user isrootif [ $ (id -u)  != "0"  ]; then    echo   "Error: you must be root to runthis script, please use  root to install "    exit 1fi clearecho" ========================= ================================================ "echo " a tool toauto-compile &  install mysql 5.6.16 on redhat/centos linux  "echo" ============================== =========================================== "cur_dir=$ (pwd)   #set  mysql rootpasswordecho" ======== =================== " mysqlrootpwd=" MANAGER "echo-e " please input the root  Password of mysql: "read-p " (Default password: manager): " mysqlrootpwdif[ " $ Mysqlrootpwd " = ""  ]; thenmysqlrootpwd= "MANAGER" Fiecho "===========================" echo "Mysql root password: $mysqlrootpwd "echo" =========================== "  #which  MySQL Versiondo you want  To install?echo "==========================="  isinstallmysql56= "n" echo "install mysql 5.6.16 , Please input y "read-p " (please input y , n): " isinstallmysql56  Case "$isinstallmysql  iny|" y| yes| yes|yes|yes|yes| Yes|yes) echo "you will install mysql 5.6.16" isinstallmysql56= "Y";; *) echo "input error,you will exit install mysql 5.6.16" isinstallmysql56= "n"      exitesac get_char () {savedstty= ' stty-g ' stty-echosttycbreak#ddif=/dev/tty bs=1  Count=1 2> /dev/nullstty-rawsttyechostty$savedstty}echo "echo" press any key to  start...or press ctrl+c to cancel "char= ' Get_char '  # initIalize  the installation related content.functioninitinstall () {cat/etc/ Issueuname-amemtotal= ' free-m | grep mem | awk  ' {print  $2} '   echo-e  "\n memory is: ${memtotal} mb " #Settimezonerm-rf /etc/localtimeln-s  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime      #Synchronization  timeyuminstall -y ntpntpdate-u pool.ntp.orgdate      #Delete  old mysql programrpm-qa|grep mysqlrpm-e mysqlyum-y remove mysql-server  mysql mysql-libsyum-y remove php-mysql yum-y install yum-fastestmirror# yum-y update  #DisableSeLinuxif [ -s /etc/selinux/config ]; thensed-i  ' s/ Selinux=enforcing/selinux=disabled/g '  /etc/selinux/configfi    setenforce 0     #Installation &NBSP;OFDEPEND&NBSP;ON&NBsp;and optimization options.functioninstalldependsandopt () {cd  $cur _dir cat>>/etc/ Security/limits.conf<<eof* soft nproc 65535* hard nproc 65535* soft  nofile 65535* hard nofile 65535eof echo "fs.file-max=65535"  >> / etc/sysctl.conf}  #Install  mysqlfunctioninstallmysql56 () {echo "============================install  mysql5.6.16================================== "cd  $cur _dir  #Backup  old my.cnf#rm  -f /etc/my.cnfif [ -s /etc/my.cnf]; then    mv /etc/ my.cnf /etc/my.cnf. ' date+%y%m%d%h%m%s ' .bakfi  #mysql  directoryconfigurationmkdir -p / Data/mysqlmkdir -p /log/mysqlchown -r mysql:mysql/data/mysqlchown -r mysql:mysql /usr/local/mysqlchown -r mysql:mysql/log  groupadd mysql -g512useradd -u  512 -gmysql -s /sbin/nologin -d /home/mysql mysql  #edit  /etc/my.cnfcat>>/etc/my.cnf< <eof[client] #port         =3306#socket         =/tmp/mysql.sock#default-character-set=utf8 [mysql] #default-character-set=utf8 [ mysqld]port        =3306socket         =/tmp/mysql.sockbasedir        =/usr/local/mysqldatadir         =/data/mysqlopen_files_limit    =  3072back_log = 103max_connections =512max_connect_errors =100000table_open_cache = 512external-locking =falsemax_allowed_packet =32msort_buffer_size =2mjoin_buffer_size = 2mthread_cache_size =51query_cache_size =32mtmp_table_size = 96mmax_heap_table_size=  96mslow_query_log = 1slow_query_log_file= /data/mysql/slow.loglog-error =/data/mysql/error.loglong_query_time = 0.05server-id = 1log-bin =/data/mysql/mysql-binsync_binlog = 1binlog_cache_size  =4mmax_binlog_cache_size= 8mmax_binlog_size =1024mexpire_logs_days = 7key_buffer_size  =32Mread_buffer_size =1Mread_rnd_buffer_size= 16Mbulk_insert_buffer_size=  64mcharacter-set-server=utf8default-storage-engine= innodbbinlog_format=row  #gtid_mode =on#log_slave_ Updates=1#enforce_gtid_consistency=1 transaction_isolation= repeatable-readinnodb_additional_mem_ pool_size= 16minnodb_buffer_pool_size= 1434minnodb_data_file_path= ibdata1:1024m: autoextendinnodb_flush_log_at_trx_commit= 1innodb_log_buffer_size= 16minnodb_log_file_size=  256minnodb_log_files_in_group= 2innodb_max_dirty_pages_pct= 50innodb_file_per_table= 1innodb_ Locks_unsafe_for_binlog= 0[mysqldump]quickmax_allOwed_packet =32m eof  tar xvf/home/mysql/mysql-5.6.16-linux-glibc2.5-x86_64. Tar.gzmvmysql-5.6.16-linux-glibc2.5-x86_64 /usr/local/mysql  /usr/local/mysql/scripts/mysql_ Install_db--basedir=/usr/local/mysql --datadir=/data/mysql --defaults-file=/etc/my.cnf--user=mysql  cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchmod 700/etc/init.d/ mysqldchkconfig --addmysqlchkconfig --level2345 mysqld on cat >>/etc/ Ld.so.conf.d/mysql-x86_64.conf<<eof/usr/local/mysql/libeofldconfig if [ -d "/proc/vz"  ];thenulimit -s unlimitedfi/etc/init.d/mysqlstart  cat >>/etc/profile  <<eofexportpath=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/ mysql/bin:/usr/local/mysql/libexportld_library_path=/usr/local/mysql/libeofsource /etc/profile /usr/ Local/mysql/bin/mysqladmin-u root password  $mysqlrootpwd  cat >/tmp/mysql_sec_script<<EOFuse mysql;delete  frommysql.user where user!= ' root '  or host!= ' localhost '; update user setpassword= Password (' MANAGER ')  where user= ' root '; grantselect,delete,update,insert on *.* to  [email protected] ' 192.168.1.% '  identified by ' MANAGER '; Grant all privilegeson  *.* to [email protected] ' 192.168.1.% '  identified by  ' MANAGER ';flush  privileges; eof /usr/local/mysql/bin/mysql-u root -p$mysqlrootpwd -h localhost < / tmp/mysql_sec_script  #rm  -f/tmp/mysql_sec_scriptsource /etc/profile/etc/init.d/mysqldrestart#/ Etc/init.d/mysqlstopecho "============================mysql 5.6.16 installcompleted================== ======= "}  functioncheckinstall () {echo" ===================================== check install =================================== "clearismysql=" "echo" Checking ... " if [ -s/usr/local/mysql/bin/mysql ]  && [ -s /usr/local/mysql/bin/mysqld_safe ]&& [ -s /etc/ my.cnf ]; then  echo  "Mysql: ok"   ismysql= "OK"   else   echo  "Error: /usr/local/mysql notfound!!! Mysql install failed. " fi if ["$ismysql"  =  "OK"  ]; thenecho  "installmysql 5.6.16 " Completed! enjoy it. " echo "=========================================================================" Netstat -ntlelseecho "Sorry , failed to install mysql! " echo  "You cantail /root/mysql-install.log from your server." fi}  #The  installationloginitinstall2>&1 | tee /root/ mysql-install.logcheckanddownloadfiles2>&1 | tee -a /root/ Mysql-install.loginstalldependsandopt2>&1 | tee -a /root/mysql-install.logInstallMySQL562>&1 | tee  -a /root/mysql-install.logcheckinstall2>&1 | tee -a /root/mysql-install.log




Reference: http://www.dataguru.cn/thread-476844-1-1.html

This article is from the "Age volt" blog, please make sure to keep this source http://suifu.blog.51cto.com/9167728/1754063

MySQL Automation deployment (binary)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.