Linux Centos7 server MongoDB installation, startup, remote management

Author: Songbao writes code

When you are young, you need to deal with it, because you are always debugging MongoDB locally and want to deploy it to the server for remote login management. This is a bit of a mess with MongoDB’s database. Following is a detailed tutorial on installing, starting, and remotely managing MongoDB on Linux Centos7 server.

One, foreword

Linux Centos7 server MongoDB installation, startup, remote management and other functions. Let’s use the yum setup package this time.

Check the Centos version of the server

cat /etc/os-release
Copy the code

The output

NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0; 31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"Copy the code

The Centos version is 7

Install Mongodb

Configure the source of system YUM

1. Create a. Repo file to generate the mongodb source

Vi/etc/yum. Repos. D/mongo - org - 4.2. RepoCopy the code

2. Add the configuration information

[mongo - org - 4.4] name = directing a Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/ gpgcheck = 1 enabled = 1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.ascCopy the code
  • Name: Refers to the name
  • Baseurl: Get the download path
  • Gpgcheck: verifies RPM packages downloaded from this source
  • Enabled: Enables the source
  • Gpgkey: INDICATES GPG authentication

3. Save the Settings and exit

:wq
Copy the code

Install Mongodb using yum

1, install,

sudo yum install -y mongodb-org
Copy the code

Implementation process

已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
base                                                     | 3.6 kB     00:00     
docker-ce-stable                                         | 3.5 kB     00:00     
epel                                                     | 4.7 kB     00:00     
extras                                                   | 2.9 kB     00:00     
google-chrome                                            | 1.3 kB     00:00     
mongodb-org-4.4                                          | 2.5 kB     00:00     
mysql-connectors-community                               | 2.6 kB     00:00     
mysql-tools-community                                    | 2.6 kB     00:00     
mysql56-community                                        | 2.6 kB     00:00     
updates                                                  | 2.9 kB     00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 mongodb-org.x86_64.0.4.4.6-1.el7 将被 安装
--> 正在处理依赖关系 mongodb-org-shell = 4.4.6,它被软件包 mongodb-org-4.4.6-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-org-tools = 4.4.6,它被软件包 mongodb-org-4.4.6-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-org-server = 4.4.6,它被软件包 mongodb-org-4.4.6-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-org-mongos = 4.4.6,它被软件包 mongodb-org-4.4.6-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mongodb-org-mongos.x86_64.0.4.4.6-1.el7 将被 安装
---> 软件包 mongodb-org-server.x86_64.0.4.4.6-1.el7 将被 安装
---> 软件包 mongodb-org-shell.x86_64.0.4.4.6-1.el7 将被 安装
---> 软件包 mongodb-org-tools.x86_64.0.4.4.6-1.el7 将被 安装
--> 正在处理依赖关系 mongodb-org-database-tools-extra = 4.4.6,它被软件包 mongodb-org-tools-4.4.6-1.el7.x86_64 需要
--> 正在处理依赖关系 mongodb-database-tools,它被软件包 mongodb-org-tools-4.4.6-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mongodb-database-tools.x86_64.0.100.3.1-1 将被 安装
--> 正在处理依赖关系 cyrus-sasl-gssapi,它被软件包 mongodb-database-tools-100.3.1-1.x86_64 需要
--> 正在处理依赖关系 cyrus-sasl-plain,它被软件包 mongodb-database-tools-100.3.1-1.x86_64 需要
--> 正在处理依赖关系 cyrus-sasl,它被软件包 mongodb-database-tools-100.3.1-1.x86_64 需要
---> 软件包 mongodb-org-database-tools-extra.x86_64.0.4.4.6-1.el7 将被 安装
--> 正在检查事务
---> 软件包 cyrus-sasl.x86_64.0.2.1.26-23.el7 将被 安装
---> 软件包 cyrus-sasl-gssapi.x86_64.0.2.1.26-23.el7 将被 安装
---> 软件包 cyrus-sasl-plain.x86_64.0.2.1.26-23.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package                          架构   版本             源               大小
================================================================================
正在安装:
 mongodb-org                      x86_64 4.4.6-1.el7      mongodb-org-4.4 6.2 k
