mongdb复制集+仲裁(带权限认证)
一、 环境 1、架构图 650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/120F554M-0.jpg" title="111111111.png" alt="wKioL1XRzn6SRVMYAADM1onFESo308.jpg" /> 2、部署详细 10.10.17.26:27000(primary)10.10.17.27:27000(seco
一、环境
1、架构图
2、部署详细
10.10.17.26:27000 (primary) 10.10.17.27:27000 (secondary) 10.10.2.74:27000 (arbiter)
3、软件版本
mongdb :2.6.11 系统:centos 6.6
二、安装配置
1、安装见mongodb安装
2、撰写配置文件
vi /etc/mongod_27000.conf logpath=/data/mongodb/navy_db/log/mongod.log #mongodb日志文件 logappend=true #追加方式写日志文件 fork=true #后台运行 port=27000 #mongodb端口 dbpath=/data/mongodb/navy_db/db pidfilepath=/data/mongodb/navy_db/log/mongod.pid bind_ip=0.0.0.0 rest = true #开启web访问 journal = true #启用日志选项,MongoDB的数据操作将会写入到journal文件夹的文件里 oplogSize=2048 #同步操作记录文件大小(MB) replSet=dbset #副本集名称,同一个副本集,名称必须一致 auth=true #开启验证 keyFile=/data/mongodb/navy_db/password.key #key认证
3、生成keyfile文件
echo "c57a012cf2f8a8e20dd4b21a7fae48b3" >/data/mongodb/navy_db/password.key
4、设置keyfile权限,必须是600
chmod 600 /data/mongodb/navy_db/password.key
5、启动服务
ulimit -s 4096 && ulimit -m 16777216 & numactl --interleave=all /usr/bin/mongod -f /etc/mongod_27000.conf
PS:
在配置集群之前auth和keyFile先注释掉,待集群初始化完成,建立用户(从库上不需要建用户,当集群初始化完成会从主库上同步过来的,如果从库建了用户,集群初始化会报错,提示从库已有数据),然后打开,并重启服务让其生效
三、集群配置
#use到admin use admin 创建配置(dbset是集群名称,必须和配置文件中replSet的值一样) config = { _id:"dbset", members:[ ... ... {_id:1,host:"10.10.11.34:27000"}, ... ... {_id:2,host:"10.10.16.6:27000"} ] ... ... } #初始化集群 rs.initiate(config); #添加仲裁节点 rs.addArb("10.10.2.74:27000") #查看集群状态 rs.status()
PS:其他常用命令
#删除一个节点 rs.remove("10.10.2.74:27000") #查看集群配置信息 rs.conf() #查看当前谁是primary rs.isMaster() #查看主从延时 rs.printSlaveReplicationInfo() #查看rs相关命令 rs.help()
rs.status()结果说明
1. STARTUP:刚加入到复制集中,配置还未加载 2. STARTUP2:配置已加载完,初始化状态 3. RECOVERING:正在恢复,不适用读 4. ARBITER: 仲裁者 5. DOWN:节点不可到达 6. UNKNOWN:未获取其他节点状态而不知是什么状态,一般发生在只有两个成员的架构,脑裂 7. REMOVED:移除复制集 8. ROLLBACK:数据回滚,在回滚结束时,转移到RECOVERING或SECONDARY状态 9. FATAL:出错。查看日志grep “replSet FATAL”找出错原因,重新做同步 10. PRIMARY:主节点 11. SECONDARY:备份节点
四、建立用户(只能在primary节点上操作)
use admin db.addUser('admin','123456') #建立管理员账号 use navy_db #如果navy_db存在就进入库,如果不存在就建立navy_db库,空库show dbs是看不到的 db.addUser('navy_db_pro','123456') #建立navy_db的读写账号 db.addUser('navy_db_sel','123456',true) #建立navy_db的只读账号
五、重启集群
把auth和keyFile的注释去掉,arbiter、secondary、primary三个节点依次重启,让其生效
rs.status() 查看集群状态是否ok
PS:
1、从库默认是不可以读的,如果需要从库提供读业务,需要做一下设置
db.getMongo().setSlaveOk()
2、mongdb的客户端驱动支持这种架构,主库挂了,secondary提升为主,对于应用基本透明
client=MongoClient(“mongdb://navy_db_pro:123456@10.10.17.26:27000,10.10.17.27:27000/navy_db”

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Windows Recovery Environment (WinRE) is an environment used to repair Windows operating system errors. After entering WinRE, you can perform system restore, factory reset, uninstall updates, etc. If you are unable to boot into WinRE, this article will guide you through fixes to resolve the issue. Unable to boot into the Windows Recovery Environment If you cannot boot into the Windows Recovery Environment, use the fixes provided below: Check the status of the Windows Recovery Environment Use other methods to enter the Windows Recovery Environment Did you accidentally delete the Windows Recovery Partition? Perform an in-place upgrade or clean installation of Windows below, we have explained all these fixes in detail. 1] Check Wi

