下載安裝包 下載地址:https://www.mongodb.com/download-center/community curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.5.tgz 實驗步驟 解壓Mon ...
下載安裝包
下載地址:https://www.mongodb.com/download-center/community
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.5.tgz
實驗步驟
解壓MongoDB
tar -zxvf mongodb-linux-x86_64-rhel70-4.2.5.tgz -C /usr/local/
把下麵的配置加到環境變數中 ,進入profile配置文件目錄,使用了這條配置下麵的啟動命令前面是不用加./ 的 如mongodb服務的啟動命令 mongod -f mongodb.conf
[root@localhost ~]# vi /etc/profile
把這條複製到profile配置文件中 註意目錄要對應安裝的目錄
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地址測試
如有不足的地方請多多指教哈,不清楚地方下方留言哦,歇歇來訪問!