Centos8.x 下安裝mongodb4.2
1、切換的src目錄,下載包檔案解壓後,改名並遷移到 /usr/local/mongodb ,
建立執行mongodb的使用者、組,建立存放資料、日、執行pid的目錄,並改成所屬使用者、組為mongodb
cd /usr/local/src
wgetwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.2.11.tgz
tar xvzfmongodb-linux-x86_64-rhel80-4.2.11.tgz
mv mongodb-linux-x86_64-rhel80-4.2.11/usr/local/mongodb
cd /usr/local/mongodb
groupadd mongodb
useradd -s /sbin/nologin -g mongodb -M mongodb
mkdir data log run
chown -R mongodb:mongodb data log run
2、在/usr/local/mongodb 裡面建立一個配置檔案 mongodb.conf
vi mongodb.conf 並寫入下面的資訊:
bind_ip=0.0.0.0
port=27017
dbpath=/usr/local/mongodb/data/
logpath=/usr/local/mongodb/log/mongodb.log
pidfilepath =/usr/local/mongodb/run/mongodb.pid
logappend=true
fork=true
maxConns=500
noauth = true
3、註冊服務vi /usr/lib/systemd/system/mongodb.service
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongodb.conf
PrivateTmp=
true
[Install]
WantedBy=multi-user.target
4、這是開機啟動,並啟動。
systemctl daemon-reload
systemctl enable mongodb
systemctl start mongodb
如果需要停止,就執行:
systemctl stop mongodb
檢視狀態:
systemctl status mongodb
5、配置mongodb為環境變數,方便直接在shell中操作
vi /etc/profile
在/etc/profile檔案末尾新增一行:
export PATH=/usr/local/mongodb/bin:$PATH
讓其生效:
source /etc/profile
6、檢視當前mongodb的版本:
mongod --version