Linux環境下安裝MongoDB

下載安裝包linux

下載地址:https://www.mongodb.com/download-center/communitymongodb

curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.5.tgz數據庫

 

實驗步驟瀏覽器

解壓MongoDBcurl

tar -zxvf mongodb-linux-x86_64-rhel70-4.2.5.tgz -C /usr/local/tcp

把下面的配置加到環境變量中 ,進入profile配置文件目錄,使用了這條配置下面的啓動命令前面是不用加./ 的 如mongodb服務的啓動命令 mongod  -f  mongodb.conf測試

[root@localhost ~]# vi /etc/profileurl

把這條複製到profile配置文件中  注意目錄要對應安裝的目錄spa

export PATH=/usr/local/mongodb-linux-x86_64-rhel70-4.2.5/bin:$PATH日誌

 

使修改生效

[root@localhost ~]# source /etc/profile

 

建立MongoDB數據存儲位置

mkdir /home/data

建立MongoDB日誌存儲位置

mkdir /home/log

 

mongodb 的默認的配置文件mongodb-linux-x86_64-rhel70-4.2.5目錄下

進入mongodb-linux-x86_64-rhel70-4.2.5目錄下編輯mongodb的配置文件

[root@localhost bin]# cd /usr/local/mongodb-linux-x86_64-rhel70-4.2.5/

[root@service mongodb-linux-x86_64-rhel70-4.2.5]# vi mongodb.conf

 

配置文件以下

# mongodb 配置文件 port=27017 #端口 bind_ip=0.0.0.0 #默認是127.0.0.1 dbpath=/home/data #數據庫存放 logpath=/home/log/mongodb.log #日誌文件 fork=true #設置後臺運行 #auth=true #開啓認證

 

 注意:查看數據庫存放目錄和存放日誌目錄是否存在,不存在啓動服務是報錯的!

 

啓動mongod數據庫服務,以配置文件的方式啓動

[root@service mongodb-linux-x86_64-rhel70-4.2.5]# ./mongod  -f  mongodb.conf

或者 mongod -f mongodb.conf

查進程

[root@localhost bin]# ps -aux|grep mongod

 

啓動成功效果圖

 

 

 

 

 

 

查看MongoDB 的日誌記錄

[root@localhost ~]# mongod --dbpath /home/data

 

客戶端鏈接MongoDB

[root@localhost ~]# ./mongo    或者mongo

指定ip和端口 或者

[root@service ~]# mongo mongodb://localhost:27017

 

配置防火牆

# 放行 27017 端口號 使用默認的
firewall-cmd --zone=public --add-port=27017/tcp --permanent
# 查看放行端口號
firewall-cmd --list-ports
# 重啓防火牆
firewall-cmd --reload

 

瀏覽器輸入本機ip地址測試

 

若有不足的地方請多多指教哈,不清楚地方下方留言哦,歇歇來訪問!

相關文章
相關標籤/搜索