• Mysql 编译安装脚本


    cat mysql_init.sh
    ##安装mariadb依赖包
    function install_yum()
    {
      yum -y install $1
    }
    i="ncurses* bison gcc* screen make gcc-c++ cmake bison-devel ncurses-devel libaio libaio libaio-devel perl-Data-Dumper net-tools lvm2* unzip zlib-* mdadm libaio* bison* openssl* libcurl-devel libarchive-devel boost* kernel-headers kernel-devel pcre-devel"
    for j in $i
    do
      install_yum $j
    done
    echo "###################################finish yum install rpm package 10%"
    sleep 5
    ####软raid0
    m1=`ls /dev/* |grep md0`
    if [ ! -n "$m1" ]
    then
      ra=`ls /tmp/raiddir/*|awk -F'/' '{print $4}'|awk -F'.' 'BEGIN{ORS=" "}{print "/dev/"$1}'`
      rb=`ls /tmp/raiddir/*|wc -l`
      if [ $rb -eq 0 ]
      then
        echo "no init partition storage"
      else
        mdadm -C /dev/md0 -l raid0 -n $rb $ra
        mkfs.ext4 /dev/md0
        mdadm -E -s -v >> /etc/mdadm.conf
        mkdir /u02
        mount /dev/md0 /u02
        echo '/dev/md0 /u02 ext4 defaults 0 0'>>/etc/fstab
      fi
    else
      echo 'Md0 has been created'
    fi
    echo "###################################finish install raid0 15%"
    sleep 5
    ##新建mariadb安装包存放目录
    mkdir /u04/mysql -p
    find / -name mariadb-10.3.8.tar.gz > find.log
    oz=`cat find.log`
    chown root. $oz
    for oi in $oz
    do
      tar -vzxf $oi -C /u04/mysql
    done
    ox=`echo $?`
    if [ $ox -eq 0 ]
    then
      echo "###################################finish tar mysql soft 20%"
      sleep 5
    else
      echo "###################################Tar mysql soft is wrong!"
      exit
    fi
    ##新建mysql用户已经相关目录
    groupadd mysql
    useradd -r -g mysql mysql
    #mkdir /u02
    #mount /dev/md0 /u02
    mkdir /u02/mysql -p
    mkdir /u02/mysql/binlog
    mkdir /u02/mysql/undo
    mkdir /u02/mysql/tmp
    mkdir /u02/mysql/slowlog
    mkdir /u02/mysql/redo
    mkdir /u02/mysql/data
    mkdir /u02/mysql/sock
    mkdir /u02/mysql/error
    chown mysql. /u02/mysql -R
    echo "####################################25%"
    sleep 5
    ##编译mariadb
    cd /u04/mysql/mariadb-10.3.8
    cmake -DCMAKE_INSTALL_PREFIX=/u02/mysql/ -DMYSQL_DATADIR=/u02/mysql/data/ -DSYSCONFDIR=/etc -DMYSQL_UNIX_ADDR=/u02/mysql/sock/ -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=utf8mb4,utf8,gbk -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_unicode_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1
    a=`echo $?`
    if [ $a -eq 0 ]
    then
      echo ""
      echo "finish cmake##################################################30%"
      sleep 5
    else
      echo "cmake  wrong!"
      exit
    fi
    make -j 8
    b=`echo $?`
    if [ $b -eq 0 ]
    then
      echo ""
      echo "finish make##################################################40%"
      sleep 5
    else
      echo "make wrong!"
      exit
    fi
    make install
    c=`echo $?`
    if [ $c -eq 0 ]
    then
      echo ""
      echo "finishi make install##################################################60%"
      sleep 5
    else
      echo "make install wrong!"
      exit
    fi

    ##配置mariadb配置文件
    g=`free -g|grep Mem|awk '{print $2}'`
    h=$(($g*4/5))
    rm -rf /etc/my.cnf
    touch /etc/my.cnf
    echo "[mysql]
    default-character-set =utf8mb4
    [mysqld]
    basedir = /u02/mysql/
    datadir = /u02/mysql/data
    tmpdir =  /u02/mysql/tmp
    port = 3306
    socket = /u02/mysql/sock/mysql.sock
    character_set_server = utf8mb4
    max_user_connections=2980
    default-storage-engine=InnoDB
    partition
    lock_wait_timeout=900
    collation-server = utf8mb4_unicode_ci
    init_connect='SET NAMES utf8mb4'
    init_connect='SET collation_connection = utf8mb4_unicode_ci'
    skip-character-set-client-handshake
    lower_case_table_names=1
    default-time-zone="+8:00"
    join_buffer_size=128K
    sort_buffer_size=8m
    table_open_cache=1024
    table_definition_cache=1024
    query_cache_type=0
    query_cache_size=0
    query_cache_limit=0
    back_log=300
    thread_cache_size=512
    max_connections=3000
    tmp_table_size=128m  #for mairadb
    max_heap_table_size=128m #for mairadb
    skip-name-resolve
    net_buffer_length=8k
    max_allowed_packet=1g
    connect_timeout=10
    wait_timeout=120
    interactive_timeout=120
    net_read_timeout=3 #set to 10 if across IDC
    net_write_timeout=6 #set to 10 if across IDC
    net_retry_count=2 #set to 5 if across IDC
    log-error=/u02/mysql/error/error3306.log
    skip-log-warnings
    slow-query-log
    slow_query_log_file=/u02/mysql/slowlog/slow3306.log
    log_slow_verbosity='Query_plan,Innodb'  #for mariadb
    innodb_log_group_home_dir=/u02/mysql/redo
    innodb_log_files_in_group=4
    innodb_log_file_size=256M
    innodb_open_files=4096
    innodb_change_buffering=inserts
    innodb_adaptive_hash_index=ON
    innodb_autoinc_lock_mode=2
    innodb_buffer_pool_size="$h"G
    innodb_buffer_pool_instances=4
    innodb_max_dirty_pages_pct=50
    innodb_old_blocks_pct=25
    innodb_old_blocks_time=3000
    innodb_log_buffer_size=50m
    innodb_flush_method=O_DIRECT
    innodb_use_native_aio
    innodb_adaptive_flushing
    innodb_flush_log_at_trx_commit=1
    innodb_io_capacity=20000
    innodb_read_io_threads=4
    innodb_write_io_threads=4
    innodb_read_ahead_threshold=56
    innodb_purge_threads=1
    innodb_purge_batch_size=20
    innodb_file_per_table
    innodb_autoextend_increment=32
    innodb_stats_on_metadata=0  #for mariadb
    innodb_stats_sample_pages=32
    innodb_stats_method=nulls_unequal
    innodb_fast_shutdown=1
    autocommit=1
    transaction-isolation=READ-COMMITTED #for mariadb
    completion_type=NO_CHAIN
    #innodb_support_xa
    innodb_table_locks
    innodb_lock_wait_timeout=900
    innodb_spin_wait_delay=6
    innodb_sync_spin_loops=30
    innodb_commit_concurrency=0
    innodb_thread_concurrency=32       #at least equal cpu nums
    #server-id=1
    #log_bin=/u02/mysql/binlog/master
    #sync_binlog=1
    #innodb_flush_log_at_trx_commit=1
    #log_bin_trust_function_creators=1
    #expire_logs_days = 1
    #binlog_format=ROW
    " >/etc/my.cnf
    echo "finish mysql /etc/my.cnf##################################################70%"
    sleep 5
    ##初始化mariadb
    cd /u04/mysql/mariadb-10.3.8/scripts
    ./mysql_install_db --user=mysql --basedir=/u02/mysql --datadir=/u02/mysql/data
    sleep 120
    echo $'03'
    cd /u02
    chown mysql. mysql/ -R
    echo "finish mysql init##################################################80%"
    sleep 5

    ##开启mariadb
    cd /u04/mysql/mariadb-10.3.8
    cp support-files/mysql.server /etc/init.d/mysqld
    chmod 755 /etc/init.d/mysqld
    chkconfig mysqld on
    nohup /etc/init.d/mysqld start >/dev/null 2>&1 &
    sleep  30
    echo "finish mysql start##################################################90%"
    sleep 5
    ##配置变量以及配置root用户密码
    ln -s /u02/mysql/bin/mysql /usr/bin/mysql
    ln -s /u02/mysql/bin/mysqldump /usr/bin/mysqldump
    /u02/mysql/bin/mysqladmin  -u root -h 127.0.0.1 password 'oracletest'
    echo "finish mysql install ok##################################################100%"
    sleep 5
    ##配置主从用户
    #################################################################flyway init
    mysql -uroot -poracletest -h127.0.0.1 -e "create database dbadmin"
    mysql -uroot -poracletest -h127.0.0.1 -e "grant all on *.* to dbadmin@'127.0.0.1' identified by 'dbadmin'"
    ###############################################
    #backup
    mkdir /u03/mysql/backup -p
    mkdir /u01/dba_scripts/mysqldump -p
    mkdir /u01/dba_scripts/mysql_add_partition -p
    mv /tmp/mysqlbackup.sh /u01/dba_scripts/mysqldump
    mv /tmp/mysql_add_partition_tables.sh /u01/dba_scripts/mysql_add_partition
    cat /tmp/mysql_crontab.txt >> /var/spool/cron/root
    echo "#################################finish shell"
    ###############################################
    yum -y install java
    mkdir -p  /u10/flyway_mysql
    unzip     /tmp/flyway-commandline-4.2.0-windows-x64.zip -d /u10/flyway_mysql
    flyway_home=/u10/flyway_mysql/flyway-4.2.0/
    flyway_conf=/u10/flyway_mysql/flyway-4.2.0/conf/flyway.conf
    flyway_sql=/u10/flyway_mysql/flyway-4.2.0/sql/db/migration
    flyway_drivers=/u10/flyway_mysql/flyway-4.2.0/drivers
    #cp        /tmp/ojdbc6.jar  $flyway_drivers
    ln -s /u10/flyway_mysql/flyway-4.2.0/flyway /usr/bin/flyway_mysql
    #a=`who|awk '{print $1}'`
    #cd
    echo "alias flymysql='cd /u10/flyway_mysql/flyway-4.2.0'" >>/etc/profile
    source /etc/profile
    ####$flyway_home/.flyway migrate
    ####Sql?..?½å§..ï####V3_1__20170921_1.sql
    #ip_dir=`ifconfig |grep inet|grep -v '127.0.0.1'|awk '{print $2}'|sed -n '1p'`
    echo "
    flyway.url=jdbc:mariadb://127.0.0.1:3306/dbadmin
    flyway.user=dbadmin
    flyway.password=dbadmin
    flyway.schemas=dbadmin
    flyway.table=schema_version
    flyway.baselineOnMigrate=true" >> $flyway_conf
    cd /u10/flyway_mysql/flyway-4.2.0
    chmod 777 sql
    flyway_mysql  migrate
    echo "#################################finish flyway install"
  • 相关阅读:
    [置顶] RGB颜色查询对照表
    3.3FactoryMethod——工厂方法
    从零开始学C++之数据封装与抽象:分别用C和C++来实现一个链栈
    C# 自定义事件
    Qt4--加密日记本(子例化QMainWindow文本加密解密)
    SharePoint PerformancePoint Service-PowerShell
    Windows下安装Eric5时出现的“Sorry, please install QtHelp.”问题解决办法
    Char* ,CString ,WCHAR*之间的转换
    [C++基础]关键词volatile
    备忘--简单比较SPSS、RapidMiner、KNIME以及Kettle四款数据分析工具
  • 原文地址:https://www.cnblogs.com/xibuhaohao/p/10748589.html
Copyright © 2020-2023  润新知