mongodb 配置单实例与双实例

环境: centos6.5 192.168.16.70

配置单实例mongodb:
[[email protected] soft]# tar xf mongodb-linux-x86_64-rhel62-3.2.7.tgz
[[email protected] soft]# ls
mongodb-linux-x86_64-rhel62-3.2.7
mongodb-linux-x86_64-rhel62-3.2.7.tgz
[[email protected] soft]# mv mongodb-linux-x86_64-rhel62-3.2.7 /usr/local/mongodb
[[email protected] soft]# cd /usr/local/mongodb/
[[email protected] mongodb]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[[email protected] mongodb]# ulimit -n
1024
[[email protected] mongodb]# ulimit -n 25000 //指定同一时间最多可开启的文件数
[[email protected] mongodb]# ulimit -u
3648
[[email protected] mongodb]# ulimit -u 25000 //用户最多可开启的程序数目
[[email protected] mongodb]# ulimit -n
25000
[[email protected] mongodb]# ulimit -u
25000
[[email protected] mongodb]# mkdir -p /data/mongodb1
[[email protected] mongodb]# mkdir -p /data/logs/mongodb
[[email protected] mongodb]# touch /data/logs/mongodb/mongodb1.log
[[email protected] mongodb]# cd /usr/local/mongodb/
[[email protected] mongodb]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[[email protected] mongodb]# mkdir conf
[[email protected] mongodb]# vim conf/mongodb1.conf

port=27017
dbpath=/data/mongodb1
logpath=/data/logs/mongodb/mongodb1.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
[[email protected] mongodb]# pwd
/usr/local/mongodb
[[email protected] mongodb]# ls
bin conf GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
[[email protected] mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf //启动mongodb数据库 -f 指定配置文件
about to fork child process, waiting until server is ready for connections.
forked process: 1652
child process started successfully, parent exiting
[[email protected] mongodb]# ps -ef | grep mongod
root 1652 1 2 04:53 ? 00:00:00 bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf
root 1666 1607 0 04:53 pts/0 00:00:00 grep mongod
[[email protected] mongodb]# netstat -lnpt | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1652/bin/mongod
[[email protected] mongodb]# lsof -i:27017
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 1652 root 6u IPv4 12709 0t0 TCP *:27017 (LISTEN)
[[email protected] conf]# vim /etc/rc.local //设置开机自启动
rm -rf /data/mongodb1/mongod.lock
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf

[[email protected] mongodb]# bin/mongo //登陆mongodb数据库
MongoDB shell version: 3.2.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-03-28T04:53:32.052+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-03-28T04:53:32.052+0800 I CONTROL [initandlisten]
> show dbs
local 0.078GB
> exit
bye

去除报错问题:
[[email protected] mongodb]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[[email protected] mongodb]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[[email protected] ~]# vim .bash_profile
。。。。。。。。。。。。。。。。
alias mongo=/usr/local/mongodb/bin/mongo
。。。。。。。。。。。。。。。。。。。
[[email protected] ~]# source .bash_profile

关闭服务的三种方法:
方法一:
[[email protected] mongodb]# bin/mongo
MongoDB shell version: 3.2.7
connecting to: test
Server has startup warnings:
2017-03-28T05:16:53.926+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2017-03-28T05:16:53.926+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
2017-03-28T05:38:06.756+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-03-28T05:38:06.758+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-03-28T05:38:06.758+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
> exit
bye

方法二:
[[email protected] mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf --shutdown
killing process with pid: 1829

方法三:杀进程号(不建议用杀进程方法,mongodb集群的话节点数据不易保存)
[[email protected] mongodb]# bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 1882
child process started successfully, parent exiting
[[email protected] mongodb]# ps -ef | grep mongod
root 1882 1 2 05:41 ? 00:00:00 bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf
root 1896 1717 0 05:41 pts/1 00:00:00 grep mongod
[[email protected] mongodb]# kill 1882
[[email protected] mongodb]# ps -ef | grep mongod
root 1899 1717 0 05:41 pts/1 00:00:00 grep mongod

开启两个实例,配置双实例mongodb:

[[email protected] conf]# pwd
/usr/local/mongodb/conf
[[email protected] conf]# vim mongodb2.conf

port=27018
dbpath=/data/mongodb2
logpath=/data/logs/mongodb/mongodb2.log
logappend=true //日志追加
fork=true
maxConns=5000
storageEngine=mmapv1 //存储引擎

[[email protected] conf]# ls /data/ //建立mongodb2数据文件目录
logs mongodb1 mongodb2
[[email protected] conf]# ls /data/logs/mongodb/ //建立mongodb2.log 日志文件
mongodb1.log mongodb2.log
[[email protected] mongodb2]# chmod 777 /data/logs/mongodb/mongodb2.log //给mongodb2.log添加权限

编写启停脚本:
[[email protected] mongodb2]# cd /etc/init.d
[[email protected] init.d]# vim mongodb

#!/bin/bash
INSTANCE=$1
ACTION=$2
case "$ACTION" in

start)
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf
;;

stop)
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf
;;