为依赖而安装:
 cyrus-sasl                       x86_64 2.1.26-23.el7    base             88 k
 cyrus-sasl-gssapi                x86_64 2.1.26-23.el7    base             41 k
 cyrus-sasl-plain                 x86_64 2.1.26-23.el7    base             39 k
 mongodb-database-tools           x86_64 100.3.1-1        mongodb-org-4.4  50 M
 mongodb-org-database-tools-extra x86_64 4.4.6-1.el7      mongodb-org-4.4  19 k
 mongodb-org-mongos               x86_64 4.4.6-1.el7      mongodb-org-4.4  17 M
 mongodb-org-server               x86_64 4.4.6-1.el7      mongodb-org-4.4  22 M
 mongodb-org-shell                x86_64 4.4.6-1.el7      mongodb-org-4.4  14 M
 mongodb-org-tools                x86_64 4.4.6-1.el7      mongodb-org-4.4 6.1 k

事务概要
================================================================================
安装  1 软件包 (+9 依赖软件包)

总计:103 M
总下载量:64 M
安装大小:413 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
警告:/var/cache/yum/x86_64/7/mongodb-org-4.4/packages/mongodb-database-tools-100.3.1.x86_64.rpm: 头V3 RSA/SHA1 Signature, 密钥 ID 90cfb1f5: NOKEY
mongodb-database-tools-100.3.1.x86_64.rpm 的公钥尚未安装
(1/3): mongodb-database-tools-100.3.1.x86_64.rpm           |  50 MB   00:24     
(2/3): mongodb-org-tools-4.4.6-1.el7.x86_64.rpm            | 6.1 kB   00:00     
(3/3): mongodb-org-shell-4.4.6-1.el7.x86_64.rpm            |  14 MB   06:30     
--------------------------------------------------------------------------------
总计                                               167 kB/s |  64 MB  06:32     
从 https://www.mongodb.org/static/pgp/server-4.4.asc 检索密钥
导入 GPG key 0x90CFB1F5:
 用户ID     : "MongoDB 4.4 Release Signing Key <[email protected]>"
 指纹       : 2069 1eec 3521 6c63 caf6 6ce1 6564 08e3 90cf b1f5
 来自       : https://www.mongodb.org/static/pgp/server-4.4.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : cyrus-sasl-2.1.26-23.el7.x86_64                            1/10 
  正在安装    : mongodb-org-database-tools-extra-4.4.6-1.el7.x86_64        2/10 
  正在安装    : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64                     3/10 
  正在安装    : mongodb-org-shell-4.4.6-1.el7.x86_64                       4/10 
  正在安装    : cyrus-sasl-plain-2.1.26-23.el7.x86_64                      5/10 
  正在安装    : mongodb-database-tools-100.3.1-1.x86_64                    6/10 
  正在安装    : mongodb-org-tools-4.4.6-1.el7.x86_64                       7/10 
  正在安装    : mongodb-org-server-4.4.6-1.el7.x86_64                      8/10 
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
  正在安装    : mongodb-org-mongos-4.4.6-1.el7.x86_64                      9/10 
  正在安装    : mongodb-org-4.4.6-1.el7.x86_64                            10/10 
  验证中      : mongodb-database-tools-100.3.1-1.x86_64                    1/10 
  验证中      : mongodb-org-4.4.6-1.el7.x86_64                             2/10 
  验证中      : mongodb-org-mongos-4.4.6-1.el7.x86_64                      3/10 
  验证中      : mongodb-org-server-4.4.6-1.el7.x86_64                      4/10 
  验证中      : cyrus-sasl-plain-2.1.26-23.el7.x86_64                      5/10 
  验证中      : mongodb-org-shell-4.4.6-1.el7.x86_64                       6/10 
  验证中      : mongodb-org-tools-4.4.6-1.el7.x86_64                       7/10 
  验证中      : cyrus-sasl-gssapi-2.1.26-23.el7.x86_64                     8/10 
  验证中      : mongodb-org-database-tools-extra-4.4.6-1.el7.x86_64        9/10 
  验证中      : cyrus-sasl-2.1.26-23.el7.x86_64                           10/10 

已安装:
  mongodb-org.x86_64 0:4.4.6-1.el7                                              

作为依赖被安装:
  cyrus-sasl.x86_64 0:2.1.26-23.el7                                             
  cyrus-sasl-gssapi.x86_64 0:2.1.26-23.el7                                      
  cyrus-sasl-plain.x86_64 0:2.1.26-23.el7                                       
  mongodb-database-tools.x86_64 0:100.3.1-1                                     
  mongodb-org-database-tools-extra.x86_64 0:4.4.6-1.el7                         
  mongodb-org-mongos.x86_64 0:4.4.6-1.el7                                       
  mongodb-org-server.x86_64 0:4.4.6-1.el7                                       
  mongodb-org-shell.x86_64 0:4.4.6-1.el7                                        
  mongodb-org-tools.x86_64 0:4.4.6-1.el7                                        

完毕
Copy the code

2. Verify the installation result

