欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

快速實(shí)現(xiàn)MySQL的部署以及一機(jī)多實(shí)例部署

 更新時間:2016年04月20日 14:38:11   作者:iVictor  
這篇文章主要為大家詳細(xì)介紹了快速實(shí)現(xiàn)MySQL的部署以及一機(jī)多實(shí)例部署的相關(guān)資料,感興趣的小伙伴們可以參考一下

MySQL有三個版本:二進(jìn)制,源碼包,RPM。

下面講講二進(jìn)制包的安裝過程

下載地址:http://dev.mysql.com/downloads/mysql/

選擇Linux-Generic

我這里選擇的是mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

解壓后,里面有個文件INSTALL-BINARY,其實(shí)給出了二進(jìn)制包的部署過程

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 

相對于實(shí)際生產(chǎn)環(huán)境的部署,上面在初始化數(shù)據(jù)庫的過程中少了一步-即指定配置文件,如果配置文件確認(rèn)了,數(shù)據(jù)目錄,日志目錄都確認(rèn)了,MySQL二進(jìn)制版本的部署還是相當(dāng)容易的一件事情。

下面寫了一個腳本,基于后面提供的配置文件,執(zhí)行格式如下:

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是二進(jìn)制包的絕對路徑,/mysql3306是basedir,3306是需設(shè)置的端口,

利用該腳本,只需要預(yù)先定義好配置文件,就可進(jìn)行MySQL數(shù)據(jù)庫的快速部署以及一臺服務(wù)器上多個實(shí)例的部署。

#!/bin/bash
#需傳入三個參數(shù),第一個是mysql二進(jìn)制壓縮包的路徑(絕對路徑),譬如/root/mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz,
#第二個是mysql的basedir,即需要創(chuàng)建在哪個目錄下,第三個是設(shè)置的端口號
filename=$1
basedir=$2
port=$3

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf $filename
#file是獲取mysql二進(jìn)制包的名稱,譬如mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz
#dir是mysql壓縮包的路徑,不含包名本身,譬如/root,因?yàn)楹罄m(xù)的配置文件my.cnf也是放到這個路徑下
file=`basename $filename`
dir=`dirname $filename`

#獲取解壓后的名字,即mysql-5.6.28-linux-glibc2.5-x86_64
after_tar_file=${file:0:-7}
#將二進(jìn)制包改名為 mysql+端口號,這樣也便于后續(xù)的區(qū)分
mv $after_tar_file mysql"$port"
cd mysql"$port"

