2020-09-29

centos7安装Mongodb4.2.9版本

访问Mongodb官网https://www.mongodb.com/try/download/community,右侧有选择项,这里选择centos7+tgz+4.2.9选择项。

[root@guangzhou src]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.9.tgz--2020-09-29 15:01:18-- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.9.tgz正在解析主机 fastdl.mongodb.org (fastdl.mongodb.org)... 204.246.164.124, 204.246.164.81, 204.246.164.16, ...正在连接 fastdl.mongodb.org (fastdl.mongodb.org)|204.246.164.124|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:132776427 (127M) [application/gzip]正在保存至: "mongodb-linux-x86_64-rhel70-4.2.9.tgz"100%[========================================================================================>] 132,776,427 9.48MB/s 用时 14s2020-09-29 15:01:33 (9.37 MB/s) - 已保存 "mongodb-linux-x86_64-rhel70-4.2.9.tgz" [132776427/132776427])[root@guangzhou src]# tar zxvf mongodb-linux-x86_64-rhel70-4.2.9.tgz[root@guangzhou src]# mv mongodb-linux-x86_64-rhel70-4.2.9 /usr/local/mongodb[root@guangzhou src]# cd /usr/local/mongodb/[root@guangzhou mongodb]# mkdir -p ./data/db[root@guangzhou mongodb]# mkdir log[root@guangzhou mongodb]# mv log logs[root@guangzhou mongodb]# touch ./logs/mongodb.log

新建配置文件:

[root@guangzhou mongodb]# vim mongodb.conf#端口号port=27017#db目录dbpath=/usr/local/mongodb/data/db#日志目录logpath=//usr/local/mongodb/logs/mongodb.log#后台fork=true#日志输出logappend=true#允许远程IP连接bind_ip=0.0.0.0

 

启动mongodb:

[root@guangzhou mongodb]# ./bin/mongod --config mongodb.confabout to fork child process, waiting until server is ready for connections.forked process: 17024child process started successfully, parent exiting

 

连接mongodb:

[root@guangzhou mongodb]# ./bin/mongoMongoDB shell version v4.2.9connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodbImplicit session: session { "id" : UUID("2e0543e1-1f66-44cf-bfd3-3af38f6abe80") }MongoDB server version: 4.2.9Server has startup warnings:2020-09-29T15:03:49.377+0800 I STORAGE [initandlisten]2020-09-29T15:03:49.377+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine2020-09-29T15:03:49.377+0800 I STORAGE [initandlisten] **   See http://dochub.mongodb.org/core/prodnotes-filesystem2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten] **   Read and write access to data and configuration is unrestricted.2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2020-09-29T15:03:50.166+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] **  We suggest setting it to 'never'2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] **  We suggest setting it to 'never'2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 100001 files. Number of processes should be at least 50000.5 : 0.5 times number of files.2020-09-29T15:03:50.167+0800 I CONTROL [initandlisten]---Enable MongoDB's free cloud-based monitoring service, which will then receive and displaymetrics 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 youand anyone you share the URL with. MongoDB may use this information to make productimprovements 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()---#选择数据库> use adminswitched to db admin> show databases;admin 0.000GBconfig 0.000GBlocal 0.000GB
#创建root用户> db.createUser({user:"root",pwd:"freedom",roles:[{role:"userAdminAnyDatabase",db:"admin"},"readWriteAnyDatabase"]})Successfully added user: { "user" : "root", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" }, "readWriteAnyDatabase" ]}

 

断开重联链接输入验证信息:

[root@guangzhou mongodb]# ./bin/mongo> use adminswitched to db admin> db.auth('root','freedom')1

 

配置service文件:

[root@guangzhou mongodb]# touch /usr/lib/systemd/system/mongod.service[Unit]Description=mongodbAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/conf/mongodb.confUser=rootGroup=rootPrivateTmp=trueRestart=alwaysRestartSec=1

 

重启systemd服务,启动mongodb:

[root@guangzhou mongodb]# chmod +x /usr/lib/systemd/system/mongod.service[root@guangzhou mongodb]# systemctl daemon-reload[root@guangzhou ~]# systemctl status mongod● mongod.service - mongodb Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled) Active: active (running) since 二 2020-09-29 15:44:53 CST; 5s ago Process: 25525 ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf (code=exited, status=0/SUCCESS) Main PID: 25527 (mongod) CGroup: /system.slice/mongod.service   └─25527 /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf9月 29 15:44:52 guangzhou systemd[1]: Starting mongodb...9月 29 15:44:52 guangzhou mongod[25525]: about to fork child process, waiting until server is ready for connections.9月 29 15:44:52 guangzhou mongod[25525]: forked process: 255279月 29 15:44:53 guangzhou mongod[25525]: child process started successfully, parent exiting9月 29 15:44:53 guangzhou systemd[1]: Started mongodb.[root@guangzhou ~]# systemctl stop mongod[root@guangzhou ~]# systemctl status mongod● mongod.service - mongodb Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled) Active: inactive (dead)9月 29 15:33:54 guangzhou systemd[1]: Unit mongod.service entered failed state.9月 29 15:33:54 guangzhou systemd[1]: mongod.service failed.9月 29 15:44:52 guangzhou systemd[1]: Starting mongodb...9月 29 15:44:52 guangzhou mongod[25525]: about to fork child process, waiting until server is ready for connections.9月 29 15:44:52 guangzhou mongod[25525]: forked process: 255279月 29 15:44:53 guangzhou mongod[25525]: child process started successfully, parent exiting9月 29 15:44:53 guangzhou systemd[1]: Started mongodb.9月 29 15:45:04 guangzhou systemd[1]: Stopping mongodb...9月 29 15:45:04 guangzhou mongod[25625]: killing process with pid: 255279月 29 15:45:05 guangzhou systemd[1]: Stopped mongodb.

 客户端快捷方式创建:

[root@guangzhou mongodb]# ln -s /usr/local/mongodb/bin/mongo /usr/local/bin/mongo[root@guangzhou mongodb]# mongo -versionMongoDB shell version v4.2.9git version: 06402114114ffc5146fd4b55402c96f1dc9ec4b5OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013allocator: tcmallocmodules: nonebuild environment:distmod: rhel70distarch: x86_64target_arch: x86_64

 开机启动mongodb:   systemctl enable mongod

手动启动mongodb:systemctl start mongod

停止mongodb:   systemctl stop mongod

查看运行状态:  systemctl status mongod

 

原文转载:http://www.shaoqun.com/a/478764.html

赛兔:https://www.ikjzd.com/w/2375

tracker:https://www.ikjzd.com/w/2720

俄罗斯灰色清关:https://www.ikjzd.com/w/1409


访问Mongodb官网https://www.mongodb.com/try/download/community,右侧有选择项,这里选择centos7+tgz+4.2.9选择项。[root@guangzhousrc]#wgethttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.9.tgz--2020-09-2915:0
李群:https://www.ikjzd.com/w/1767
google趋势:https://www.ikjzd.com/w/397
美国对关税清单做出第二轮调整,这些产品被移除!:https://www.ikjzd.com/home/104942
大屠杀历史重演!30亿大卖遭遇亚马逊封店:https://www.ikjzd.com/home/96193
继安克创新之后,爱淘城股票终止挂牌新三板!:https://www.ikjzd.com/home/5697

No comments:

Post a Comment