INSTALL_SQL_SHELL

#!/bin/bash


ping_baidu(){
    if ping -c 1 www.baidu.com >/dev/null; then
        echo 1
    else
        echo 0
    fi
}

ping_check_mysqlfile(){
    if ping -c 1 XX.XX.XX.XX > /dev/null; then
        echo 1
    else
        echo 0
    fi
}

ifuser(){
        num_user=`cat /etc/passwd | grep mysql | wc -l`
        if [ $num_user -ge 1 ]
         then
                echo "MYSQL用户已存在"
        else
                /usr/sbin/groupadd mysql
                /usr/sbin/useradd -g mysql -s /sbin/nologin mysql
        fi
}

ifworkdir(){
        if [ ! -d "/data/server" ]
         then
                mkdir -p /data
                cd /data
                wget http://XX.XX.XX.XX:8080/mysql5.6.tar.gz
        else
                cd /data
                wget http://XX.XX.XX.XX:8080/mysql5.6.tar.gz

        fi
}

install_package(){
        yum -y install gcc gcc-c++ make cmake autoconf automake ncurses-devel bison perl-Number-Format perl-Statistics-Descriptive perl-TermReadKey perl-DBD-MySQL perl-Statistics-Basic perl-Sys-Statistics-Linux perl perl-devel libaio libaio-devel perl-Time-HiRes  numactl.x86_64 libev.x86_64 perl-IO-Socket-SSL bc
}

write_sysctl(){
echo "
vm.min_free_kbytes = 409600
vm.vfs_cache_pressure = 200
vm.swappiness=10
kernel.sysrq = 1


net.core.rmem_max = 4194304
net.core.wmem_max = 2097152
net.core.wmem_default = 262144
net.core.rmem_default = 262144
kernel.shmmni = 4096
kernel.sem = 250 32000 100 142
#kernel.shmall = 2097152
#kernel.shmmax = 2147483648

fs.file-max = 6815744
fs.aio-max-nr = 1048576

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 9000 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

# for oracle
kernel.shmall = 4294967296               
kernel.shmmax = 68719476736
" >> /etc/sysctl.conf
sysctl -p
}


write_limit(){
echo "
* soft nofile 655360
* hard nofile 655360
* soft nproc 655360
* hard nproc 655360
* soft stack unlimited
* hard stack unlimited
" >> /etc/security/limits.conf


echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
echo never > /sys/kernel/mm/transparent_hugepage/enabled

echo "* soft nproc 65535" >> /etc/security/limits.d/90-nproc.conf
}


modify_mysql_conf(){
        last_addr=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:" | awk -F "." '{print $4}'`
        serverid=
}

install_mysql(){
        cd /data
        tar -xzvf mysql5.6.tar.gz
        cd /data/server
        mv mysql5.6 /usr/local/mysql
        chown -R mysql.mysql /data/server
        chmod -R 775 /data/server
        echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
        sed -i 's/read_only/#read_only/g' /data/server/my3306/conf/my3306.cnf
        source /etc/profile
        cd /usr/local/mysql
        /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/server/my3306/conf/my3306.cnf &
        sleep 20
        echo
        result="安装成功! 您的账户为root 密码为 xxxx 此账户只能限制在本地登陆, 如需要远程登陆,请自行创建!"
        echo $result
}

main(){
    ping_check=`ping_baidu`
    if [ $ping_check -eq 1 ]; then
        num_process=`ps -elf | grep mysqld | grep -v grep | wc -l`
        echo $num_process
        if [ $num_process -lt 2 ]
         then
            ping_check_mysqlfile_result=`ping_check_mysqlfile`
            if [ $ping_check_mysqlfile_result -eq 1 ]; then
                ifuser
                ifworkdir
                install_package
                write_sysctl
                write_limit
                install_mysql
            else
                echo "此主机无法连接mYSQL文件下载服务器,无法无成安装!!!"
            fi
        else
                echo "此主机已安装好MYSQL,无需重复安装!!!"
        fi
    else
        echo "此主机无法联网,因安装MySQL数据库时需要安装一些依赖包,因此必须联网,或者配置内部yum 源!!!"
    fi
}

main

  

posted @ 2019-01-07 22:20  SMALL-D  阅读(301)  评论(0编辑  收藏  举报