CentOS7 以前的防火墙是不同的,好比你要添加3306端口:php
## 所有 iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT ## 部分ipiptables iptables -A INPUT -p tcp -s 138.111.21.11 -dport 3306 -j ACCEP service iptables save service iptables restart ## 查看 iptables iptables -L -n
但这个在CentOS 7 就很差使,查看文档才知道CentOS 7 使用了加强版firewall
mysql
firewall-cmd --zone=public --permanent --add-port=3306/tcp
一、firwall-cmd:是Linux提供的操做firewall的一个工具; 二、--permanent:表示设置为持久; 三、--add-port:标识添加的端口; 四、--zone=public:指定的zone为public;
固然若是不太习惯使用命令,咱们能够直接改配置文件linux
进入etc/firewalld/zone
中,修改public.xml
sql
<?xml version="1.0" encoding="utf-8"?> <zone> <short>Public</short> <description>For use in public areas.</description> <rule family="ipv4"> <source address="122.10.70.234"/> <port protocol="udp" port="514"/> <accept/> </rule> <rule family="ipv4"> <source address="123.60.255.14"/> <port protocol="tcp" port="10050-10051"/> <accept/> </rule> <rule family="ipv4"> <source address="192.249.87.114"/> 放通指定ip,指定端口、协议 <port protocol="tcp" port="80"/> <accept/> </rule> <rule family="ipv4"> 放通任意ip访问服务器的9527端口 <port protocol="tcp" port="9527"/> <accept/> </rule> </zone>
上述配置文件能够看出:数据库
一、添加须要的规则,开放通源ip为122.10.70.234,端口514,协议tcp; 二、开放通源ip为123.60.255.14,端口10050-10051,协议tcp;/三、开放通源ip为任意,端口9527,协议
firewall 经常使用命令
# 重启
service firewalld restart
# 开启
service firewalld start
# 关闭
service firewalld stop
# 查看firewall 服务状态
systemctl status firewall
# 查看防火墙
firewall-cmd --list-all
开启服务器3306对外开放后,还须要设置数据库用户受权服务器
在数据库
mysql
中的user
表中能够看到默认是只能本地链接的,全部能够添加一个用户tcp
# 针对ip create user 'root'@'192.168.10.10' identified by 'password'; #所有 create user 'root'@'%' identified by 'password';
建议仍是针对于ip开放吧,不要所有开放ide
受权用户:工具
# 给用户最大权限 grant all privileges on *.* to 'root'@'%' identified by 'password'; # 给部分权限(test 数据库) grant all privileges on test.* to 'root'@'%' identified by 'password' with grant option; # 刷新权限表 flush privileges; # show grants for 'root'@'localhost';
接下来就是能够本地链接了。spa
Ubuntu 16.04 LTS 上安装 Nginx、MariaDB 和 HHVM 运行 WordPress http://www.linuxidc.com/Linux/2016-10/136435.htm
Ubuntu 16.04 Dockerfile 安装MariaDB http://www.linuxidc.com/Linux/2016-09/135260.htm
Linux系统教程:如何检查MariaDB服务端版本 http://www.linuxidc.com/Linux/2015-08/122382.htm
Ubuntu 16.04下如何安装MariaDB http://www.linuxidc.com/Linux/2017-04/142915.htm
CentOS 7.3二进制安装MariaDB10.2.8步骤 http://www.linuxidc.com/Linux/2017-10/147904.htm
CentOS 7 编译安装MariaDB-10.1.22 http://www.linuxidc.com/Linux/2017-05/143291.htm
Ubuntu 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10 http://www.linuxidc.com/Linux/2014-11/109471.htm
[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB http://www.linuxidc.com/Linux/2014-12/110048htm
Ubuntu 14.04(Trusty)安装MariaDB 10数据库 http://www.linuxidc.com/Linux/2016-11/136833.htm