restart)
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf --shutdown
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/"$INSTANCE".conf
;;

esac

[[email protected]ww init.d]# chmod +x mongodb
[[email protected] init.d]# /etc/init.d/mongodb mongodb1 start
about to fork child process, waiting until server is ready for connections.
forked process: 1957
child process started successfully, parent exiting
[[email protected] init.d]# /etc/init.d/mongodb mongodb2 start
about to fork child process, waiting until server is ready for connections.
forked process: 1973
child process started successfully, parent exiting
[[email protected] init.d]# ps -ef | grep mongodb
root 1957 1 1 05:56 ? 00:00:00 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb1.conf
root 1973 1 1 05:56 ? 00:00:00 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb2.conf
root 1987 1902 0 05:56 pts/2 00:00:00 grep mongodb

时间: 2024-11-05 12:13:31

mongodb 配置单实例与双实例的相关文章

1、MySQL单双实例实战

########################################################################################### MySQL单实例实战 ########################################################################################### #单实例安装,上传mysql-5.5.32.tar.gz.cmake-2.8.8.tar.gz到opt目录下

MariaDB单机双实例主从复制

MariaDB其实和mysql一样,非有啥不一样那就是名字不一样~.~! 开始-上篇实验是MariaDB的单机多实例安装 双实例端口3307主库,3308从库 3307主实例的mysqld配置 [mysqld2] port=3307 socket=/tmp/mysql3307.sock pid-file=/tmp/mysql3307.pid max_allowed_packet=1M net_buffer_length=2k table_open_cache=4 sort_buffer_size

keepalived 双实例_nginx互为主备

一.实验目的:两台nginx服务器,利用keepalived实现双实例互为主备,并能够对http服务检测动态切换主备,主服务器检测失败后,重启对应http服务. 二.实验环境 服务器类型 IP 软件 主备情况 VIP CentOS 6.6(nginx1) 172.18.100.11 nginx+keepalived 实例VI_1为主服务器:实例VI_2为辅服务器 172.18.100.21 CentOS 6.6(nginx2) 172.18.100.12 nginx+keepalived 实例V

keepalived双实例配置

一.keepalived双实例 keepalived在master/backup工作模式下,会有一个主机处于闲置,所以keepalived可以使用vrrp的特性配置双master模式,使资源最大化.     1.承接上文配置 --->  keepalived基础配置     2.双主配置 第一个节点: [[email protected] keepalived]# grep -Ev '#|^$' keepalived.conf ! Configuration File for keepalive

配置Keepalived双实例高可用Nginx

我们知道Keepalived原生设计目的是为了高可用LVS集群的,但Keepalived除了可以高可用LVS服务之外,还可以基于vrrp_script和track_script高可用其它服务,如Nginx等.本篇主要演示如何使用Keepalived高可用Nginx服务(双实例),关于vrrp_script.track_script的更多介绍可以见上一篇博客<Keepalived学习总结>. 实验要求 ==> 实现Keepalived基于vrrp_script.track_script高可

手把手教你写Dockerfile, 附赠MongoDB和Nginx Dockerfile编写实例

手把手教你写Dockerfile, 附赠MongoDB和Nginx Dockerfile编写实例 基础镜像可以用于创建Docker容器.镜像可以非常基础,仅仅包含操作系统:也可以非常丰富,包含灵巧的应用栈,随时可以发布.当你在使用 Docker构建镜像的时候,每一个命令都会在前一个命令的基础上形成一个新层.这些基础镜像可以用于创建新的容器.本篇文章将手把手教您如何从基础镜 像,一步一步,一层一层的从Dockerfile构建容器的过程. Docker简介 Docker项目提供了构建在Linux内核

Mongodb的主从模式搭建实例

对数据库来说,为了保证数据的安全性和高可用性,往往会采用主从架构模式,对于Mongodb也是如此,这篇文章将讲述一下如何搭建一个简单的Mongodb主从架构模型. 在下面的实例中,因为没有多个服务器的原因,在一台服务器上进行了实验,采用不同的端口号进行区分主从. 首先我们需要的是下载Mongodb的官方版本,这里我下载的是2.4.1的Linux版本,并在Linux下进行解压,然后创建两个文件夹master和slave,分别存放主Mongodb实例和从mongodb实例. 然后我们首先启动mast

ElasticSearch单机双实例的配置方法

ElasticSearch单机双实例的配置方法https://knktc.com/2016/06/10/elasticsearch-multiple-instances/Don't Cross 32 GB!https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html#compressed_oopsElasticSearch术语https://www.cnblogs.com/chenny7/p/431172

ORACLE11g R2【单实例 FS→单实例FS】

ORACLE11g R2[单实例 FS→单实例FS] 本演示案例所用环境:   primary standby OS Hostname pry std OS Version RHEL6.5 RHEL6.5 DB Version 11.2.0.4 11.2.0.4 db_name stephen stephen db_unique_name stephen standby service_names stephen standby instance_name stephen standby Pri