centos-mongodb
centos 7 + mongodb 4.0
- create
mongodb-org.repoinside/etc/yum.repos.d/directory
past following contents
[mongodb-org-4.0] |
Installing MongoDB
sudo yum install mongodb-orgStarting MongoDB
sudo systemctl start mongod
sudo systemctl enable mongodVerifying MongoDB Installation
// 进入命令行
mongo
db.version()
//启动服务
mongod --dbpath /home/tyler/mongodb/stock
// 使用配置文件启动
mongod -f /etc/mongod.conf
Failed to unlink socket file /tmp/mongodb-27017.sock Unknown error
delete the /tmp/mongodb-27017.sock file manually and start the mongod process.
Failed to set up listener: SocketException: Address already in use
sudo service mongod stop |
- Configuring MongoDB
编辑配置文件/etc/mongod.conf
security: |
The authorization option enables Role-Based Access Control (RBAC) that regulates users access to database resources and operations. If this option is disabled each user will have access to any database and will be able to execute any action.
sudo systemctl restart mongod |
- Creating Administrative MongoDB User
mongo
use admin
db.createUser(
{
user: "mongoSuperAdmin",
pwd: "cow2wsx1qaz",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
quit()
mongo -u mongoSuperAdmin -p --authenticationDatabase admin |