Toggle navigation
Home
安装部署
Archives
Tags
Mongodb Deployment
2022-01-29 08:12:55
24
0
0
louyj
#Install MongoDB Community Edition MongoDB only supports the 64-bit versions of these platforms. Follow these steps to install MongoDB Community Edition using the yum package manager. Create a `/etc/yum.repos.d/mongodb-org-4.4.repo` file so that you can install MongoDB directly using `yum`: ``` [mongodb-org-4.4] name=MongoDB 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.asc ``` To install the latest stable version of MongoDB, issue the following command: sudo yum install -y mongodb-org Alternatively, to install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example: sudo yum install -y mongodb-org-4.4.11 mongodb-org-server-4.4.11 mongodb-org-shell-4.4.11 mongodb-org-mongos-4.4.11 mongodb-org-tools-4.4.11 You can specify any available version of MongoDB. However yum upgrades the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To pin a package, add the following exclude directive to your /etc/yum.conf file: exclude=mongodb-org,mongodb-org-database,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools #Run MongoDB Community Edition ##Prerequisites Most Unix-like operating systems limit the system resources that a process may use. These limits may negatively impact MongoDB operation, and should be adjusted On Linux, you can change ulimit settings by issuing a command in the following form: ulimit -n <value> You should typically start mongod using systemctl, which uses the ulimit settings Prepare data directory ``` mkdir -p /data/mongodb/data mkdir -p /data/mongodb/log chown -R mongod:mongod /data/mongodb ``` Configure SELinux if enforced ``` sestatus setenforce Permissive vi /etc/selinux/config SELINUX=permissive ``` ##Configure Mongodb Edit the configuration file `/etc/mongod.conf` and modify the following fields accordingly: ``` systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log storage: dbPath: /var/lib/mongo net: port: 27017 bindIp: 127.0.0.1 ``` ##Run Mongodb You can start the mongod process by issuing the following command: sudo systemctl start mongod You can verify that the mongod process has started successfully by issuing the following command: sudo systemctl status mongod #Begin using MongoDB Start a mongo shell on the same host machine as the mongod. You can run the mongo shell without any command-line options to connect to a mongod that is running on your localhost with default port 27017: mongo Within the shell, db refers to your current database. Type db to display the current database. db to switch databases, type use <db>. For example, to switch to the examples database: use examples You do not need to create the database before you switch. MongoDB creates the database when you first store data in that database #Convert a Standalone to a Replica Set Shut down the standalone mongod instance. service mongod stop Edit service config ``` vi /usr/lib/systemd/system/mongod.service; Environment="OPTIONS=-f /etc/mongod.conf --replSet rs0" ``` If your application connects to more than one replica set, each set must have a `distinct name`. then start service systemctl daemon-reload service mongod start Connect a mongo shell to the mongod instance. mongo Use `rs.initiate()` to initiate the new replica set: rs.initiate() The replica set is now operational. To view the replica set configuration, use `rs.conf()`. To check the status of the replica set, use `rs.status()`. To add members to this replica set, use the `rs.add()` method.
Pre:
Hadoop Ecosystem Deployment
Next:
install kubectl plugins
0
likes
24
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.