溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CentOS 6.8 編譯安裝MySQL5.5.32 (二 多實(shí)例)

發(fā)布時(shí)間:2020-07-17 22:33:54 來源:網(wǎng)絡(luò) 閱讀:1855 作者:邱月濤 欄目:數(shù)據(jù)庫

MySQL多實(shí)例的配置

通過上文 CentOS 6.8 編譯安裝MySQL5.5.32 ,我們完成了編譯安裝,接下配置多實(shí)例

CentOS 6.8 編譯安裝MySQL5.5.32 (二 多實(shí)例)

本圖借鑒徐亮偉"思維簡圖"

5,添加多實(shí)例目錄

[root@db01 application]# mkdir -p /data/{3306,3307}/data
[root@db01 application]# tree  /data/
/data/
├── 3306   
│   └── data   
└── 3307
       └── data,

6,上傳多實(shí)例配置文件

[root@db01 /]# cd /
[root@db01 /]# rz -y data.zip 
[root@db01 /]# unzip data.zip
[root@db01 /]# tree data
data
├── 3306  ##3306實(shí)例目錄
│   ├── data     
│   ├── my.cnf   
│   └── mysql    
└── 3307
    ├── data
    ├── my.cnf
    └── mysql

##多實(shí)例 文件對比 配置文件中 只有字符串 3306與3307,與serverID 的不同

7,給Mysql啟動腳本增加執(zhí)行權(quán)限

find /data -type f -name "mysql"|xargs chmod 700
chown -R mysql.mysql /data

CentOS 6.8 編譯安裝MySQL5.5.32 (二 多實(shí)例)

8,多實(shí)例初始化,作用就是加載mysql自帶的庫與表##

cd /application/mysql/scripts
./mysql_install_db  --defaults-file=/data/3306/my.cnf --basedir=/application/mysql/ --datadir=/data/3306/data --user=mysql
./mysql_install_db  --defaults-file=/data/3307/my.cnf --basedir=/application/mysql/ --datadir=/data/3307/data --user=mysql

##提示:--basedir=/application/mysql/為MySQL的安裝路徑,--datadir為數(shù)據(jù)文件目錄。
另,注意mysql_install_db和MySQL5.1的路徑不同,MySQL5.1不在MySQL bin路徑下了。

  編譯過程,注意要有2個(gè)OK 才算成功