Run the following command to obtain the installation package

rpm -qa | grep mongodb
Copy the code

Run the following command to obtain the installation path

rpm -ql mongodb-org-server
Copy the code

The execution process is as follows:

[renZ ~] # RPM - qa | grep mongo mongo - org - the shell - 4.4.6-1. El7. X86_64 mongo - org - server - 4.4.6-1. El7. X86_64 Mongo - org - tools - 4.4.6-1. El7. X86_64 mongo - org - mongos - 4.4.6-1. El7. X86_64 Mongo - org - database - tools - extra - 4.4.6-1. El7. X86_64 mongo database - tools - 100.3.1-1. X86_64 Mongodb -org-4.4.6-1.el7.x86_64 [renZ ~]# RPM -ql mongodb-org-server /etc/mongod.conf /run/mongodb /usr/bin/mongod The/usr/lib/systemd/system/mongod. Service/usr/share/doc/mongo - org - server - 4.4.6 The/usr/share/doc/mongo - org - server - 4.4.6 / LICENSE - Community. TXT/usr/share/doc/mongo - org - server - 4.4.6 / MPL - 2 The/usr/share/doc/mongo - org - server - 4.4.6 / README/usr/share/doc/mongo - org - server - 4.4.6 / THIRD - PARTY - NOTICES /usr/share/man/man1/mongod.1.gz /var/lib/mongo /var/log/mongodb /var/log/mongodb/mongod.logCopy the code

3. Start the service

Starting the MongoDB Service

systemctl start mongod.service
Copy the code

The default MongoDB port is 27017. Check whether the MongoDB port is enabled

netstat -natp | grep 27017
Copy the code

Check whether the database is installed successfully

Ps - aux | grep mongod # to check the database process existsCopy the code

Implementation process

[rZ ~] # systemctl start mongod. Service/rZ ~ # netstat natp | grep TCP 27017 0 0 127.0.0.1:27017 0.0.0.0: * LISTEN 21255 / mongod/rZ ~ # ps - aux | grep mongod mongod 21255 1552004 65052 3.3 3.4? Sl 13:20 0:05 /usr/bin/mongod -f /etc/mongod. Conf root 22373 0.0 0.0 112728 976 PTS /1 S+ 13:23:00 grep --color=auto mongod [rZ ~]#Copy the code

4. Verify that the service is enabled

mongo
Copy the code

Implementation process

[rZ ~] # mongo mongo shell version v4.4.6 connecting to: mongo: / / 127.0.0.1:27017 /? compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("cf367eda-8002-4dbb-9b14-493f251a31a6") } MongoDB server version: 4.4.6 Welcome to the MongoDB shell. For interactive help, type "help". see https://docs.mongodb.com/ Questions? Try the MongoDB Developer Community Forums https://community.mongodb.com --- The server generated these startup warnings when booting: 2021-05-24T13:20:26.974+08:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See The T13:2021-05-24 http://dochub.mongodb.org/core/prodnotes-filesystem fell. 935 + 08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted The T13:2021-05-24 fell. 936 + 08:00: / sys/kernel/mm/transparent_hugepage/enabled is' always'. We suggest setting it to 2021-05-24 T13: 'never' fell. 936 + 08:00:  /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never' --- --- Enable MongoDB's free cloud-based monitoring service, which will then receive and display metrics about your deployment (disk utilization, CPU, operation statistics, etc). The monitoring data will be available on a MongoDB website with a unique URL accessible to you and anyone you share the URL with. MongoDB may use this information to make product improvements and to suggest MongoDB products and deployment options to you. To enable free monitoring, run the following command: db.enableFreeMonitoring() To permanently disable this reminder, run the following command: db.disableFreeMonitoring() --- >Copy the code

5. List of common commands

MongoDB sudo chkconfig mongod on // 1, MongoDB sudo chkconfig mongod on // run the following command to restart the MongoDB service: // run the following command to restart the MongoDB service $(RPM - qa | grep mongo - org) # uninstall mongo sudo rm - r/var/log/mongo sudo rm # delete log files - r/var/lib/mongo # delete data fileCopy the code

4. Remotely connect to Mongodb

1. Modify the mongodb

vi /etc/mongod.conf
Copy the code
# network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.Copy the code

Change the binding IP address 127.0.0.1 by default, only local connections are allowed. Therefore, change the binding IP address to bindIp:0.0.0.0 and exit

2. Restart the mongodb service

sudo service mongod restart 
Copy the code

3. Open external ports

iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
Copy the code

4. Security port of Ali Cloud server

