Centos7源碼安裝MongoDB-3.6
MongoDB 是一個介於關系數據庫和非關系數據庫之間的產品,是非關系數據庫當中功能最豐富,最像關系數據庫的。他支持的數據結構非常松散,是類似json的bson格式,因此可以存儲比較復雜的數據類型。Mongo最大的特點是他支持的查詢語言非常強大,其語法有點類似於面向對象的查詢語言,幾乎可以實現類似關系數據庫單表查詢的絕大部分功能,而且還支持對數據建立索引。
Packages包說明
MongoDB官方源中包含以下幾個依賴包:
mongodb-org: MongoDB元數據包,安裝時自動安裝下面四個組件包:
1、mongodb-org-server: 包含MongoDB守護進程和相關的配置和初始化腳本。
2、mongodb-org-mongos: 包含mongos的守護進程。
3、mongodb-org-shell: 包含mongo shell。
4、mongodb-org-tools: 包含MongoDB的工具: mongoimport, bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop。
實驗環境
系統版本:centos7x3.10.0-514.el7.x86_64
mongodb版本:mongodb-linux-x86_64-rhel70-3.6.6
關閉防火墻並禁止開機自啟
systemctl stop firewalld.service
systemctl disable firewalld
關閉selinux
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/sysconfig/selinux
重啟 reboot
安裝MongoDB
Mongodb官網
Mongodb使用教程
Mongodb源碼下載
註:根據需求下載源碼包即可!
1、前往Mongodb官網下載安裝包(以下截圖為下載路徑)
//進入Mongodb官網(一定要使用兼容的瀏覽器否則可能打不開,例如火狐、谷歌等)
//單擊選擇社區服務器和linux系統
//單擊左下方“Version下拉菜單”選擇適合的版本
//最後根據需求下載指定版本的二進制文件並上傳到服務器即可
2、解壓Mongodb
1)查看壓縮包 ls
2)解壓mongodb-linux-x86_64-rhel70-3.6.6.tgz到指定目錄
tar zxf mongodb-linux-x86_64-rhel70-3.6.6.tgz -C /usr/local/
3)進入解壓目錄
cd /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/
3、創建Mongodb數據存儲目錄和日誌存放目錄
mkdir db log
註:這兩個目錄在後邊的配置文件中會用到!
4、編寫MongoDB配置文件
vi /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongodb.conf
systemLog:
destination: file
path: "/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/log/mongodb.log"
logAppend: true
storage:
dbPath: "/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/db/"
journal:
enabled: true
processManagement:
fork: true
pidFilePath: "/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/mongodb.pid"
net:
port: 27017
setParameter:
enableLocalhostAuthBypass: false
註:這塊可能有童鞋就會問了?你這mongodb.pid是什麽文件?怎麽沒有呢?別著急這pid文件你可以理解成服務啟動或者關閉時的進程代號。為啥沒有找到這個文件呢?是因為這個文件默認源碼安裝不存在,我們提前寫好路徑是為了之後啟動mongodb時,系統會自動按照這個路徑去創建這個pid文件。
5、創建mongodb啟動的腳本
vi /etc/init.d/mongodb
#!/bin/sh
#chkconfig: 2345 80 90
#description: mongodb
start() {
/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongod -f /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongodb.conf
}stop() {
/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongod -f /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin/mongodb.conf --shutdown
}case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
6、給mongodb啟動腳本執行權限
chmod +x /etc/init.d/mongodb
7、設置啟動服務
1)將mongodb設置開機自啟
chkconfig --level 35 mongodb on
2)將mongodb註冊為系統服務
chkconfig --add mongodb
3)啟動mongodb服務
/etc/init.d/mongodb start
4)停止mongodb服務
/etc/init.d/mongodb stop
5)重啟mongodb服務
/etc/init.d/mongodb restart
8、開啟防火墻,打開27017端口
1)開啟防火墻
systemclt start firewalld
2)永久打開27017端口
firewall-cmd --add-port=27017/tcp --permanent
3)重啟防火墻使配置生效
systemctl restart firewalld
4)查看是否生效
firewall-cmd --list-all
9、配置環境變量
1)編輯環境變量並在最後添加一行文件如下
vi /etc/profile
export PATH=$PATH:/usr/local/mongodb-linux-x86_64-rhel70-3.6.6/bin
2)執行環境變量
source /etc/profile
10、測試mongodb是否安裝成功
1)使用mongo命令進入到mongodb控制臺
2)切換數據庫管理用戶
use admin
註:到這裏就完成了mongodb數據庫的源碼搭建!
Centos7源碼安裝MongoDB-3.6