1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| 一、下载源码包: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-6.0.0.tgz
二、安装mongodb
1、解压 放到 /usr/local/ 目录下 tar -zxvf mongodb-linux-x86_64-rhel80-6.0.0.tgz mv mongodb-linux-x86_64-rhel80-6.0.0 /usr/local/mongodb
2、切换目录 cd /usr/local/mongodb
3、在当前路径【/usr/local/mongodb】下创建文件夹 mkdir -p ./data/db mkdir ./logs
4、进入/usr/local/mongodb/bin 目录下,创建配置文件 vi mongodb.conf
dbpath = /usr/local/mongodb/data/db #数据文件存放目录 logpath = /usr/local/mongodb/logs/mongodb.log #日志文件存放目录 port = 27017 #端口 fork = true #以守护程序的方式启用,即在后台运行 nohttpinterface = true auth=true #建议练习条件下为false 认证字段 bind_ip=0.0.0.0 #监听绑定的IP
5、进行环境变量配置, 打开配置文件 /etc/profile vi /etc/profile
在后面添加一条语句 添加这条语句:export PATH=/usr/local/mongodb/bin:$PATH
配置文件生效:source /etc/profile
三、设置开机启动 添加开机启动服务 [root@localhost bin]# vi /etc/systemd/system/mongodb.service
复制粘贴以下内容: [Unit] Description=mongodb-service After=network.target
[Service] Type=forking ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf PrivateTmp=true
[Install] WantedBy=multi-user.target
设置开机启动 [root@localhost bin]# systemctl daemon-reload [root@localhost bin]# systemctl start mongodb.service [root@localhost bin]# systemctl enable mongodb.service
四、测试连接mongodb [root@localhost ~]# mongo 127.0.0.1:27017 MongoDB shell version v4.0.6 connecting to: mongodb://127.0.0.1:27017/test?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("d0d45a69-84b7-4fba-bead-60ea89c49ac0") } MongoDB server version: 6.0.0 WARNING: shell and server versions do not match > use test switched to db test >
|