CentOS 7 configuration mariadb allows you to specify IP remote connection database

Source: Internet
Author: User
Tags iptables server port

Firewall
 The firewall before CentOS7 is different. For example, if you want to add port 3306:

## All
 iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT

 ## Part of ipiptables
 iptables -A INPUT -p tcp -s 138.111.21.11 -dport 3306 -j ACCEP

 service iptables save
 
 service iptables restart

 ## View iptables
 iptables -L -n


But this is not easy to use in CentOS 7. Check the documentation to know that CentOS 7 uses the enhanced version of firewall

firewall-cmd --zone = public --permanent --add-port = 3306 / tcp

  1. firwall-cmd: is a tool provided by Linux to operate firewall;
  2. --permanent: means set to persistent;
  3. --add-port: Identify the added port;
  4. --zone = public: The specified zone is public;


Of course, if you are not used to using commands, we can directly change the configuration file

Enter etc / firewalld / zone, modify public.xml

<? 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" /> open specified IP, specify port, protocol
    <port protocol = "tcp" port = "80" />
    <accept />
  </ rule>
<rule family = "ipv4"> Open any IP access server port 9527
    <port protocol = "tcp" port = "9527" />
    <accept />
  </ rule>
</ zone>
The above configuration file can be seen:

1. Add the required rules, open source IP is 122.10.70.234, port 514, protocol tcp
2. Open source IP is 123.60.255.14, port 10050-10051, protocol tcp; / 3, open source IP is arbitrary, port 9527, protocol
firewall common commands

# Restart
service firewalld restart

# Open
service firewalld start

# shut down
service firewalld stop

# View firewall service status
 systemctl status firewall

# View firewall
 firewall-cmd --list-all
 


After opening the server 3306 and opening to the outside world, you need to set up database user authorization

MariaDB opens a remote connection
In the user table in the database mysql, you can see that the default is only local connection, so you can add a user

# For ip
create user ‘root‘@‘192.168.10.10’ identified by ‘password’;

#All
 create user ‘root‘ @ ‘%‘ identified by ‘password’;
It is recommended to open to ip, do not open all

Authorized users:

 # Give users maximum permissions
  grant all privileges on *. * to ‘root‘ @ ‘%‘ identified by ‘password’;

 # Give some permissions (test database)

  grant all privileges on test. * to ‘root‘ @ ‘%‘ identified by ‘password’ with grant option;

# Refresh permission table
 
 flush privileges;

# show grants for ‘root‘ @ ‘localhost’;



The next step is to connect locally.

Install Nginx, MariaDB and HHVM on Ubuntu 16.04 LTS to run WordPress

Ubuntu 16.04 Dockerfile install MariaDB http://www.linuxidc.com/Linux/2016-09/135260.htm

Linux system tutorial: How to check the MariaDB server version http://www.linuxidc.com/Linux/2015-08/122382.htm

How to install MariaDB under Ubuntu 16.04 http://www.linuxidc.com/Linux/2017-04/142915.htm

CentOS 7.3 binary installation MariaDB10.2.8 steps http://www.linuxidc.com/Linux/2017-10/147904.htm

CentOS 7 compile and install MariaDB-10.1.22 http://www.linuxidc.com/Linux/2017-05/143291.htm

How to migrate MySQL 5.5 database to MariaDB 10 on Ubuntu http://www.linuxidc.com/Linux/2014-11/109471.htm

[Translation] Ubuntu 14.04 (Trusty) Server installation MariaDB http://www.linuxidc.com/Linux/2014-12/110048htm

Ubuntu 14.04 (Trusty) install MariaDB 10 database http://www.linuxidc.com/Linux/2016-11/136833.htm

A detailed introduction to MariaDB: click here
MariaDB: Click here

CentOS 7 configures MariaDB to allow specified IP to connect to the database remotely


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.