此腳本儘可能運行在centos 服務器上面,用於編譯安裝mysql 5.7 mysql
將此腳本和相應的軟件 都放到/usr/local/src 目錄下面c++
因爲不能上傳附件 因此須要把cmake-3.9.6.tar.gz ,boost_1_59_0.tar.gz,mysql-5.7.22.tar.gz 先下載好。sql
#####編譯安裝mysql5.7
#####此腳本的做用在於自動化安裝mysql5.7 爲並行複製(基於組提交), mysql5.7 自動化failover ,和archer 工單審覈作準備
#####version mysql5.7.22
####下載msyql https://downloads.mysql.com/archives/community/mysql-5.7.22.tar.gz
###先將腳本 壓縮本上傳到服務器/usr/local/src/目錄下 這是我習慣用的統一目錄數據庫
####安裝必要的依賴包
yum -y install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl make openssl-develbootstrap
####安裝cmake 去這裏面下載分爲源碼版和編譯好的版本https://cmake.org/download/
####添加用戶 建立目錄
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
mkdir /data/mysql/3306/{data,log,tmp,mysql-bin,relay-bin,redo-log,undo-log} -p
chown mysql.mysql /data/mysql -R
chmod 755 /data/mysql -R
#安裝cmake
cd /usr/local/src
tar -xvzf cmake-3.9.6.tar.gz
cd /usr/local/src/cmake-3.9.6/
./bootstrap
sleep 10
gmake
make install
cd ..
#安裝boost mysql5.7依賴
tar -xvzf boost_1_59_0.tar.gz -C /data/mysql/
######安裝mysql5.7
tar -xvzf mysql-5.7.22.tar.gz
cd mysql-5.7.22
#指定boost的位置 -DWITH_BOOST=/data/mysql/boost_1_59_0
/usr/local/src/cmake-3.9.6/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/3306/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/mysql/boost_1_59_0 -DSYSCONFDIR=/etc/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DMYSQL_TCP_PORT=3306;centos
make -j `grep processor /proc/cpuinfo | wc -l` #編譯時會消耗很大內存,小內存可能沒法編譯完成
make install
cd /usr/local/src/
rm -rf *.tar.gz
rm -rf mysql-5.7.22
####添加環境變量
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source /etc/profilebash
cat > /usr/local/mysql/my.cnf <<"EOF"
[client]服務器
port = 3306
socket = /data/mysql/3306/tmp/mysql.socketsocket
[mysqld]ui
server-id = 100
port = 3306
basedir=/usr/local/mysql
datadir=/data/mysql/3306/data
tmpdir = /tmp
socket = /data/mysql/3306/tmp/mysql.socket
skip-external-locking
skip_name_resolve = 1
transaction_isolation = REPEATABLE-READ
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
lower_case_table_names = 1
max_connections = 8000
max_connect_errors = 8000
explicit_defaults_for_timestamp = 1
max_allowed_packet = 256M
interactive_timeout = 1800
wait_timeout = 1800
tmp_table_size = 128M
max_heap_table_size = 128M
query_cache_size = 0
query_cache_type = 0
read_buffer_size = 1M
read_rnd_buffer_size = 2M
secure-file-priv = "/"
binlog_cache_size = 8M
join_buffer_size = 128M
back_log = 600
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
#######log set#############
log_error = /data/mysql/3306/log/mysql.err
slow_query_log = 1
slow_query_log_file = /data/mysql/3306/log/slow.log
log_queries_not_using_indexes = 1
long_query_time = 2
expire_logs_days = 7
log-bin=/data/mysql/3306/mysql-bin/mysql-bin
binlog_format = ROW
binlog_row_image = minimal
relay_log = /data/mysql/3306/relay-bin/relay-bin
####用戶從庫級聯複製
log_slave_updates
####relay_log_recovery = 1 ##從庫參數
slave_skip_errors = 1062
######刷盤方式#########
innodb_flush_log_at_trx_commit = 2
sync_binlog = 0
#########Innodb設置##########
innodb_buffer_pool_size = 512M
innodb_buffer_pool_instances = 8
#innodb_log_buffer_size = 16777216
innodb_flush_method = O_DIRECT
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_lock_wait_timeout = 60
innodb_log_group_home_dir = /data/mysql/3306/redo-log/
innodb_undo_directory = /data/mysql/3306/undo-log/
innodb_log_files_in_group = 3
innodb_log_file_size = 1G #線上改爲4G
innodb_undo_log_truncate = 1
#innodb_undo_tablespaces = 1#線上改爲3
innodb_undo_logs = 128
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
######gtid#######
gtid_mode = on
enforce_gtid_consistency = 1
######並行複製參數從庫須要開啓###########
#slave-parallel-type=LOGICAL_CLOCK
#slave-parallel-workers=16
master_info_repository=TABLE
relay_log_info_repository=TABLE
#relay_log_recovery=ON
replicate-wild-ignore-table = mysql.%
replicate-wild-ignore-table = test.%
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqld_safe]
#增長每一個進程的可打開文件數量.
open-files-limit = 28192
[mysqld-5.7]
innodb_buffer_pool_dump_pct = 40
innodb_page_cleaners = 4
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 2G
innodb_purge_rseg_truncate_frequency = 128
binlog_gtid_simple_recovery=1
log_timestamps=system
transaction_write_set_extraction=MURMUR32
show_compatibility_56=on
EOF
touch /data/mysql/3306/log/mysql.err
chown mysql.mysql /data/mysql/3306/log/mysql.err
####初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data/ --explicit_defaults_for_timestamp
#####啓動mysql
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
sleep 300
######修改數據庫密碼
#/usr/local/mysql/bin/mysqladmin -u root -p -S /data/mysql/3306/tmp/mysql.socket password "abc123"
/usr/local/mysql/bin/mysql --port=3306 -S /data/mysql/3306/tmp/mysql.socket -BNe "update mysql.user set authentication_string=password('abc123') where user='root';flush privileges;"
####配置快捷登錄方式
cat >/usr/local/local.cnf <<EOF
[client]
host=localhost
port=3306
user=root
password=abc123
socket=/data/mysql/3306/tmp/mysql.socket
EOF
cat >>/root/.bashrc <<EOF
alias mysql.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &'
alias mysql.login='/usr/local/mysql/bin/mysql --defaults-file=/usr/local/local.cnf'
alias mysql.stop='/usr/local/mysql/bin/mysqladmin --port=3306 -uroot -p'abc123' -S /data/mysql/3306/tmp/mysql.socket shutdown'
EOF
source /root/.bashrcsource /root/.bash_profile cat >>/etc/rc.local <<EOFalias mysql.3310.start='/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &'alias mysql.3310.login='/usr/local/mysql/bin/mysql --defaults-file=/usr/local/local.cnf'alias mysql.3310.stop='/usr/local/mysql/bin/mysqladmin --port=3310 -uroot -p'Pass@word' -S /data/mysql/3310/tmp/mysql.socket shutdown'EOFsource /root/.bashrcecho "Please execute:source /root/.bash_profile"