MySQL5.6 One-click installation script

Source: Internet
Author: User
Tags uuid iptables yum repolist egrep

#!/bin/sh

#*************************

#Created By:yixianwei.cn

#*************************

Yum install-y grep procps coreutils xfsprogs util-linux-ng e2fsprogs libselinux-utils chkconfig wget yum-utils gawk Libai o Cronie XZ

if [-b/dev/sdb]; then

If [-Z ' ' Mount |grep/dev/sdb ']; then

Mkfs.xfs-b size=4096-d sectsize=4096-i attr=2-l lazy-count=1,sectsize=4096-l data/dev/sdb

If [-Z "' Blkid/dev/sdb '"]; then

Uuidgen | Xargs tune2fs/dev/sdb-u

Fi

Sdbuuid= "' Blkid-o value-s uuid/dev/sdb '"

If [-Z ' grep $sdbuuid/etc/fstab ']; then

echo "uuid= $sdbuuid/data xfs rw,noatime,noikeep,allocsize=16m,attr2,largeio,inode64 0 0" >> /etc/fstab

echo "echo \" deadline\ ">/sys/block/sdb/queue/scheduler" >/etc/profile.d/skyeye_mysql.sh

sh/etc/profile.d/skyeye_mysql.sh

Fi

Mkdir-p/data

Mount-a

Else

Mkdir-p/data

Fi

Else

Mkdir-p/data

Fi


If [-Z "' Grep-i mysql/etc/security/limits.conf '"]; then

echo "Mysql-proc 10240" >>/etc/security/limits.conf

echo "Mysql-nofile 65535" >>/etc/security/limits.conf

Ulimit-u 10240

Ulimit-n 65535

Fi


If [-Z "' Grep-i tcp_timestamps/etc/sysctl.conf '"]; then

echo "net.ipv4.tcp_timestamps = 1" >>/etc/sysctl.conf

Fi

If [-Z "' Grep-i tcp_tw_recycle/etc/sysctl.conf '"]; then

echo "net.ipv4.tcp_tw_recycle = 1" >>/etc/sysctl.conf

Fi

If [-Z "' Grep-i tcp_tw_reuse/etc/sysctl.conf '"]; then

echo "Net.ipv4.tcp_tw_reuse = 1" >>/etc/sysctl.conf

Fi

If [-Z "' Grep-i swappiness/etc/sysctl.conf '"]; then

echo "vm.swappiness = 1" >>/etc/sysctl.conf

Fi

If [-Z "' Grep-i aio-max-nr/etc/sysctl.conf '"]; then

echo "FS.AIO-MAX-NR = 1048576" >>/etc/sysctl.conf

Fi

If [-Z "' Grep-i ip_local_port_range/etc/sysctl.conf '"]; then

echo "Net.ipv4.ip_local_port_range = 10000 65535" >>/etc/sysctl.conf

Fi


Sysctl-p


Setenforce 0

Sed-i ' s/selinux=enforcing/selinux=disabled/'/etc/selinux/config


Service Iptables Stop

Service Ip6tables Stop

Chkconfig iptables off

Chkconfig Ip6tables off

Service MySQL Stop

Service Mysqld Stop

Mysqld_multi--user=root Stop

Killall-9 Mysqld_safe

Killall-9 mysqld


Oldmysqlserver= "' Rpm-qa|egrep-i mysql-server '"

If [-N "$oldmysqlserver"]; then

Yum Erase-y $oldmysqlserver

Fi


Yum Localinstall-y mysql-community-release-el6-5.noarch.rpm


Mysqlrepo= "' Yum repolist all | Egrep-i mysql[0-9]+-community |grep enabled|awk ' {print '} ' "

Yum-config-manager--disable $mysqlrepo

Yum-config-manager--enable mysql56-community


Yum install-y mysql-community-client* ' uname-m '. RPM mysql-community-devel* ' uname-m '. RPM mysql-community-server* ' Uname-m '. RPM mysql-community-common* ' uname-m '. RPM mysql-community-libs* ' uname-m '. RPM mysql-community-libs-compat* ' Uname-m '. rpm

Service Mysqld Stop


Mkdir-p/data/mysql

Chown Mysql:mysql/data/mysql


if [!-d/data/mysql/mysqldata3306]; then

Mkdir-p/data/mysql/mysqldata3306

Mkdir-p/data/mysql/mysqldata3306/mydata

Mkdir-p/data/mysql/mysqldata3306/binlog

Mkdir-p/data/mysql/mysqldata3306/innodb_ts

Mkdir-p/data/mysql/mysqldata3306/innodb_log

Mkdir-p/data/mysql/mysqldata3306/relaylog

Mkdir-p/data/mysql/mysqldata3306/tmpdir

Mkdir-p/data/mysql/mysqldata3306/log

Mkdir-p/data/mysql/mysqldata3306/sock

Chown-r mysql:mysql/data/mysql/mysqldata3306

Fi


if [-f/etc/my.cnf]; then

Mv-f/etc/my.cnf "/etc/my.cnf. ' Date +%s '. Bak '

Fi

if [-f/etc/mysql/my.cnf]; then

Mv-f/etc/mysql/my.cnf "/etc/mysql/my.cnf. ' Date +%s '. Bak '

Fi

if [-f/usr/etc/my.cnf]; then

Mv-f/usr/etc/my.cnf "/usr/etc/my.cnf. ' Date +%s '. Bak '

Fi

If [-f ~/.my.cnf]; then

Mv-f ~/.my.cnf "~/.my.cnf. ' Date +%s '. Bak '

Fi

if [-f/root/.my.cnf]; then

Mv-f/root/.my.cnf "/root/. ' Date +%s '. Bak '

Fi

if [-f/var/lib/mysql/.my.cnf]; then

Mv-f/var/lib/mysql/.my.cnf "/var/lib/mysql/. ' Date +%s '. Bak '

Fi

Mysqlhome= "' grep ^mysql/etc/passwd |awk-f ': ' {print $6} '"

If [-F "$mysqlhome/.my.cnf"]; then

Mv-f $mysqlhome/.my.cnf "$mysqlhome/. ' Date +%s '. Bak '

Fi



Bpsize= "' free-m |grep Mem:|awk ' {print int ($2/2) ==$2/2?$2/2:int ($2/2) +1} ' m"

Iocapacity= "' Df-b GB--total/data |grep Total|awk ' {sub (/gb/,\" \ ", $ $);p rint ($2/300==int ($2/300)? $2/300:int ($2/300) + 1) *100} ""



