• MySQL5.6一键部署


    
    

    # 快速部署单节点MySQL脚本
    # 执行方式:将MySQL包,my3302.cnf配置文件,dbtool脚本文件放到一个目录下。然后按照脚本执行就可以。配置文件提前修改好。文章最后附上my.cnf配置文件内容

    # 环境:

    # Linux:CentOS release 6.6 (Final)
    # mysql: Percona-Server-5.6.32-rel78.0-Linux.x86_64.ssl098e.tar.gz # 下载地址 : https://www.percona.com/downloads/Percona-Server-5.6/LATEST/

    # 简介:脚本中每一步都定义的函数,通过:./dbtool port cmd 格式 来调用。port:MySQL端口;cmd 每个函数的调用命令简写。例如:./dbtool 3002 sd 启动mysql.
    #   大家可以根据需要在下面追加函数,定义功能。比如:mysql的启动、停止、登录。
    #   该脚本提供一种思路,大家可以自己扩展


    # 脚本名:dbtool
    #!/bin/sh
    # 
    PORT=$1
    Instance_Name="inst01"    #实例名:多实例时目录层的区分标志
    CMD="$2"
    DB_DIR="/data/mysql"    # MySQL相关目录文件,本脚本为了方便都放一起了;data和log可以放到单独的分区里
    Current_dir=`pwd`        
    
    INSTALL_RPM()
    {
        rpmlist="openssl-devel.x86_64 
            openssl098e.x86_64 
            openssl.x86_64 
            readline.x86_64 
            readline-devel.x86_64 
            crypto-utils.x86_64 
            perl-DBD-MySQL.x86_64 
            perl-IO-Socket-SSL.noarch"
        echo
        echo '------------------------------------------'
        echo 'Install rpm :'
        echo 
        for str in ${rpmlist};
        do
            rpm -qa|grep ${str%.*}>>/dev/null && echo "Installed : "${str} || 
        (yum install -y ${str} >> /dev/null && echo "Installed : "${str} )
    done
        echo
        echo '------------------------------------------'
        echo 
    }
    
    ADD_USER()
    {
        echo 
        echo '------------------------------------------' 
        groupadd mysql && useradd -g mysql mysql >/dev/null
        echo "id mysql :"
        id mysql
        echo '------------------------------------------' 
    }
    
    MK_DIR()
    {
        Dir_data="${DB_DIR}/mysqlData/${Instance_Name}"
        Dir_log="${DB_DIR}/mysqlLog/${Instance_Name}"
        Dir_socket="${DB_DIR}/socket"
        Dir_conf="${DB_DIR}/config"
        echo '--------------------------------------------'
        if [ ! -d "${DB_DIR}" ];then
            mkdir -pv ${DB_DIR}
        fi
    
        mkdir -pv $Dir_data/{data,tmp} 
        mkdir -pv $Dir_log/logs
        mkdir -pv $Dir_socket
        mkdir -pv $Dir_conf
        echo 
        echo '[ show dirs : ]'
        ls -lh ${DB_DIR}
        echo '---------------------------------------------------------'
        echo 
    }
    
    TAR_MYSQL()
    {
        echo '---------------------------------------------------------'
        PerconaName=`ls ${Current_dir} |grep Percona-Server`
        PerconaVerson=`echo ${PerconaName}|awk -F'-' '{print $3}'|sed 's#.##g'`
        tar -xf ${PerconaName}
        mv ${PerconaName%.tar*} percona${PerconaVerson}
        ln -s ${Current_dir}/percona${PerconaVerson} /usr/local/mysql
        echo '---------------------------------------------------------'
    }
    
    MOD_CONF()
    {
        echo '---------------------------------------------------------'
        mv ${Current_dir}/my${PORT}.cnf ${DB_DIR}/config/
        ls -lh ${DB_DIR}/config/
        echo '---------------------------------------------------------'
    }
    
    GRANT_DIR()
    {
        echo '---------------------------------------------------------'
        chown -R mysql.mysql ${DB_DIR}
        chown -R mysql.mysql /usr/local/mysql
        chown -R mysql.mysql /usr/local/mysql/
        echo '---------------------------------------------------------'
    }
    
    SET_PATH()
    {
        echo
        echo '---------------------------------------------------------'
        echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile 
        cat /etc/profile|grep '/usr/local/mysql/bin'
        echo
        echo '---------------------------------------------------------'
    }
    
    INITIALIZE_DB()
    {
        echo
        echo '---------------------------------------------------------'
        cd /usr/local/mysql/
        ./scripts/mysql_install_db --defaults-file=${DB_DIR}/config/my${PORT}.cnf --user=mysql
        echo '---------------------------------------------------------'
    }
    
    START_DB()
    {
        echo '---------------------------------------------------------'
        cd /usr/local/mysql
        ./bin/mysqld_safe --defaults-file=${DB_DIR}/config/my${PORT}.cnf --user=mysql &
        sleep 5
        echo 
        echo "Check :"
        echo "[ps -ef|grep mysql]"
        ps -ef|grep mysql
        echo "[netstat -ntpl|grep mysql]"
        netstat -ntpl|grep mysql
        
        echo '---------------------------------------------------------'
    }
    
    FIRST_LOGIN()
    {
    echo '---------------------------------------------------------'
        echo "Press Enter"
        mysql -uroot -p -S ${DB_DIR}/socket/mysql${PORT}.sock -e"delete from mysql.user where host !='localhost' or user=''"
        echo "Press Enter"
        mysql -uroot -p -S ${DB_DIR}/socket/mysql${PORT}.sock -e"select user,host,password from mysql.user"
        echo
        echo 
    echo '---------------------------------------------------------'
    }
    
    HELP()
    {
    echo "---------------------------------------------------------------"
    printf "%-50s
    " "+ ToolName : dbtool "
    printf "%-50s
    " "+ ToolDesc : install single mysql"
    printf "%-50s
    " "+ Authors : Chris"
    
    printf "%-50s
    " "+ Help:"
    printf "%-50s
    " "For example:"
    printf "%-50s
    " "+ [root@monitor data]# ./dbtool 3002 in"
    
    printf "%-50s
    " "+ Parameter: "
    printf "%-50s
    " "+ ir    --install rpm for mysql"
    printf "%-50s
    " "+ au    --add user : mysql "
    printf "%-50s
    " "+ md    --mkdir " 
    printf "%-50s
    " "+ tm    --tar -xf mysql.xx.tar.gz"
    printf "%-50s
    " "+ mc    --mv myxx.cnf to config_file"
    printf "%-50s
    " "+ gd    --grant to dirs"
    printf "%-50s
    " "+ sp    --set environment"
    printf "%-50s
    " "+ in    --initialization mysql"
    printf "%-50s
    " "+ sd    --start mysql"
    printf "%-50s
    " "+ fg    --first login mysql and delete unuserd users"
    echo "---------------------------------------------------------------"
    
     
    }
    
    if [ $# -eq 2 ];then
        case $2 in
        'install_rpm'|'ir')  
        INSTALL_RPM
        ;;
        'add_user'|'au')
        ADD_USER
        ;;
        'mk_dir'|'md') 
        MK_DIR
        ;;
        'tar_mysql'|'tm')
        TAR_MYSQL
        ;;
        'mv_conf'|'mc')
        MOD_CONF
        ;;
        'grant_dir'|'gd')
        GRANT_DIR
        ;;
        'set_path'|'sp')
        SET_PATH
        ;;
        'initialization_db'|'in')
        INITIALIZE_DB
        ;;
        'start_db'|'sd')
        START_DB
        ;;
        'firstlogin'|'fg')
        FIRST_LOGIN
        ;;
        'install'|'install')    # 一键部署
        INSTALL_RPM
        ADD_USER
        MK_DIR
        TAR_MYSQL
        MOD_CONF
        GRANT_DIR
        SET_PATH
        INITIALIZE_DB
        START_DB
        FIRST_LOGIN
        ;;
        *) 
        HELP
        ;;
        esac
    else
        HELP
        exit
    fi

    附件:myxx.cnf 

    注意:innodb_buffer_pool需要更加实际内存情况设置

    [client]
    port            = 3002
    socket          = /data/socket/mysql3002.sock
    
    
    # The MySQL server
    [mysqld]
    server-id       = 8 
    port            = 3002
    user            = mysql
    basedir         = /usr/local/mysql
    datadir         = /data/mysql/mysqlData/inst01/data
    tmpdir          = /data/mysql/mysqlData/inst01/tmp
    socket          = /data/mysql/socket/mysql3002.sock
    pid-file        = /data/mysql/socket/mysql3002.pid
    log-bin         = /data/mysql/mysqlLog/inst01/logs/mysql-bin
    log-error       = /data/mysql/mysqlLog/inst01/err.log
    slow_query_log_file =/data/mysql/mysqlLog/inst01/slow.log
    binlog_format=mixed
    #log_short_format
    #log-slave-updates
    slow_query_log
    long_query_time=1 
    wait_timeout=100
    interactive_timeout=100
    max_connections=1024
    character_set_server=utf8
    skip-external-locking
    key_buffer_size = 384M
    max_allowed_packet = 1M
    table_open_cache = 512
    sort_buffer_size = 2M
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size = 32M
    # Try number of CPU's*2 for thread_concurrency
    thread_concurrency = 8
    #skip-networking
    binlog-ignore-db=mysql
    binlog-ignore-db=information_schema
    replicate_ignore_db=mysql
    replicate_ignore_db=information_schema
    expire-logs-days=15
    skip-slave-start
    
    # InnoDB
    innodb_data_home_dir = /data/mysql/mysqlData/inst01/data
    innodb_log_group_home_dir = /data/mysql/mysqlLog/inst01/logs
    innodb_data_file_path = ibdata1:10M:autoextend
    innodb_buffer_pool_size = 256M
    innodb_additional_mem_pool_size = 5M
    innodb_log_file_size = 10M
    innodb_log_buffer_size = 8M
    innodb_flush_log_at_trx_commit = 0
    innodb_lock_wait_timeout = 50
    innodb_file_per_table
    
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [mysql]
    #no-auto-rehash
    auto-rehash
    [myisamchk]
    key_buffer_size = 256K
    sort_buffer_size = 256K
    read_buffer = 256K
    write_buffer = 256K
    
    [mysqlhotcopy]
    interactive-timeout
  • 相关阅读:
    洛谷 P2053 :[SCOI2007]修车(拆点+最小费用流)
    LightOJ
    spark简单入门
    crontab 应用
    HttpClient的使用
    build.sbt的定义格式
    Scalatra
    SBT 构建scala eclipse开发
    mysql 存在更新,不存在插入
    Flash Vector例子
  • 原文地址:https://www.cnblogs.com/cuisi/p/7059117.html
Copyright © 2020-2023  润新知