It allows users to perform more in-depth operations and customization of the system. Root permission is an administrator permission in the Android system. Obtaining root privileges usually requires a series of tedious steps, which may not be very friendly to ordinary users, however. By enabling root permissions with one click, this article will introduce a simple and effective method to help users easily obtain system permissions. Understand the importance and risks of root permissions and have greater freedom. Root permissions allow users to fully control the mobile phone system. Strengthen security controls, customize themes, and users can delete pre-installed applications. For example, accidentally deleting system files causing system crashes, excessive use of root privileges, and inadvertent installation of malware are also risky, however. Before using root privileges

We users should be able to understand the diversity of some functions when using this platform. We know that the lyrics of some songs are very well written. Sometimes we even listen to it several times and feel that the meaning is very profound. So if we want to understand the meaning of it, we want to copy it directly and use it as copywriting. However, if we want to use it, we still need to You just need to learn how to copy lyrics. I believe that everyone is familiar with these operations, but it is indeed a bit difficult to operate on a mobile phone. So in order to give you a better understanding, today the editor is here to help you. A good explanation of some of the above operating experiences. If you also like it, come and take a look with the editor. Don’t miss it.

How to set permission access in QQ space? You can set permission access in QQ space, but most friends don’t know how to set permission access in QQ space. Next is the diagram of how to set permission access in QQ space brought by the editor for users. Text tutorial, interested users come and take a look! QQ usage tutorial QQ space how to set permission access 1. First open the QQ application, click [Avatar] in the upper left corner of the main page; 2. Then expand the personal information area on the left and click the [Settings] function in the lower left corner; 3. Enter the settings page Swipe to find the [Privacy] option; 4. Next in the privacy interface, select the [Permission Settings] service; 5. Then challenge to the latest page and select [Space Dynamics]; 6. Set up in QQ Space again

Discuz forum permission management: Read the permission setting guide In Discuz forum management, permission setting is a crucial part. Among them, the setting of reading permissions is particularly important, as it determines the scope of content that different users can see in the forum. This article will introduce in detail the reading permission settings of the Discuz forum and how to flexibly configure it for different needs. 1. Basic concepts of reading permissions In the Discuz forum, reading permissions mainly include the following concepts that need to be understood: Default reading permissions: Default after new user registration

In the PS copy layer shortcut keys, we can know that if you want to copy a layer when using PS, you can use the shortcut key [Ctrl+J] for quick copying. This introduction to the shortcut keys for copying layers can tell you the specific operation method. The following is the detailed content, so take a look. PS copy layer shortcut key answer: [Ctrl+J] Specific method: 1. Open the image in PS and select the layer that needs to be copied. 2. Press [Ctrl+J] on the keyboard at the same time to complete the copy of the layer. Other copying methods: 1. After opening the image, press and hold the layer and move the [New Layer] icon downwards. 2. After moving to the icon, let go. 3. The layer copy is completed.

When many users use computers, if they encounter something that needs to be copied and pasted, it is very troublesome to copy with the mouse. So how to use the shortcut keys for copy and paste? Come and take a look at the detailed tutorial ~ Copy and paste shortcuts How to use the key: 1. Copy key: Ctrl+C, select the text or image to be copied, and press the shortcut key. 2. Paste key: Ctrl+V. Just press the shortcut key directly where you want to paste.

This article will take you to understand the essence of TI and further explore how to obtain TI permissions with the help of powershell and NtObjectManager modules to complete any operation you want in the operating system. If you have ever administered a Windows system, you should be familiar with the concept of the trustedInstaller (TI) group. The TI group has important permissions in the operation of system files and registry. For example, you can view the properties of files under the System32 folder. In the security options, the TI group and the file owner have permission to delete and modify files. Even administrators cannot directly modify the security options. Therefore, for the operation of system files and registry, it is necessary to
