markdown mongoDB构建Percona副本集

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown mongoDB构建Percona副本集相关的知识,希望对你有一定的参考价值。

# Build Percona MongoDB Replica Set

1. Install Percona yum repo & check packages are available
``` sh
$ sudo yum update
$ sudo yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
$ sudo yum list | grep percona
```

1. Install Percona server for MongoDB via yum
``` sh
$ sudo yum install Percona-Server-MongoDB-34
```

1. Change ownership of /data 
``` sh
sudo chown mongod:mongod /data
```

1. Add following to /etc/hosts
``` sh
127.0.0.1   server1.address.com
```

1. Create keyfile (/etc/mongodb.key) and copy to all mongod servers
``` sh
$ sudo openssl rand -base64 756 > /etc/mongodb.key
$ sudo chmod 400 /etc/mongodb.key
$ sudo chown mongod:mongod /etc/mongodb.key
```

1. Start the mongod service
``` sh
$ sudo service mongod start
```

1. Connect to mongo on one host
``` sh
$ mongo --host localhost
```

1. In the mongo shell - Create an admin account on the "admin" database
``` js
> use admin
```
``` js
> db.createUser(
  {
    user: "admin",
    pwd: "<set strong password [32 chars] here>",
    roles: [ { role: "root", db: "admin" }, { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)
```
List database users
``` js
> db.getUsers()
```
Log out
``` js
> quit()
```

1. Edit the mongo config file (/etc/mongod.conf) on all hosts - setting the following:
``` sh
$ sudo vi /etc/mongod.conf
```
``` yaml
storage:
	engine: wiredTiger
	dbPath: /data
	journal:
		enabled: true
wiredTiger:
	engineConfig:
		cacheSizeGB: 3
systemLog:
	destination: file
	logAppend: true
	path: /var/log/mongo/mongod.log
processManagement:
	fork: true
	pidFilePath: /var/run/mongod.pid
net:
	port: 36035
	# bindIp: 127.0.0.1
replication:
	replSetName: <name of replica set>
security:
	authorization: enabled
	keyFile: /etc/mongodb.key
```

1. Run mongo on all hosts
``` sh
$ sudo service mongod start
```

1. Connect to one mongod host - Set-up replica set
``` sh
$ mongo --host localhost:36035
```
In the mongo shell, initiate a Replica Set
``` js
> rs.initiate( {
   _id : "<name of replica set>",
   members: [
      { _id: 0, host: "server1.address.com:36035" },
      { _id: 1, host: "server2.address.com:36035" },
      { _id: 2, host: "server3.address.com:36035" }
   ]
})
```
Check the replica set config
``` js
> rs.config()
```
Check the Replica set status
``` js
> rs.status()
```

1. Log into mongo with user credentials
``` sh
mongo -u admin -p <password> mongodb://server1.address.com:36035  --authenticationDatabase admin
```

以上是关于markdown mongoDB构建Percona副本集的主要内容,如果未能解决你的问题,请参考以下文章

Percona Monitoring and Management (PMM) 监控MongoDB

docker安装管理和监控MySQL和MongoDB性能的开源平台Percona

当引擎设置为rocksdb(MongoRocks)时,Percona Server for MongoDB 无法启动

percona顶级项目(针对数据库)

Percona监控工具初探

MySQL - percona-toolkit工具