PS: In fact, after this is opened, we need to open the security port on ali Cloud server, so that we can really access the external world and configure the security group rules.

5. MongoDB Compass visual operation

Read more

  • (57) How to flatten an array?

  • Depth first traversal and breadth first traversal.

  • (55题) To achieve a full array of arrays

  • 2020 “Songbao Write Code” personal year-end summary: the future can be expected

Previous “Question of the Day”

1. JavaScript && ES6

  • 57. What are the methods of flattening an array?

  • (47) In which scenarios does memory leak exist in JS?

  • 第 46题 : What are the traversal methods in JavaScript?

  • 第 41题 : How does JS code get compressed?

  • 40. What do you not know about the script tag?

  • 第 39题 : What is the function extension of JS?

  • Interviewer :ES6 deconstruction of the value of the understanding?

  • Interviewer: What is the difference between prototype chain and constructor combination method inheritance and primitive type inheritance?

  • Interviewer: What is the main difference between var and const,let?

  • Interviewer: What about the binding of this in JS?

  • Q: What about the understanding of webSockets in JS?

  • Q: What do you understand about XMLHttpRequest objects in JAVASCRIPT?

  • Question 18: Ajax in JS extends Comet across domains?

  • Q: What is the understanding of event flow, event handler and event object in JS?

  • 第 16 题 : How to perform client detection comprehensively in JS?

  • Interviewer: What are the methods for judging the JS type?

  • Interviewer: Tell me about your creation and extension of JS objects

  • [‘1’, ‘2’, ‘3’]. Map (parseInt) output, the reason, and the extension?

  • Q: What is the execution process of the JS engine?

  • Q: What is the execution process of JS engine?

  • Q: Tell me more about the JS data type

  • Q: What is your understanding of ES6 proxy?

  • Interviewer: What is the difference between “for in” and “for of”?

  • 6. How can Async/Await Async/Await Async?

  • 3. “Question of the Day” The interviewer asks you what you think of Promise?

  • In ES6, why do we use Symbol?

2. Browser

  • 9. Doesn’t requestAnimationFrame smell good?

3, Vue

  • How does VUE data binding work?

4, the React

  • React Hooks compare to Vue3.0 Function based API.

5, HTML 5

  • 第 29题 : What is the new attribute of htML-HTML5?

6, algorithm

  • 第 56题 : How to implement depth-first traversal and breadth-first traversal?

  • 54. (54) Maximum suborder sum

  • A pair of k-diff numbers in an array

  • 第 52题 : Merge two ordered arrays

  • 第 51题 : Maximum suborder sum

  • 第 50题 : The number III appears only once

  • 第 49题 (49题) Algorithm: the number II appears only once

  • 第 48题 : A number that appears only once

  • 第 45 道【每日一题】(45题)编程题:如何实现strStr()

  • 第 44题 : Split palindrome strings

  • Interviewer: How much do you know about graph theory? (7)

  • Interviewer: What do you know about graph theory? (6)

  • Interviewer: What do you know about graph theory? (5)

  • Interviewer: What do you know about graph theory? (4)

  • Interviewer: What do you know about graph theory? (3)

  • Interviewer: What do you know about graph theory? (2)

  • Interviewer: What do you know about graph theory?

  • 第 27题 (27题) Algorithm: How to use multiple solutions to achieve a jump game?

  • 第 26题 : What is the longest common prefix?

  • 第 25题 : Heap data structure – the first K high frequency elements?

  • 第 24题 【 daily 1 题】(24题) Algorithm: Greedy algorithm – how to fuel around the world?

  • Question 4: How to find repetitive elements in a scientific and efficient way?

7, the Node

  • 第 23题 : Describe the Event Loop in detail?

8, Http

  • 1. “How does an interview question trigger deep soul searching?”

  • (42) What is your understanding of Http2.0?

  • Question 43 (43) How do I use Http2.0 in my projects?

9. Year-end review

  • 2020 “Songbao Write Code” personal year-end summary: the future can be expected

Thank you for your support

1, if you like the article, you can “share, like, favorites” three even oh.

2, author nickname: SaucXS, songEagle, Songbao write code. Author of songbao Write Code, one of the day, lab, etc. A bytedance engineer who loves to toss, is committed to the whole stack, and is working hard to grow, star Sea, the future can be expected. Inside push bytedance each department each post.

3, pay attention to “Songbao write code”, is to acquire development knowledge system construction, selected articles, project actual combat, laboratory, a daily interview question, advanced learning, thinking about career development, involving JavaScript, Node, Vue, React, browser, HTTP, algorithm, end related, small program and other fields, hope to help you. We grow up together