[root@db02 scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
WARNING: The host 'db02' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK #<==兩個(gè)OK是初始化成功的標(biāo)志。
Filling help tables...
OK  #<==兩個(gè)OK是初始化成功的標(biāo)志。
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h db02 password 'new-password'
Alternatively you can run:
/application/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /application/mysql/scripts/mysqlbug script!
###請注意如下幾行英文的說明及報(bào)錯(cuò)
New default config file was createdas /application/mysql//my.cnf and
will be used by default by theserver when you start it.
You may edit this file to changeserver settings
#從上文說明中可以指導(dǎo)mysql的默認(rèn)配置文件已經(jīng)變到了/application/mysql//my.cnf
WARNING: Default config file/etc/my.cnf exists on the system
This file will be read by defaultby the MySQL server
If you do not want to use this,either remove it, or use the
--defaults-file argument tomysqld_safe when starting the server
#從上文說明中可以看到數(shù)據(jù)庫啟動時(shí)會讀取/etc/my.cnf,因此有可能會導(dǎo)致無法啟動,避免的方法就是使用mysqld_safe啟動服務(wù)時(shí)采用--defaults-file參數(shù)指定配置文件,前文已將/etc/my.cnf改名了,所以,就不需要指定參數(shù)了,這里是一個(gè)坑,讀者要注意。
此步驟必須要初始化成功,否則,后面會出現(xiàn)登錄不了數(shù)據(jù)庫等各種問題。
[root@oldboy ~]# mysql
ERROR1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解決辦法:重新初始化數(shù)據(jù)庫即可,此問題一般都是數(shù)據(jù)庫初始化問題,或者數(shù)據(jù)庫文件損壞,以及目錄權(quán)限問題

9,MySQL 初始化原理

初始化數(shù)據(jù)庫的就是加載MySQL自帶的庫與表  例如:生成的test及mysql庫表等。

初始化數(shù)據(jù)庫后,查看數(shù)據(jù)目錄,生成哪些文件

[root@db02 scripts]# ls -l /data/3306/data/
total 143372
-rw-rw---- 1 mysql mysql 134217728 Apr 29 03:32 ibdata1
-rw-rw---- 1 mysql mysql   4194304 Apr 29 03:32 ib_logfile0
-rw-rw---- 1 mysql mysql   4194304 Apr 29 03:32 ib_logfile1
-rw-rw---- 1 mysql mysql   4194304 Apr 29 03:32 ib_logfile2
drwx------ 2 mysql root       4096 Apr 29 03:31 mysql      ##用于存放管理mysql數(shù)據(jù)
drwx------ 2 mysql mysql      4096 Apr 29 03:31 performance_schema #內(nèi)部性能庫
drwx------ 2 mysql root       4096 Apr 29 03:31 test       ##測試庫

10,啟動MySQL 命令 多實(shí)例(3306/3307)

[root@db02 scripts]# /data/3306/mysql start ##啟動腳本見百度云連接
Starting MySQL...    
[root@db02 scripts]# /data/3307/mysql start
Starting MySQL...
[root@db02 scripts]# ps -ef|grep 330
root      13426      1  0 11:32 pts/1    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf
mysql     14150  13426  0 11:32 pts/1    00:00:05 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3306/mysql_oldboy3306.err --open-files-limit=1024 --pid-file=/data/3306/mysqld.pid --socket=/data/3306/mysql.sock --port=3306
root      17840      1  0 12:57 pts/1    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf
mysql     18540  17840 15 12:57 pts/1    00:00:01 /application/mysql-5.5.32/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/mysql_oldboy3307.err --open-files-limit=1024 --pid-file=/data/3307/mysqld.pid --socket=/data/3307/mysql.sock --port=3307
root      18558   1286  0 12:57 pts/1    00:00:00 grep --color=auto 330
##如果啟動失敗,請檢查日志,路徑是在 每個(gè)實(shí)例下都有個(gè)err文件,例如下面的3306
[root@db02 scripts]# vi /data/3306/mysql_oldboy3306.err

#MySQL5.6.36版本會出現(xiàn)如下錯(cuò)誤:
[root@db02 scripts]# /data/3306/mysql start
Starting MySQL...
170508 12:56:08 mysqld_safe error: log-error set to '/data/3306/oldboy_3306.err', however file don't exists. Create writable for user 'mysql'.
#解決方法:
touch /data/3306/oldboy_3306.err
chown mysql.mysql /data/3306/oldboy_3306.err
/data/3306/mysql start   ##3307實(shí)例也是如此操作,主要是缺少錯(cuò)誤日志文件導(dǎo)致無法啟動

11,連接MySQL數(shù)據(jù)庫( 以socket區(qū)分,多實(shí)例

[root@db02 scripts]# mysql -uroot -p -S /data/3306/mysql.sock  #-S指定要啟動實(shí)例的socket-bash: mysql: command not found  #報(bào)錯(cuò)是因?yàn)闆]有設(shè)定環(huán)境變量
解決方法的兩種思路: (建議使用第二種)
1)將mysql 路徑添加到環(huán)境變量
echo "PATH=$PATH:/application/mysql/bin/">>/etc/profile
source /etc/profilep
2)將mysql 需要執(zhí)行的文件或腳本,拷貝到第一個(gè)已經(jīng)有環(huán)境變量權(quán)限的目錄下,去執(zhí)行。
cp /application/mysql/bin/* /usr/local/sbin/
再次連接,登錄3306
[root@db02 ~]# mysql -uroot -p -S /data/3306/mysql.sock 
[root@db02 ~]# mysql -uroot -p -S /data/3307/mysql.sock
Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.32-log Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

12,添加開機(jī)自啟動 (多實(shí)例 multi instances

[root@db02 ~]# echo "# mysql multi instances" >>/etc/rc.local #添加注釋,及實(shí)例啟動項(xiàng)
[root@db02 ~]# echo "/data/3306/mysql start " >>/etc/rc.local
[root@db02 ~]# echo "/data/3307/mysql start " >>/etc/rc.loca

13,新增一個(gè)3308實(shí)例

mkdir -p /data/3308/data
\cp /data/3306/my.cnf  /data/3308/
\cp /data/3306/mysql  /data/3308/
sed -i 's/3306/3308/g' /data/3308/my.cnf 
sed -i 's/server-id = 6/server-id = 8/g' /data/3308/my.cnf 
sed -i 's/3306/3308/g' /data/3308/mysql
chown -R mysql:mysql /data/3308
chmod 700 /data/3308/mysql
cd /application/mysql/scripts
./mysql_install_db --defaults-file=/data/3308/my.cnf --datadir=/data/3308/data --basedir=/application/mysql --user=mysql
chown -R mysql:mysql /data/3308
egrep "server-id|log-bin" /data/3308/my.cnf 
touch /data/3308/oldboy_3308.err
chown mysql /data/3308/oldboy_3308.err
/data/3308/mysql start  #mysql啟動慢,如果此段命令放到腳本中支持,需要sleep 3-5秒
netstat -lnt|grep 3308

 測試3308實(shí)例

[root@db02 scripts]# mysqld_safe /data/3308/mysql.sock  #目前已啟動3個(gè)實(shí)例
[root@db02 scripts]# netstat -lnt|grep 330
tcp        0      0 :::3306                     :::*                        LISTEN      
tcp        0      0 :::3307                     :::*                        LISTEN      
tcp        0      0 :::3308                     :::*                        LISTEN

14,Mysql多實(shí)例啟動故障排錯(cuò)說明

  1. 如果MySQL多實(shí)例有服務(wù)沒有被啟動,排除方法如下:

     如果發(fā)現(xiàn)沒有顯示MySQL對應(yīng)的實(shí)例端口,請稍微等待幾秒在檢查,MySQL服務(wù)的啟動稍慢

     如果還是不行,請查看MySQL實(shí)例對應(yīng)的錯(cuò)誤日志,路徑在my.cnf配置文件中最下面定義:

    例如:3306實(shí)例的錯(cuò)誤日志為:/data/3306/*.err

  2. 細(xì)看所有執(zhí)行命令返回的屏幕輸出,不要忽略關(guān)鍵的輸出內(nèi)容。

  3. 輔助查看系統(tǒng)日志/var/log/messages

  4. 如果是MySQL關(guān)聯(lián)了其他服務(wù),同時(shí)查看相關(guān)服務(wù)日志

  5. 仔細(xì)閱讀,重新查看操作的步驟是否正確,書寫命令及字符串是否正確。

  6. 多看日志,多多總結(jié),終究會稱為高手的。




附件:http://down.51cto.com/data/2366621
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI