Linux-CentOS下mongodb安裝和啟動配置


Linux:CentOS下mongodb安裝和啟動配置

1.下載安裝包
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.9.tgz
下載完成后解壓縮壓縮包
tar zxf mongodb-linux-x86_64-2.6.9.tgz

2. 安裝准備
將mongodb移動到/usr/local/server/mongdb文件夾
mv mongodb-linux-x86_64-2.6.9 /usr/local/mongodb

創建數據庫文件夾與日志文件
mkdir /usr/local/mongodb/data
touch /usr/local/mongodb/logs

3. 設置開機自啟動
將mongodb啟動項目追加入rc.local保證mongodb在服務器開機時啟動
echo "/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data –logpath=/usr/local/mongodb/logs –logappend --auth –port=27017" >> /etc/rc.local

4. 啟動mongodb
cd到mongodb目錄下的bin文件夾啟動mongodb
//下面這個是需要權限的登錄方式, 用戶連接需要用戶名和密碼
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --auth --port=27017 --fork

//這個是不需要密碼的
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --port=27017 --fork

5. 進入數據庫的CLI管理界面
cd到mongodb目錄下的bin文件夾,執行命令./mongo
運行如下:
[root@namenode mongodb]# ./bin/mongo

 

6. 參數解釋: --dbpath 數據庫路徑(數據文件)
--logpath 日志文件路徑
--master 指定為主機器
--slave 指定為從機器
--source 指定主機器的IP地址
--pologSize 指定日志文件大小不超過64M.因為resync是非常操作量大且耗時,最好通過設置一個足夠大的oplogSize來避免resync(默認的 oplog大小是空閑磁盤大小的5%)。
--logappend 日志文件末尾添加
--port 啟用端口號
--fork 在后台運行
--only 指定只復制哪一個數據庫
--slavedelay 指從復制檢測的時間間隔
--auth 是否需要驗證權限登錄(用戶名和密碼)
 
-h [ --help ]             show this usage information
--version                 show version information
-f [ --config ] arg       configuration file specifying additional options
--port arg                specify port number
--bind_ip arg             local ip address to bind listener - all local ips
                           bound by default
-v [ --verbose ]          be more verbose (include multiple times for more
                           verbosity e.g. -vvvvv)
--dbpath arg (=/data/db/) directory for datafiles    指定數據存放目錄
--quiet                   quieter output   靜默模式
--logpath arg             file to send all output to instead of stdout   指定日志存放目錄
--logappend               appnd to logpath instead of over-writing 指定日志是以追加還是以覆蓋的方式寫入日志文件
--fork                    fork server process   以創建子進程的方式運行
--cpu                     periodically show cpu and iowait utilization 周期性的顯示cpu和io的使用情況
--noauth                  run without security 無認證模式運行
--auth                    run with security 認證模式運行
--objcheck                inspect client data for validity on receipt 檢查客戶端輸入數據的有效性檢查
--quota                   enable db quota management   開始數據庫配額的管理
--quotaFiles arg          number of files allower per db, requires --quota 規定每個數據庫允許的文件數
--appsrvpath arg          root directory for the babble app server 
--nocursors               diagnostic/debugging option 調試診斷選項
--nohints                 ignore query hints 忽略查詢命中率
--nohttpinterface         disable http interface 關閉http接口,默認是28017
--noscripting             disable scripting engine 關閉腳本引擎
--noprealloc              disable data file preallocation 關閉數據庫文件大小預分配
--smallfiles              use a smaller default file size 使用較小的默認文件大小
--nssize arg (=16)        .ns file size (in MB) for new databases 新數據庫ns文件的默認大小
--diaglog arg             0=off 1=W 2=R 3=both 7=W+some reads 提供的方式,是只讀,只寫,還是讀寫都行,還是主要寫+部分的讀模式
--sysinfo                 print some diagnostic system information 打印系統診斷信息
--upgrade                 upgrade db if needed 如果需要就更新數據庫
--repair                  run repair on all dbs 修復所有的數據庫
--notablescan             do not allow table scans 不運行表掃描
--syncdelay arg (=60)     seconds between disk syncs (0 for never) 系統同步刷新磁盤的時間,默認是60s
 
Replication options:
--master              master mode 主復制模式
--slave               slave mode 從復制模式
--source arg          when slave: specify master as <server:port> 當為從時,指定主的地址和端口
--only arg            when slave: specify a single database to replicate 當為從時,指定需要從主復制的單一庫
--pairwith arg        address of server to pair with
--arbiter arg         address of arbiter server 仲裁服務器,在主主中和pair中用到
--autoresync          automatically resync if slave data is stale 自動同步從的數據
--oplogSize arg       size limit (in MB) for op log 指定操作日志的大小
--opIdMem arg         size limit (in bytes) for in memory storage of op ids指定存儲操作日志的內存大小
 
Sharding options:
--configsvr           declare this is a config db of a cluster 指定shard中的配置服務器
--shardsvr            declare this is a shard db of a cluster 指定shard服務器

 參考資料:http://blog.csdn.net/yuwenruli/article/details/8529192

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM