Linux install MongoDB and set up firewalls to use remote client access __linux

Source: Internet
Author: User
Tags install mongodb mongodb

1. Download

MongoDB offers Linux release 64-bit installation package download address: https://www.mongodb.com/download-center#community

2. Installation

1 tar-zxvf mongodb-linux-x86_64-3.0.6.tgz                                   # decompression
2 
3 mv  mongodb-linux-x86_64-3.0.6//usr/local/ MongoDB                         # Copies the unpacked package to the specified directory

The MongoDB executable is in the bin directory, so you can add it to the path:

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

<mongodb-install-directory> The installation path for your MongoDB. such as the /usr/local/mongodb of this article. Create a database directory

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

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

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

Mkdir-p/data/db

Start the service side

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

./mongod          #启动服务端        

Remote Client Links

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

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

Modified to read as follows:

#特别提示: Many netizens add these two rules to the last line of the firewall configuration, which causes the firewall to start failing, the correct one should be added to the default 22 port under the Rule 
# Firewall configuration written by System-config-firewall 
# Manual Customization of this file is not recommended. 
*filter 
: INPUT ACCEPT [0:0] 
: FORWARD ACCEPT [0:0] 
: OUTPUT ACCEPT [0:0] 
-A input-m state–state Establish Ed,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 22-j ACCEPT 
-a input-m state–state new-m tcp-p tcp–dport 27017-j ACCEPT 
-A input-m state–s Tate new-m tcp-p tcp–dport 3306-j ACCEPT-a input-j reject–reject-with 
-a icmp-host-prohibited Reject–reject-with icmp-host-prohibited 

Finally reboot the firewall for the configuration to take effect

Finally, you can use your remote client to access MongoDB

. \mongo 192.168.*.***:27017
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.