Linux installs MongoDB and sets up firewalls that use remote client access

Source: Internet
Author: User

1. Download

MongoDB offers 64-bit installation packages for Linux releases: https://www.mongodb.com/download-center#community

2. Installation

1 tar-zxvf mongodb-linux-x86_64-3.0. 6 . tgz                                   # Unzip 23 mv  mongodb-linux-x86_64-3.0.  6//usr/local/mongodb                         # Copy the unpacked package to the specified directory

MongoDB's executable file is located in the bin directory, so you can add it to your path path:

Export Path=<mongodb-install-directory>/bin: $PATH

<mongodb-install-directory> for your MongoDB installation path. As the /usr/local/mongodb of this article.

Create a database directory

MongoDB data is stored in the DB directory in the database directory, but this directory is not created automatically during the installation process, so you need to create the data directory manually and create the DB directory in the data directory.

In the following example we create the data directory under the root directory (/).

Note:/data/db is the default startup database path for MongoDB (--dbpath).

Mkdir-p/data/db

Start the service side

Enter the installation directory/usr/local/mongodb/bin,

./mongod          #启动服务端        

Remote Client link

1). Because MongoDB uses the default short time of 27017, but the Linux firewall is blocked by 27017 port access, so you need to open the Linux firewall 27017 port

Vi/etc/sysconfig/iptables                     #查看防火墙配置表

The changes are as follows:

#特别提示: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start, the correct one should be added to the default 22 port under the rule # Firewall configuration written by System-config-Firewall # Manual customization of ThisFile isNot recommended.*filter:input ACCEPT [0:0]: FORWARD ACCEPT [0:0]: OUTPUT ACCEPT [0:0] -A input-m state–state established,related-J ACCEPT-A input-p ICMP-J ACCEPT-A input-i lo-J ACCEPT-A input-m state–state new-m tcp-p tcp–dport A-J ACCEPT-A input-m state–state new-m tcp-p tcp–dport27017-J ACCEPT-A input-m state–state new-m tcp-p tcp–dport3306-J ACCEPT-A input-j Reject–reject-with icmp-host-prohibited-A forward-j Reject–reject-with icmp-host-prohibited COMMIT

Finally reboot the firewall to make the configuration effective

Finally, you can use your remote client to access MongoDB

192.168. *.***:27017

Linux installs MongoDB and sets up firewalls that use remote client access

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.