您好,登錄后才能下訂單哦!
Centos6.6安裝并配置單機多實例的MYSQL數據庫
本文介紹安裝單機多實例的MYSQL數據庫的環境如下:
系統平臺環境: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(光盤中會自帶,也可自行編譯安裝)
如果是自行編譯安裝cmake可以#which cmake查看到全路徑,以便后面編譯安裝MYSQL
三:開始安裝MYSQL數據庫
1:創建mysql用戶賬號
# useradd -s /sbin/nologin -M mysql && id mysql
2: 獲取MYSQL的源代碼包(如連接失效可自行找到相應鏈接)
# 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方式安裝就算成功了!!
既然是配置安裝單機多實例數據庫,那么我們接下來要做的就是為每個實例創建必須的 數據文件,配置文件.以及啟動文件。
四:實例創建必須的數據文件,配置文件.以及啟動文件。
1:為每個實例創建數據目錄
#mkdir -p /data/{3306,3307}/data
2:為每個實例創建配置文件(ls -l /application/mysql/suport-files/my*.cnf 數據庫默認提供的多個 配置文件模板,用戶可根據服務器硬件配置選擇相應的模板)
#vim /data/3306/my.cnf (配置實例如下 #為注釋行)
[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:創建MYSQL多實例的啟動文件
#vim /data/3306/mysqld(啟動腳本配置實例如下,供參考)
#!/bin/bash #this scripts is created by niutianwen at 2016-10-20 #site :www.niutianwen.com ############################## port=3306 mysql_user="root" mysql_pwd="niutianwen" #<==要與數據庫密碼一致> 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
至此兩個實例的數據文件,配置文件,啟動文件都已完成配置。
五:配置MYSQL多實例的文件權限
1:授權mysql用戶管理整個多實例的根目錄/data
#chown -R mysql.mysql /data
2:因為啟動文件中有數據庫的密碼信息,因此應設置700權限最佳
#find /data -name mysqld | xargs chmod 700
六:將Mysql命令加入全局路徑,方便使用。
# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
# source /etc/profile (直接生效)
# echo $PATH (查看配置是否成功)
七:初始化MYSQL多實例的數據庫文件(初始化數據庫的實質就是創建基礎的數據庫的庫文件)
# 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
八:啟動MYSQL多實例數據庫
# /data/3306/mysqld start(stop|restart)
九:配置MYSQL數據庫開機自啟動
# echo "#mysql multi Instances" >> /etc/rc.local
# echo "/data/3306/mysql start" >> /etc/rc.local
# echo "/data/3307/mysql start" >> /etc/rc.local
十:登陸測試以及安全配置(為mysql設置密碼登陸)
# mysql -S /data/3306/mysql.sock
# mysqladmin -uroot -S /data/3306/mysql.sock password 'niutianwen'
至此單機MYSQL雙實例的配置已經完成!如要再增加MYSQL實例上去只要重復上述過程即可!謝謝大家。專注linux之路讓大家不在孤單!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。