Cat >>/etc/my.cnf <<eof

#*************************

#Created By:yixianwei.cn

#*************************

[Mysqld]

User=mysql

Pid-file=/data/mysql/mysqldata3306/sock/mysql.pid

Socket=/data/mysql/mysqldata3306/sock/mysql.sock

Datadir=/data/mysql/mysqldata3306/mydata

Tmpdir=/data/mysql/mysqldata3306/tmpdir

Skip-name-resolve

Performance_schema=off

transaction-isolation=read-committed

Character_set_server=utf8

Collation_server=utf8_general_ci

Lower_case_table_names=1

Explicit_defaults_for_timestamp

group_concat_max_len=1048576

max_connections=800

max_connect_errors=9999

wait_timeout=172800

interactive_timeout=172800

max_allowed_packet=64m

Read_rnd_buffer_size=2m

Query_cache_type=1

query_cache_size=32m

query_cache_limit=16k

Log-error=/data/mysql/mysqldata3306/log/error.log

log_warnings=2

long_query_time=0.3

Slow_query_log

Slow_query_log_file=/data/mysql/mysqldata3306/log/slow-query.log

server-id=3306

Log-bin-index=/data/mysql/mysqldata3306/binlog/mysql-bin.index

#log-bin=/data/mysql/mysqldata3306/binlog/mysql-bin

Binlog-format=mixed

binlog_cache_size=256k

Sync_binlog=1

Expire_logs_days=15

Log-slave-updates

