Things covered in this article:

  • Ali Cloud server ECS
  • CentOs 7.4 system
  • Directing a 3.6

The fifth day of the year, still don’t shake with 64 hexagrams quickly? How about your New Year’s money

Welfare will be written in the front: the Chinese New Year, we do not have a New Year’s money ah? Ha ha ha ha, New Year’s money to buy candy to eat is not as good as investing in yourself. For example, to buy courses, or to buy servers, to learn programming, to write crawlers. Come buy a server buy a server! Running in the local area is useless! Coincidentally, there are thousands of coupons from Alibaba Cloud and Tencent Cloud for you to use (just click on the discount link to enter and receive each discount) :

Ali cloud part: [ali cloud 1888 yuan cloud products general vouchers 】 : promotion.aliyun.com/ntms/yunpar…

【 ali cloud hot style cloud hosting, 2 discount coupons 】 : promotion.aliyun.com/ntms/act/qw…

“Ali cloud enterprise server 2 discount coupons” : promotion.aliyun.com/ntms/act/en…

Tencent cloud:

【 new clients have no threshold for total value as high as 2775 yuan voucher, each voucher set limit to 500 pieces, first come first serve 】 : cloud.tencent.com/redirect.ph…

【 tencent cloud server, cloud database privileges, 3 discount coupons 】 : cloud.tencent.com/redirect.ph…

Next comes the text

Due to their own learning and public number background development project needs (

You can’t always use MongoDB locally, but try it out in production

), in Baidu a lot of methods to install MongoDB in Ali cloud server, the effect is not very good, so this time I step on the pit for everyone, to comb the process of installing MongoDB.

It is recommended that you save the article or keep it for future use.

This installation method is from the official website, but it must be modified to work properly.

Before we start, let’s make sure that our Alicloud uses CentOs system. Install MongoDB in different ways on different systems.

First, create the mongodb-org-3.6.repo file because we will install it with yum.

# touch/etc/yum. Repos. D/mongo - org - 3.6. Repo
Copy the code

Then, edit the mongodb-org-3.6.repo file.

# vim/etc/yum. Repos. D/mongo - org - 3.6. Repo
Copy the code

Copy the following verbatim (

No line number! No preceding line number! No front line number!!

).

[mongo - org - 3.6] name = mongo Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/ mongo - org / 3.6 / x86_64 / gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc gpgcheck = 1 enabled = 1Copy the code

Some students may not be familiar with how to use VIm, this is a required course ah, will use, is very loaded force, and very high efficiency!! Here’s how to do it.

Repos. D /mongodb-org-3.6.repo Press I on the keyboard to enter Add mode, then CTRL + V to paste the content in, then press Esc to return to Add mode, then press: to enter the command. Wq input! You can see the input at the bottom of the page :wq! After typing, press Enter to exit vim.

Go back to terminal and enter the command:

# sudo yum install -y mongodb-org
Copy the code

This process may take a bit longer, please be patient.

After the installation is complete, we need to configure a few more places to boot successfully.

First, we need vim to add a sentence to the /etc/selinux/config file in this directory

SELINUX=permissive
Copy the code

MongoDB configuration file /etc/mongod. Conf In this directory, we need to add an internal IP address of Ali Cloud server. Vim opens the.conf file and we find this:

net:  
port: 27017  
bindIp: 127.0.0.1 
Copy the code

We need to add the internal IP address of our server after this bindIp. After modification, it should look like this:

net:  
port: 27017  
bindIp: 127.0.0.1, 39.10.11.123
Copy the code

MongoDB data and logs are stored in these two directories:

/var/lib/mongo

/var/log/mongodb

So, change the role of these two directories to Mongod. You only need to execute the following two commands:

# chown -R mongod:mongod /var/lib/mongo
# chown -R mongod:mongod /var/log/mongodb
Copy the code

Next, create the /data/db directory. Because the mongo

# mkdir /data/db
Copy the code

Okay, at this point, you’re ready to start MongoDB.

/ / start the mongo# sudo service mongod start/ / close the mongo# sudo service mongod stop/ / restart mongo# sudo service mongod restart
Copy the code

If you want to see whether the mongo started successfully, please go to view the log mongo, just before the directory/var/log/mongo/mongod log. If the log ends with a line:

[initandlisten] waiting for connections on port <port>
Copy the code

MongoDB is successfully started. At this point, you can use the mongo command to go into the MongoDB shell and manipulate the database.

If the local machine wants to connect to a remote database, robomongo is recommended for visualization. This is a very simple connection.

Download and install it, open it, and a setup screen will pop up that allows you to set MongoDB addresses.

In this one, fill in the name of whatever you like, the address below, fill in the public IP address of the server, no words like HTTP, just a 4-digit IP address. The latter ports are default. If the MongoDB port of your server has been changed via mongod. Conf, enter the port number. Leave the rest of the page untouched, then click Save. Then click connect.

When connected, it looks like this:

This way, you can visually view and manipulate the database locally.

The latest update is a little slow, because I was sick this week, high fever at midnight, the whole person for several days. As for the project, I recently thought of using WeRoBot to do wechat background program. However, personal public account does not support custom menu, which is too limited. It is impossible to turn your public account into something similar to half terminal and receive messages by replying non-stop instructions. It’s not impossible, it’s just unfriendly. Anyway, no matter, first developed again, when the time comes to sort out a tutorial for everyone. All of these work, are in order to link up with the previous project, will be written before the crawler integration into the public account, want to let everyone shine at the moment.

Pay attention to this magic public number, there will be 1024 magic code oh