Mysql服務(wù)添加 iptables防火墻策略的方案
如果你的Mysql數(shù)據(jù)庫安裝在centos7的系統(tǒng)上,并且你的操作系統(tǒng)啟用了防火墻。應(yīng)用要訪問mysql數(shù)據(jù)庫,你有2個(gè)解決方案。
方案一:停止防火墻服務(wù)
方案二:在防火墻中添加策略,讓應(yīng)用能正常訪問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
配置防火墻開機(jī)啟動(dòng)
[root@mysql ~]# systemctl enable firewalld.service
訪問Mysql服務(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) 主從復(fù)制連接測試[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線程已斷開,并且報(bào)2003錯(cuò)誤,這里就確認(rèn)是網(wǎng)絡(luò)不通,訪問不了主庫的服務(wù)。
在防火墻中添加Mysql服務(wù)訪問策略
查看防火墻策略
[root@mysql ~]# iptables -L -n --line-number|grep 3306
由于在防火墻中沒有添加3306端口的訪問策略,外部應(yīng)用是無法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端口訪問策略
# 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端口的訪問策略,外部應(yīng)用可以通過TCP協(xié)議訪問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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MySQL 8中新增的這三大索引 隱藏、降序、函數(shù)
這篇文章主要介紹了MySQL 8.x版本中新增的三大索引 隱藏索引、降索引序、函數(shù)索引,如果文章對(duì)你有點(diǎn)幫助,小伙伴們點(diǎn)贊、收藏、評(píng)論、分享走起呀2021-09-09關(guān)于MySQL主從復(fù)制的幾種復(fù)制方式總結(jié)
這篇文章主要給大家介紹了關(guān)于MySQL主從復(fù)制的幾種復(fù)制方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用MySQL具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08MySQL count(1)、count(*)、count(字段)的區(qū)別
COUNT在數(shù)據(jù)庫行數(shù)統(tǒng)計(jì)中被廣泛使用,那么你知道MySQL count(1)、count(*)、count(字段)的區(qū)別嗎,本文就想的介紹一下,感興趣的可以了解一下2021-12-12MySQL?SQL性能分析之慢查詢?nèi)罩尽xplain使用詳解
這篇文章主要介紹了MySQL?SQL性能分析?慢查詢?nèi)罩?、explain使用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04mysql設(shè)置值timestamp獲取當(dāng)前時(shí)間并自動(dòng)更新方式
這篇文章主要介紹了mysql設(shè)置值timestamp獲取當(dāng)前時(shí)間并自動(dòng)更新方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07MySQL ERROR 1045 (28000): Access denied for user ''root''@''
這篇文章主要介紹了MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 的原因分解決辦法的相關(guān)資料,需要的朋友可以參考下2016-05-05