Sysdate-is-now

Innodb_support_xa=0

Relay-log-index=/data/mysql/mysqldata3306/relaylog/mysql-relay-bin.index

Relay-log=/data/mysql/mysqldata3306/relaylog/mysql-relay-bin

Innodb_buffer_pool_size=${bpsize}

Innodb_data_home_dir=/data/mysql/mysqldata3306/innodb_ts

Innodb_data_file_path=ibdata1:256m:autoextend

innodb_open_files=7168

Innodb_flush_log_at_trx_commit=1

innodb_log_file_size=4g

Innodb_log_group_home_dir=/data/mysql/mysqldata3306/innodb_log

Innodb_adaptive_flushing_lwm=30

Innodb_flush_method=o_direct

Innodb_io_capacity=${iocapacity}

[MySQL]

No-auto-rehash

prompt= "\\[email protected]\\h: \\d \\r:\\m:\\s>"

Default-character-set=utf8

Socket=/data/mysql/mysqldata3306/sock/mysql.sock

[Mysqldump]

User=skyeyebackup

Password=skyeyebackup

Socket=/data/mysql/mysqldata3306/sock/mysql.sock

Hex-blob

max_allowed_packet=2g

Default-character-set=utf8

Single-transaction

Eof


Chown mysql:mysql/etc/my.cnf

chmod 400/etc/my.cnf


if [!-d/data/mysql/mysqldata3306/mydata/mysql]; then

mysql_install_db--defaults-file=/etc/my.cnf--user=mysql--datadir=/data/mysql/mysqldata3306/mydata-- Skip-name-resolve

Chkconfig mysqld on

Service mysqld Start

Mysqlstarted= "No"

While ["$mysqlstarted" = "No"]

Do

Sleep 1

If ["' Mysql-u root-n-n-s-r-e \" Select 1\ "'" = "1"]; then

Mysqlstarted= "Yes"

Fi

Done

Mysql-u root-n-E "delete from Mysql.user where user= ' or host not in (' localhost ', ' 127.0.0.1 ');d elete from MYSQL.DB;FL Ush privileges;create database skyeye;grant select,insert,update,delete on skyeye.* to ' SkyEye ' @ ' 127.0.0.1 ' identified by password ' *a6ec8fbfbbf786d565c09125bc6de94b18c99e05 ', Grant super,process,select on * * to ' skyeyemonitor ' @ ' 127.0.0.1 ' identified by password ' *8A91882A516AD0D2459D2F1400140C0A95D67C01 '; Grant SELECT on skyeye.* to ' skyeyebackup ' @ ' localhost ' identified by password ' * 001f19f6905729491f70765bb39900ea9284531e '; Grant Process on * * to ' skyeyebackup ' @ ' localhost ';

Else

Service mysqld Start

Fi


if [!-d/data/mysql/bin]; then

Mkdir-p/data/mysql/bin

Chown Mysql:mysql/data/mysql/bin

Fi


if [!-f/data/mysql/bin/skyeye_mysql_backup.sh]; then

CP skyeye_mysql_backup.sh/data/mysql/bin/skyeye_mysql_backup.sh

Chown mysql:mysql/data/mysql/bin/skyeye_mysql_backup.sh

chmod 100/data/mysql/bin/skyeye_mysql_backup.sh

echo "0 3 * * * root/data/mysql/bin/skyeye_mysql_backup.sh" >/etc/cron.d/skyeye_mysql

Service Crond Start

Chkconfig Crond on

Fi


if [!-d/data/mysql/backup]; then

Mkdir-p/data/mysql/backup

Chown Mysql:mysql/data/mysql/backup

Fi


650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/8E/11/wKioL1i04a_BlLEfAABuC9KAPFs246.png-wh_500x0-wm_ 3-wmp_4-s_1660364464.png "title=" Qq20170228103221.png "alt=" Wkiol1i04a_bllefaabuc9kapfs246.png-wh_50 "/>

Install files after they are downloaded and scripts are executed in the same directory

MySQL5.6 One-click installation script

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.