官方网站传贴,每次去翻doc,麻烦
vi /etc/yum.repos.d/mongodb-org-3.0.repo
[mongodb-org-3.0]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1
sudo yum install -y mongodb-org
#sudo yum install -y mongodb-org-3.0.7 mongodb-org-server-3.0.7 mongodb-org-shell-3.0.7 mongodb
vi /etc/selinux/config
SELINUX=disabled
#SELINUX=permissive
#卸载
sudo yum erase $(rpm -qa | grep mongodb-org)
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo
-------偷懒----
wget: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1410-clang-3.0.3.tgz
tar -zxvf mongodb.tgz
目录层次
~/mongodb
m/data
s1/data
s2/data
a/data
log
config:
#master.conf
dbpath=~/mongodb/m/data
logpath=~/mongodb/log/m.log
pidfilepath=~/mongodb/m.pid
directoryperdb=true
logappend=true
replSet=virus
port=27017
oplogSize=10000
fork=true
noprealloc=true
#slaver.conf
dbpath=~/mongodb/s1/data
logpath=~/mongodb/log/s1.log
pidfilepath=~/mongodb/s1.pid
directoryperdb=true
logappend=true
replSet=virus
port=27018
oplogSize=10000
fork=true
noprealloc=true
#slaver.conf
dbpath=~/mongodb/s2/data
logpath=~/mongodb/log/s2.log
pidfilepath=~/mongodb/s2.pid
directoryperdb=true
logappend=true
replSet=virus
port=27019
oplogSize=10000
fork=true
noprealloc=true
#arbiter.conf
dbpath=~/mongodb/a/data
logpath=~/mongodb/log/a.log
pidfilepath=~/mongodb/a.pid
directoryperdb=true
logappend=true
replSet=virus
port=27010
oplogSize=10000
fork=true
noprealloc=true
启动命令:
cd ~/mongodb/m/bin
./mongod -f s.conf
cd ~/mongodb/s1/bin
./mongod -f s.conf
cd ~/mongodb/s2/bin
./mongod -f s.conf
cd ~/mongodb/a/bin
./mongod -f s.conf
配置:
cd ~/mongodb/m/bin
./mongo
use admin
cfg={ _id:"virus", members:[ {_id:0,host:'127.0.0.1:27017',priority:1}, {_id:1,host:'127.0.0.1:27018',priority:2},
{_id:2,host:'127.0.0.1:27019',priority:3},
{_id:3,host:'127.0.0.1:27010',arbiterOnly:true}] };
rs.initiate(cfg)
----当然可以按照下面这个来---
1、把文件拷贝到服务器上去
tar -zxvf mongxxx
mv mongodb-xxxx mongodb
cd /mongodb
mkdir data
mkdir data/"节点名称"
mkdir log
2 、修改/etc/init.d/mongod
#把mongod传输到 /etc/rc.d/init.d/下面
vi /etc/init.d/mongod
#修改配置文件路径
CONFIGFILE="/opt/mongodb/节点配置文件"
#注册服务
chmod +x /etc/init.d/mongod
chkconfig --add mongod
#chkconfig --level 5 mongod
chkconfig mongod on
chkconfig --list mongod
3 上传
libstdc++xxxx.rpm
rpm -ivh libstdc++xxxx.rpm
4 启动
service mongd start
#查看启动木有
ps -A
#如果没有看日志
vi /opt/mongodb/log/节点名称.log
5、配置home
vi /etc/profile
#最后添加
export MDB_HOME=/opt/mongodb
export PATH=$PATH:$MDB_HOME/bin
source /etc/profile
#或则
. /etc/profile
#进入操作
mongo 172.30.1.x:27017
6、 配置特殊的仲裁节点
#随便添加
cfg={ _id:"testrs", members:[ {_id:0,host:'10.10.148.130:27017',priority:2}, {_id:1,host:'10.10.148.131:27017',priority:1},
{_id:2,host:'10.10.148.132:27017',arbiterOnly:true}] };
#如果报错,把上的只留 _id和host
rs.initiate(cfg);
#手动添加仲裁
rs.addArb(“192.168.1.50:10001″)
#手工添加slaver(如果仲裁和slaver在一起麻烦换个端口不要用27017)
rs.add(“192.168.1.50:10001″)
#删除节点
rs.remove("192.168.1.50:10001")
设置启动用的代码改centos+Ubuntu的嘿嘿,偷懒啊。。。
#!/bin/bash # mongod - Startup script for mongod # chkconfig: 35 85 15 # description: Mongo is a scalable, document-oriented database. # processname: mongod # config: /etc/mongod.conf # pidfile: /var/run/mongodb/mongod.pid . /etc/rc.d/init.d/functions . /lib/lsb/init-functions # things from mongod.conf get there by mongod reading it # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. #centos下配置文件里面oplogSize=10000 会报错。。莫名,自己改下文件名称
CONFIGFILE="/opt/mongodb/master.conf" OPTIONS=" -f $CONFIGFILE" SYSCONFIG="/opt/mongodb/sysconfig" # FIXME: 1.9.x has a --shutdown flag that parses the config file and # shuts down the correct running pid, but that's unavailable in 1.8 # for now. This can go away when this script stops supporting 1.8. DBPATH=`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*dbpath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d '[:blank:]'` PIDFILE=`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d '[:blank:]'` PIDDIR=`dirname $PIDFILE` #mongod=${MONGOD-/usr/bin/mongod} mongod="/opt/mongodb/bin/mongod" MONGO_USER=root MONGO_GROUP=root if [ -f "$SYSCONFIG" ]; then . "$SYSCONFIG" fi # Handle NUMA access to CPUs (SERVER-3574) # This verifies the existence of numactl as well as testing that the command works NUMACTL_ARGS="--interleave=all" if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null then NUMACTL="numactl $NUMACTL_ARGS" else NUMACTL="" fi start() { # Make sure the default pidfile directory exists echo $PIDDIR if [ ! -d $PIDDIR ]; then install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR fi # Recommended ulimit values for mongod or mongos # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings # ulimit -f unlimited ulimit -t unlimited ulimit -v unlimited ulimit -n 64000 ulimit -m unlimited ulimit -u 64000 echo -n $"Starting mongod: " daemon --user "$MONGO_USER" --check $mongod "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod } stop() { MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print $2}'` #echo "$MONGOPID" echo -n "Stopping MongoDB server" if [ ! -z "$MONGOPID" ]; then kill -15 $MONGOPID echo -n "Stopped -----> $MONGOPID" fi RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod } restart () { stop start } RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f /var/lock/subsys/mongod ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL