您好,登錄后才能下訂單哦!
Centos6.6安裝并配置單機(jī)多實(shí)例的MYSQL數(shù)據(jù)庫
本文介紹安裝單機(jī)多實(shí)例的MYSQL數(shù)據(jù)庫的環(huán)境如下:
系統(tǒng)平臺(tái)環(huán)境:Centos6.6
Mysql軟件包:Mysql-5.5.32.tar.gz
一:安裝MYSQL需要的依賴包和編譯軟件
#yum install ncurses-devel libaio-devel -y
二:安裝編譯MYSQL需要的軟件(mysql5.2版本以后都需要使用cmake來編譯安裝MYSQL)
#rpm -ivh cmake-2.8.12.2-4.el6.x86_64(光盤中會(huì)自帶,也可自行編譯安裝)
如果是自行編譯安裝cmake可以#which cmake查看到全路徑,以便后面編譯安裝MYSQL
三:開始安裝MYSQL數(shù)據(jù)庫
1:創(chuàng)建mysql用戶賬號(hào)
# useradd -s /sbin/nologin -M mysql && id mysql
2: 獲取MYSQL的源代碼包(如連接失效可自行找到相應(yīng)鏈接)
# wget http://dev.mysql.com/downloads/mysql
3:采用編譯方式安裝MYSQL
# tar xf mysql-5.5.32.tar.gz
# cd mysql-5.5.32
# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32
-DMYSQL_DATADIR=/application/mysql-5.5.32/data
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii
-DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1
-DWITH_FAST_MUTEXES=1
-DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1
-DWITH_READLINE=1
-DWITH_EMBEDDED_SERVER=1
-DWITH_DEBUG=0
# make && make install
# ln -s /application/mysql-5.5.32/ /application/mysql
至此MYSQL-5.5.32的源代碼包采用cmake方式安裝就算成功了??!
既然是配置安裝單機(jī)多實(shí)例數(shù)據(jù)庫,那么我們接下來要做的就是為每個(gè)實(shí)例創(chuàng)建必須的 數(shù)據(jù)文件,配置文件.以及啟動(dòng)文件。
四:實(shí)例創(chuàng)建必須的數(shù)據(jù)文件,配置文件.以及啟動(dòng)文件。
1:為每個(gè)實(shí)例創(chuàng)建數(shù)據(jù)目錄
#mkdir -p /data/{3306,3307}/data
2:為每個(gè)實(shí)例創(chuàng)建配置文件(ls -l /application/mysql/suport-files/my*.cnf 數(shù)據(jù)庫默認(rèn)提供的多個(gè) 配置文件模板,用戶可根據(jù)服務(wù)器硬件配置選擇相應(yīng)的模板)
#vim /data/3306/my.cnf (配置實(shí)例如下 #為注釋行)
[client] port = 3306 socket = /data/3306/mysql.sock [mysql] no-auto-rehash [mysqld] port = 3306 user = mysql socket = /data/3306/mysql.sock basedir = /application/mysql datadir = /data/3306/data back_log = 100 max_connections = 800 max_connect_errors = 100 table_open_cache = 2048 external-locking = FALSE binlog_cache_size = 1M max_heap_table_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 2M sort_buffer_size = 2M join_buffer_size = 1M thread_cache_size = 100 thread_concurrency = 8 query_cache_size = 2M query_cache_limit = 2M #ft_min_word_len = 4 #default-storage-engine = InnoDB thread_stack = 192K #transaction_isolation = REPEATABLE-READ tmp_table_size = 2M #binlog_format=mixed #slow_query_log long_query_time = 2 pid-file = /data/3306/mysqld.pid relay-log = /data/3306/relay-bin relay-log-info-file = /data/3306/relay-log.info max_binlog_cache_size = 1M max_binlog_size = 2M key_buffer_size =16M read_buffer_size = 1M read_rnd_buffer_size = 1M lower_case_table_names = 1 skip-name-resolve slave-skip-errors =1032,1062 replicate-ignore-db = mysql bulk_insert_buffer_size = 1M server-id = 1 #log-bin = /data/3306/logbin/mysql-bin #log-bin-index = /data/3306/logbin/log-bin.index #myisam_sort_buffer_size = 128M #myisam_max_sort_file_size = 10G #myisam_repair_threads = 1 #myisam_recover #skip-innodb innodb_additional_mem_pool_size = 16M innodb_buffer_pool_size = 32M innodb_data_file_path = ibdata1:128M:autoextend innodb_file_io_threads = 8 #innodb_read_io_threads = 8 #innodb_force_recovery=1 innodb_thread_concurrency = 16 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 24M innodb_log_files_in_group = 3 #innodb_log_group_home_dir innodb_max_dirty_pages_pct = 90 #innodb_flush_method=O_DSYNC innodb_lock_wait_timeout = 120 innodb_file_per_table = 0 [mysqldump] quick max_allowed_packet = 5M [mysqld_safe] log-error=/data/3306/mysql_niutianwen3306.err pid-file=/data/3306/mysqld.pid
#cp /data/3306/my.cnf /data/3307/my.cnf
#sed 's/3306/3307/g' /data/3307/my.cnf
3:創(chuàng)建MYSQL多實(shí)例的啟動(dòng)文件
#vim /data/3306/mysqld(啟動(dòng)腳本配置實(shí)例如下,供參考)
#!/bin/bash #this scripts is created by niutianwen at 2016-10-20 #site :www.niutianwen.com ############################## port=3306 mysql_user="root" mysql_pwd="niutianwen" #<==要與數(shù)據(jù)庫密碼一致> CmdPath="/application/mysql/bin" mysql_sock="/data/${port}/mysql.sock" txtfile="/data/${port}/txt" declare -i value #startup function function_start_mysql() { if [ ! -e "$mysql_sock" ];then printf "Starting MYSQL...\n" /bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null & echo > ${txtfile} sleep 10 value=`netstat -tnlp | grep ":$port " | awk '{print $4}' | awk -F':' '{print $NF}'` #echo $value if [ "${value}" -eq "${port}" ];then printf "MYSQL is up...!\n" else printf "MYSQL is not startup...!\n" fi else printf "MYSQL is runing...\n" exit fi } #stop function function_stop_mysql() { if [ ! -e "$mysql_sock" ];then printf "MYSQL is stopped...\n" exit else printf "Stoping MYSQL...\n" ${CmdPath}/mysqladmin -u${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown && echo "MYSQL is down...!" fi } #restart function function_restart_mysql() { printf "Restarting NYSQL...\n" function_stop_mysql sleep 2 function_start_mysql } case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage:/data/${port}/mysql {start|stop|restart}\n" esac
# cp /data/3306/mysqld /data/3307/mysqld
# sed 's/3306/3307/g' /data/3307/mysqld
至此兩個(gè)實(shí)例的數(shù)據(jù)文件,配置文件,啟動(dòng)文件都已完成配置。
五:配置MYSQL多實(shí)例的文件權(quán)限
1:授權(quán)mysql用戶管理整個(gè)多實(shí)例的根目錄/data
#chown -R mysql.mysql /data
2:因?yàn)閱?dòng)文件中有數(shù)據(jù)庫的密碼信息,因此應(yīng)設(shè)置700權(quán)限最佳
#find /data -name mysqld | xargs chmod 700
六:將Mysql命令加入全局路徑,方便使用。
# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
# source /etc/profile (直接生效)
# echo $PATH (查看配置是否成功)
七:初始化MYSQL多實(shí)例的數(shù)據(jù)庫文件(初始化數(shù)據(jù)庫的實(shí)質(zhì)就是創(chuàng)建基礎(chǔ)的數(shù)據(jù)庫的庫文件)
# cd /application/mysql/scripts
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data -- user=mysql
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data -- user=mysql
八:?jiǎn)?dòng)MYSQL多實(shí)例數(shù)據(jù)庫
# /data/3306/mysqld start(stop|restart)
九:配置MYSQL數(shù)據(jù)庫開機(jī)自啟動(dòng)
# echo "#mysql multi Instances" >> /etc/rc.local
# echo "/data/3306/mysql start" >> /etc/rc.local
# echo "/data/3307/mysql start" >> /etc/rc.local
十:登陸測(cè)試以及安全配置(為mysql設(shè)置密碼登陸)
# mysql -S /data/3306/mysql.sock
# mysqladmin -uroot -S /data/3306/mysql.sock password 'niutianwen'
至此單機(jī)MYSQL雙實(shí)例的配置已經(jīng)完成!如要再增加MYSQL實(shí)例上去只要重復(fù)上述過程即可!謝謝大家。專注linux之路讓大家不在孤單!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。