单机Mongo复制集安装配置(数据库版本:4.x)
官方文档:
https://docs.mongodb.com/manual/tutorial/deploy-replica-set-with-keyfile-access-control/#deploy-repl-set-with-auth
一、创建fileKey,秘钥文件复制集的成员一样,将秘钥复制给所有成员
openssl rand -base64 756 > <path-to-keyfile> chmod 400 <path-to-keyfile> |
实例:key/security.key: avslWt007EL8g0/omOnclstP+2cgpu6YChkc4KCJOU5bVG...省略 |
二、开启成员的访问控制
security: keyFile: <path-to-keyfile> replication: replSetName: <replicaSetName> net: bindIp: localhost,<hostname(s)|ip address(es)> |
实例:etc/mongod1.conf 注意:后面有个空格 # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /home/mongod/mongodb/log/mongod1.log # Where and how to store data. storage: dbPath: /home/mongod/mongodb/data/mongod1/ journal: enabled: true # engine: # mmapv1: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /var/run/mongodb/mongod1.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27018 bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. # keyFile privilege 400 security: authorization: enabled keyFile: /home/mongod/mongodb/key/security.key #operationProfiling: replication: replSetName: replTest #sharding: ## Enterprise-Only Options #auditLog: #snmp: |
三、创建目录,需要将以下目录的用户设置为mongod
# ll |
四、初始化mongo replSet,域名替换为自己的域名或者IP生产环境建议使用域名
rs.initiate({ _id : <replicaSetName>, members: [ { _id : 0, host : "mongo.example.net:27017" }, { _id : 1, host : "mongo.example.net:27018" }, { _id : 2, host : "mongo.example.net:27019" } ] } ) |
五、连接primary节点,在admin的数据库上创建用有userAdminAnyDatabase 角色管理员用户。使用rs.status()可以查看主节点的位置。
db.createUser( { user: "replTest", pwd: "replTest", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) |
六、使用主节点的admin数据用户登录,并且创建集群管理员账号
mongo 127.0.0.1:27018/admin(假如这个节点是主节点) db.createUser( { "user" : "cluster", "pwd" : "cluster", roles: [ { "role" : "clusterAdmin", "db" : "admin" } ] } ) |
七、创建普通数据的用户,用于操作数据库
mongo 127.0.0.1:27018/admin use business; db.createUser( { "user": "test", "pwd": "test", "roles":[ { role: "dbOwner", "db": "reset" }, { role: "readWrite", db: "reset" } ] } ) |
八、在/etc/init.d/创建启动服务配置,将CONFIGFILE="/etc/mongod.conf"执行第二点配置路径
/etc/init.d/mongod1(/etc/init.d/mongod2、/etc/init.d/mongod3) |
#!/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 . /etc/rc.d/init.d/functions # NOTE: if you change any OPTIONS here, you get what you pay for: # this script assumes all options are in the config file. CONFIGFILE="/etc/mongod.conf" OPTIONS=" -f $CONFIGFILE" mongod=${MONGOD-/usr/bin/mongod} MONGO_USER=mongod MONGO_GROUP=mongod # All variables set before this point can be overridden by users, by # setting them directly in the SYSCONFIG file. Use this to explicitly # override these values, at your own risk. SYSCONFIG="/etc/sysconfig/mongod" 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 # things from mongod.conf get there by mongod reading it PIDFILEPATH="`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' \"$CONFIGFILE\" | tr -d \"[:blank:]\\"'\" | awk -F'#' '{print $1}'`" PIDDIR=`dirname $PIDFILEPATH` start() { # Make sure the default pidfile directory exists if [ ! -d $PIDDIR ]; then install -d -m 0755 -o $MONGO_USER -g $MONGO_GROUP $PIDDIR fi # Make sure the pidfile does not exist if [ -f "$PIDFILEPATH" ]; then echo "Error starting mongod. $PIDFILEPATH exists." RETVAL=1 return 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 ulimit -l unlimited 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() { echo -n $"Stopping mongod: " mongo_killproc "$PIDFILEPATH" $mongod RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod } restart () { stop start } # Send TERM signal to process and wait up to 300 seconds for process to go away. # If process is still alive after 300 seconds, send KILL signal. # Built-in killproc() (found in /etc/init.d/functions) is on certain versions of Linux # where it sleeps for the full $delay seconds if process does not respond fast enough to # the initial TERM signal. mongo_killproc() { local pid_file=$1 local procname=$2 local -i delay=300 local -i duration=10 local pid=`pidofproc -p "${pid_file}" ${procname}` kill -TERM $pid >/dev/null 2>&1 usleep 100000 local -i x=0 while [ $x -le $delay ] && checkpid $pid; do sleep $duration x=$(( $x + $duration)) done kill -KILL $pid >/dev/null 2>&1 usleep 100000 checkpid $pid # returns 0 only if the process exists local RC=$? [ "$RC" -eq 0 ] && failure "${procname} shutdown" || rm -f "${pid_file}"; success "${procname} shutdown" RC=$((! $RC)) # invert return code so we return 0 when process is dead. return $RC } 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 |
九、从节点无法执行find等错误
rs.slaveOk(); |
十、写关注配置待补充
单机Mongo复制集安装配置(数据库版本:4.x)的更多相关文章
- mongo 复制集命令
1.登录primary2.use admin >rs.add("new_node:port") 或 rs.add({"_id":4,"host& ...
- Hadoop spark mongo复制集
启动hadoop cd /usr/local/hadoop/hadoop $hadoop namenode -format # 启动前格式化namenode $./sbin/start-all.sh ...
- 4-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(云端电脑(Windows)安装配置数据库,使用本地Navicat for MySQL和手机APP 远程连接测试)
3-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(安装配置数据库,使用Navicat for MySQL和手机APP 连接测试) 根据前面的教程把软件复制到云 ...
- Mongo服务器集群配置【转】
http://www.cnblogs.com/wly923/tag/MongoDB/ 当前标签: MongoDB Mongo服务器集群配置学习三——分片 风行影者 2013-04-14 22:35 ...
- 3-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(安装配置数据库,使用Navicat for MySQL和手机APP 连接测试)
2-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(数据库简单说明) https://www.mysql.com/ 咱用安装版的 我把自己下载的放在了这里 现在 ...
- mongo复制集脑裂问题如何处理
mongo replication 脑裂问题如何处理: 一.问题描述:一套mongo replication有4个节点.1个仲裁节点.在停止实例(或实例毁坏)的时候,导致所有节点都变为SECONDAR ...
- mongodb-3.2.8 单机复制集安装
规划: replSet 复制集名称: rs1 MongoDB数据库安装安装路径为:/usr/local/mongodb/ 复制集成员IP与端口: 节点1: localhost:28010 (默认的 ...
- Redis单机和集群配置(版本在5.0后)
摘抄并用于自己后查 单机版的配置: 1. 下载redis压缩包,然后解压缩文件(tar xzf): 2. 进入解压后的redis文件目录,编译redis源文件(make,没有c环境要gcc): 3. ...
- Mongo的Replica Sets (复制集)的配置全过程和心得体会
http://blog.csdn.net/bloggongchang/article/details/7272403 一.MongoDB Replica Sets(副本集)简单的说就是有自动故障恢复功 ...
随机推荐
- Hibernate---criteria的具体使用列子
方法 说明 Restrictions.eq = Restrictions.allEq 利用Map来进行多个等于的限制 Restrictions.gt > Restrictions.ge > ...
- 路飞学城Python-Day31
19-生产者消费者模型 生产者:生成数据的任务 消费者:处理数据的任务 在并发编程的过程中,如果生产者处理速度很快,而消费者处理速度很慢,那么生产者就必须等待消费者处理,才能继续生产数据:同样的,如果 ...
- redis 篇 - set
set 无序集合 sadd key value 127.0.0.1:6379[7]> sadd s 3 (integer) 1 127.0.0.1:6379[7]> smembers s ...
- [LUOGU]2016 Sam数
我本来想看看SAM,就看见了这个.. 这道题很容易让人想到数位DP,用\(f[i][j]\)表示考虑到第\(i\)位,最后一位是\(j\)的方案数.看到1e18,直接矩阵快速幂加速,因为它每位转移都是 ...
- UNIX系统高级编程——第四章-文件和目录-总结
文件系统: 以UNIX系统V文件系统为例: 磁盘分为区,每个分区都有自己的文件系统: i节点是固定长度的记录项,包含了文件的相关信息.目录项包含文件名和i节点号.stat结构中除文件名和i节点编号 ...
- myeclipse 字体设置为UTF-8
将myeclipse设置成utf-8格式的方式如下: 1.windows->Preferences打开"首选项"对话框,如图: 2.点击左侧导航树,导航到general-&g ...
- 简述vuex的数据传递流程
简述vuex的数据传递流程 当组件进行数据修改的时候我们需要调用dispatch来触发actions里面的方法.actions里面的每个方法中都会有一个commit方法,当方法执行的时候会通过comm ...
- nutch+hadoop 配置使用
nutch+hadoop 配置使用 配置nutch+hadoop 1,下载nutch.如果不需要特别开发hadoop,则不需要下载hadoop.因为nutch里面带了hadoop core包以及相关配 ...
- Collection 和 Collections 的差别?
Collection 是 java.util 下的接口,它是各种集合的父接口,继承于它的 接口主要有 Set 和 List:Collections 是个 java.util 下的类.是针对集合的 帮助 ...
- 玩转Android Camera开发(三):国内首发---使用GLSurfaceView预览Camera 基础拍照demo
GLSurfaceView是OpenGL中的一个类,也是能够预览Camera的,并且在预览Camera上有其独到之处. 独到之处在哪?当使用Surfaceview无能为力.痛不欲生时就仅仅有使用GLS ...