#將原始的配置文件(需和mysql壓縮包放到同層目錄下,在本例中是/root/my.cnf)copy到解壓并改名后的mysql二進(jìn)制目錄下,修改為my+端口號.cnf
cp $dir/my.cnf ./my"$port".cnf
user_cnf=my"$port".cnf
#下面主要是將原始配置文件中的路徑修改為自己設(shè)定的路徑,即傳入的第二個參數(shù)
#整個的挑戰(zhàn)在于傳入的路徑帶有"/",在sed替換時會有問題,所有用了一個取巧的思路,即先將"/"替換為"|",進(jìn)行sed替換,然后再將文件中的"|"修改回"/"
basedir_new=${basedir/\//|}
sed -i "s/\/project\/class2/$basedir_new/g" $user_cnf
sed -i "s/|/\//g" $user_cnf

#設(shè)置server_id,取當(dāng)前的秒值
server_id=`date +%s`
sed -i /^server_id/s/.*/server_id="$server_id"/ $user_cnf
#設(shè)置端口號
sed -i /^port/s/.*/port="$port"/ $user_cnf

#創(chuàng)建必要的目錄并修改權(quán)限
mkdir -p "$basedir"/mysql/{run,data,share,log,tmp}

chown -R mysql $basedir
chgrp -R mysql $basedir

#下面這個是非必要的,具體看后面的總結(jié)
cp share/english/errmsg.sys "$basedir"/mysql/share/

#初始化時--force也是非必要的,具體可見后面的總結(jié)
scripts/mysql_install_db --user=mysql --defaults-file="$user_cnf" --force
bin/mysqld_safe --defaults-file="$user_cnf" --user=mysql &

下面給出了配置文件的一個參考,大家可根據(jù)實(shí)際情況進(jìn)行相應(yīng)的修改

[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

總結(jié):

在初始化的過程中,如果報(bào)以下錯誤:

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終端上執(zhí)行hostname命令又確實(shí)有值返回,可加--force參數(shù),如下所示:

復(fù)制代碼 代碼如下:
scripts/mysql_install_db --user=mysql --defaults-file="$user_cnf" --force

如果報(bào)以下錯誤:

復(fù)制代碼 代碼如下:
[ERROR] Can't find messagefile '/mysql3306/mysql/share/errmsg.sys'

可將二進(jìn)制版本中share/english/errmsg.sys文件COPY到/mysql3306/mysql/share/下。

后續(xù):這兩個錯誤的原因都是因?yàn)閎asedir修改了,它默認(rèn)是在二進(jìn)制包中查找的。

如何利用腳本實(shí)現(xiàn)MySQL的快速部署以及一機(jī)多實(shí)例的部署,通過這篇文章希望對大家學(xué)習(xí)MySQL的部署有所幫助。

相關(guān)文章

  • Mysql事物鎖等待超時Lock wait timeout exceeded;的解決

    Mysql事物鎖等待超時Lock wait timeout exceeded;的解決

    本文主要介紹了Mysql事物鎖等待超時Lock wait timeout exceeded;的解決,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • CentOS 7搭建多實(shí)例MySQL8的詳細(xì)教程(想要幾個搞幾個)

    CentOS 7搭建多實(shí)例MySQL8的詳細(xì)教程(想要幾個搞幾個)

    這篇文章主要介紹了CentOS 7搭建多實(shí)例MySQL8的詳細(xì)教程(想要幾個搞幾個),本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-05-05
  • MySQL中如何給一個字段遞增賦值

    MySQL中如何給一個字段遞增賦值

    這篇文章主要介紹了MySQL中如何給一個字段遞增賦值問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • 安裝配置mysql及Navicat prenium的詳細(xì)流程

    安裝配置mysql及Navicat prenium的詳細(xì)流程

    這篇文章主要介紹了安裝配置mysql及Navicat Premium的詳細(xì)流程,配置方法也真的很簡單,本文給大家詳細(xì)介紹mysql Navicat Premium安裝配置相關(guān)知識感興趣的朋友,一起學(xué)習(xí)吧
    2021-06-06
  • MySQL之臨時表的實(shí)現(xiàn)示例

    MySQL之臨時表的實(shí)現(xiàn)示例

    MySQL臨時表是存儲在內(nèi)存或者磁盤上的臨時數(shù)據(jù)表,它們的生命周期只限于當(dāng)前數(shù)據(jù)庫會話,臨時表的創(chuàng)建和使用方式與普通表類似,本文就詳細(xì)的介紹了MySQL之臨時表,感興趣的可以了解一下
    2023-08-08
  • Windows(x86,64bit)升級MySQL 5.7.17免安裝版的詳細(xì)教程

    Windows(x86,64bit)升級MySQL 5.7.17免安裝版的詳細(xì)教程

    這篇文章主要介紹了Windows(x86,64bit)升級MySQL 5.7.17免安裝版的詳細(xì)教程,需要的朋友可以參考下
    2017-02-02
  • SQL更新與刪除數(shù)據(jù)操作示例詳解

    SQL更新與刪除數(shù)據(jù)操作示例詳解

    如果要在程序運(yùn)行過程中操作數(shù)據(jù)庫中的數(shù)據(jù),那得先學(xué)會使用SQL語句,下面這篇文章主要給大家介紹了關(guān)于SQL查詢語句更新和刪除數(shù)據(jù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-01-01
  • mysql查詢過去24小時內(nèi)每小時數(shù)據(jù)量的方法(精確到分鐘)

    mysql查詢過去24小時內(nèi)每小時數(shù)據(jù)量的方法(精確到分鐘)

    我們經(jīng)常遇到類似這樣的需求,查詢最近N秒、N分鐘、N小時的數(shù)據(jù)及N天的數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于mysql查詢過去24小時內(nèi)每小時數(shù)據(jù)量(精確到分鐘)的相關(guān)資料,需要的朋友可以參考下
    2023-03-03
  • MySQL表的增刪查改及聚合函數(shù)/group?by子句的使用方法舉例

    MySQL表的增刪查改及聚合函數(shù)/group?by子句的使用方法舉例

    這篇文章主要給大家介紹了關(guān)于MySQL表的增刪查改及聚合函數(shù)/group?by子句的使用方法,在MySQL中可以使用聚合函數(shù)與GROUP BY語句可以對數(shù)據(jù)進(jìn)行分組并進(jìn)行聚合計(jì)算,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01
  • MySQL中常見關(guān)鍵字的用法總結(jié)

    MySQL中常見關(guān)鍵字的用法總結(jié)

    這篇文章主要為大家詳細(xì)介紹了MySQL中常見關(guān)鍵字的用法,例如GROUP BY、ORDER BY和LIMIT,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下
    2023-09-09

最新評論