主頁(yè) > 知識(shí)庫(kù) > Mysql服務(wù)添加 iptables防火墻策略的方案

Mysql服務(wù)添加 iptables防火墻策略的方案

熱門(mén)標(biāo)簽:html地圖標(biāo)注并導(dǎo)航 400電話辦理服務(wù)價(jià)格最實(shí)惠 催天下外呼系統(tǒng) 武漢電銷(xiāo)機(jī)器人電話 400電話變更申請(qǐng) 呂梁外呼系統(tǒng) 北京金倫外呼系統(tǒng) 南太平洋地圖標(biāo)注 大豐地圖標(biāo)注app

如果你的Mysql數(shù)據(jù)庫(kù)安裝在centos7的系統(tǒng)上,并且你的操作系統(tǒng)啟用了防火墻。應(yīng)用要訪問(wèn)mysql數(shù)據(jù)庫(kù),你有2個(gè)解決方案。

方案一:停止防火墻服務(wù)
方案二:在防火墻中添加策略,讓?xiě)?yīng)用能正常訪問(wèn)mysql服務(wù)端口

停止Centos7防火墻

查看防火墻運(yùn)行狀態(tài)

[root@mysql ~]# firewall-cmd --state
running

停止防火墻服務(wù)

[root@mysql ~]# systemctl stop firewalld.service

啟動(dòng)Centos7防火墻

查看防火墻運(yùn)行狀態(tài)

[root@mysql ~]# firewall-cmd --state
not running

啟動(dòng)防火墻服務(wù)

[root@mysql ~]# systemctl start firewalld.service

配置防火墻開(kāi)機(jī)啟動(dòng)

[root@mysql ~]# systemctl enable firewalld.service

訪問(wèn)Mysql服務(wù)測(cè)試
連接Mysql服務(wù)

[mysql@mysql ~]$ mysql -utony -ptony -h 192.168.112.131 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.112.131' (113)

主從復(fù)制連接測(cè)試[root@localhost] 15:23:46 [(none)]>show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.112.131
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000034
          Read_Master_Log_Pos: 194
               Relay_Log_File: mysql-relay-bin.000007
                Relay_Log_Pos: 401
        Relay_Master_Log_File: binlog.000034
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
           .....
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master 'repl@192.168.112.131:3306' - retry-time: 60  retries: 1
               Last_SQL_Errno: 0

主從的IO線程已斷開(kāi),并且報(bào)2003錯(cuò)誤,這里就確認(rèn)是網(wǎng)絡(luò)不通,訪問(wèn)不了主庫(kù)的服務(wù)。

在防火墻中添加Mysql服務(wù)訪問(wèn)策略

查看防火墻策略

[root@mysql ~]# iptables -L -n --line-number|grep 3306

由于在防火墻中沒(méi)有添加3306端口的訪問(wèn)策略,外部應(yīng)用是無(wú)法mysql服務(wù)的。

[mysql@mysql ~]$ mysql -utony -ptony -h 192.168.112.131 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.112.131' (113)

添加3306端口訪問(wèn)策略

# iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
[root@mysql ~]# iptables -L -n --line-number|grep 3306
1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:3306

可以看到已經(jīng)添加了3306端口的訪問(wèn)策略,外部應(yīng)用可以通過(guò)TCP協(xié)議訪問(wèn)3306端口。

刪除防火墻策略

[root@mysql ~]# iptables -D INPUT 1
[root@mysql ~]# iptables -L -n --line-number|grep 3306

到此這篇關(guān)于給Mysql服務(wù)添加 iptables防火墻策略的文章就介紹到這了,更多相關(guān)Mysql服務(wù)添加 iptables防火墻內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • linux下mysql開(kāi)啟遠(yuǎn)程訪問(wèn)權(quán)限 防火墻開(kāi)放3306端口
  • linux下mysql鏈接被防火墻阻止的解決方法

標(biāo)簽:西寧 無(wú)錫 龍巖 南充 麗水 自貢 迪慶 徐州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Mysql服務(wù)添加 iptables防火墻策略的方案》,本文關(guān)鍵詞  Mysql,服務(wù),添加,iptables,防火墻,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Mysql服務(wù)添加 iptables防火墻策略的方案》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Mysql服務(wù)添加 iptables防火墻策略的方案的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章