疾速完成MySQL的安排和一機多實例安排。本站提示廣大學習愛好者:(疾速完成MySQL的安排和一機多實例安排)文章只能為提供參考,不一定能成為您想要的結果。以下是疾速完成MySQL的安排和一機多實例安排正文
MySQL有三個版本:二進制,源碼包,RPM。
上面講講二進制包的裝置進程
下載地址:http://dev.mysql.com/downloads/mysql/
選擇Linux-Generic
我這裡選擇的是mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
解壓後,外面有個文件INSTALL-BINARY,其實給出了二進制包的安排進程
shell> groupadd mysql shell> useradd -r -g mysql -s /bin/false mysql shell> cd /usr/local shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> chown -R mysql . shell> chgrp -R mysql . shell> scripts/mysql_install_db --user=mysql shell> chown -R root . shell> chown -R mysql data shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server
絕對於現實臨盆情況的安排,下面在初始化數據庫的進程中少了一步-即指定設置裝備擺設文件,假如設置裝備擺設文件確認了,數據目次,日記目次都確認了,MySQL二進制版本的安排照樣相當輕易的一件工作。
上面寫了一個劇本,基於前面供給的設置裝備擺設文件,履行格局以下:
sh 4.sh /root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz /mysql3306 3306
個中 4.sh是劇本,/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz是二進制包的相對途徑,/mysql3306是basedir,3306是需設置的端口,
應用該劇本,只須要事後界說好設置裝備擺設文件,便可停止MySQL數據庫的疾速安排和一台辦事器上多個實例的安排。
#!/bin/bash #需傳入三個參數,第一個是mysql二進制緊縮包的途徑(相對途徑),比方/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz, #第二個是mysql的basedir,即須要創立在哪一個目次下,第三個是設置的端標語 filename=$1 basedir=$2 port=$3 groupadd mysql useradd -r -g mysql -s /bin/false mysql cd /usr/local tar zxvf $filename #file是獲得mysql二進制包的稱號,比方mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz #dir是mysql緊縮包的途徑,不含包名自己,比方/root,由於後續的設置裝備擺設文件my.cnf也是放到這個途徑下 file=`basename $filename` dir=`dirname $filename` #獲得解壓後的名字,即mysql-5.6.28-linux-glibc2.5-x86_64 after_tar_file=${file:0:-7} #將二進制包更名為 mysql+端標語,如許也便於後續的辨別 mv $after_tar_file mysql"$port" cd mysql"$port" #將原始的設置裝備擺設文件(需和mysql緊縮包放到同層目次下,在本例中是/root/my.cnf)copy到解壓並更名後的mysql二進制目次下,修正為my+端標語.cnf cp $dir/my.cnf ./my"$port".cnf user_cnf=my"$port".cnf #上面重要是將原始設置裝備擺設文件中的途徑修正為本身設定的途徑,即傳入的第二個參數 #全部的挑釁在於傳入的途徑帶有"/",在sed調換時會有成績,一切用了一個取巧的思緒,即先將"/"調換為"|",停止sed調換,然後再將文件中的"|"修正回"/" basedir_new=${basedir/\//|} sed -i "s/\/project\/class2/$basedir_new/g" $user_cnf sed -i "s/|/\//g" $user_cnf #設置server_id,取以後的秒值 server_id=`date +%s` sed -i /^server_id/s/.*/server_id="$server_id"/ $user_cnf #設置端標語 sed -i /^port/s/.*/port="$port"/ $user_cnf #創立需要的目次並修正權限 mkdir -p "$basedir"/mysql/{run,data,share,log,tmp} chown -R mysql $basedir chgrp -R mysql $basedir #上面這個長短需要的,詳細看前面的總結 cp share/english/errmsg.sys "$basedir"/mysql/share/ #初始化時--force也長短需要的,詳細可見前面的總結 scripts/mysql_install_db --user=mysql --defaults-file="$user_cnf" --force bin/mysqld_safe --defaults-file="$user_cnf" --user=mysql &
上面給出了設置裝備擺設文件的一個參考,年夜家可依據現實情形停止響應的修正
[mysqld_safe] pid-file=/project/class2/mysql/run/mysqld.pid [mysql] port=3306 prompt=\\u@\\d \\r:\\m:\\s> default-character-set=utf8 no-auto-rehash [client] port=3306 socket=/project/class2/mysql/run/mysql.sock [mysqld] #dir basedir=/project/class2/mysql datadir=/project/class2/mysql/data tmpdir=/tmp lc_messages_dir=/project/class2/mysql/share log-error=/project/class2/mysql/log/alert.log slow_query_log_file=/project/class2/mysql/log/slow.log general_log_file=/project/class2/mysql/log/general.log socket=/project/class2/mysql/run/mysql.sock #innodb innodb_data_home_dir=/project/class2/mysql/data innodb_log_group_home_dir=/project/class2/mysql/data innodb_data_file_path=ibdata1:2G;ibdata2:16M:autoextend innodb_buffer_pool_size=10G innodb_buffer_pool_instances=4 innodb_log_files_in_group=2 innodb_log_file_size=1G innodb_log_buffer_size=200M innodb_flush_log_at_trx_commit=1 innodb_additional_mem_pool_size=20M innodb_max_dirty_pages_pct=60 innodb_io_capacity=1000 innodb_thread_concurrency=16 innodb_read_io_threads=8 innodb_write_io_threads=8 innodb_open_files=60000 innodb_file_format=Barracuda innodb_file_per_table=1 innodb_flush_method=O_DIRECT innodb_change_buffering=inserts innodb_adaptive_flushing=1 innodb_old_blocks_time=1000 innodb_stats_on_metadata=0 innodb_read_ahead=0 innodb_use_native_aio=0 innodb_lock_wait_timeout=5 innodb_rollback_on_timeout=0 innodb_purge_threads=1 innodb_strict_mode=1 transaction-isolation=READ-COMMITTED #myisam key_buffer=64M myisam_sort_buffer_size=64M concurrent_insert=2 delayed_insert_timeout=300 #replication master-info-file=/project/class2/mysql/log/master.info relay-log=/project/class2/mysql/log/relaylog relay_log_info_file=/project/class2/mysql/log/relay-log.info relay-log-index=/project/class2/mysql/log/mysqld-relay-bin.index slave_load_tmpdir=/project/class2/mysql/tmp slave_type_conversions="ALL_NON_LOSSY" slave_net_timeout=4 skip-slave-start sync_master_info=1000 sync_relay_log_info=1000 #binlog log-bin=/project/class2/mysql/log/mysql-bin server_id=2552763370 binlog_cache_size=32K max_binlog_cache_size=2G max_binlog_size=500M binlog-format=ROW sync_binlog=1000 log-slave-updates=1 expire_logs_days=0 #server default-storage-engine=INNODB character-set-server=utf8 lower_case_table_names=1 skip-external-locking open_files_limit=65536 safe-user-create local-infile=1 #sqlmod="STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE" log_slow_admin_statements=1 log_warnings=1 long_query_time=1 slow_query_log=1 general_log=0 query_cache_type=0 query_cache_limit=1M query_cache_min_res_unit=1K table_definition_cache=65536 thread_stack=512K thread_cache_size=256 read_rnd_buffer_size=128K sort_buffer_size=256K join_buffer_size=128K read_buffer_size=128K port=3306 skip-name-resolve skip-ssl max_connections=4500 max_user_connections=4000 max_connect_errors=65536 max_allowed_packet=128M connect_timeout=8 net_read_timeout=30 net_write_timeout=60 back_log=1024
總結:
在初始化的進程中,假如報以下毛病:
FATAL ERROR: Neither host 'keepalived02' nor 'localhost' could be looked up with /mysql3306/mysql/bin/resolveip Please configure the 'hostname' command to return a correct hostname. If you want to solve this at a later stage, restart this script with the --force option
然則在bash終端上履行hostname敕令又確切有值前往,可加--force參數,以下所示:
scripts/mysql_install_db --user=mysql --defaults-file="$user_cnf" --force
假如報以下毛病:
[ERROR] Can't find messagefile '/mysql3306/mysql/share/errmsg.sys'
可將二進制版本中share/english/errmsg.sys文件COPY到/mysql3306/mysql/share/下。
後續:這兩個毛病的緣由都是由於basedir修正了,它默許是在二進制包中查找的。
若何應用劇本完成MySQL的疾速安排和一機多實例的安排,經由過程這篇文章願望對年夜家進修MySQL的安排有所贊助。