98 lines
2.0 KiB
Bash
98 lines
2.0 KiB
Bash
#!/bin/bash
|
|
|
|
setenforce 0
|
|
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
|
|
|
|
cat >>/etc/yum.repos.d/mongodb-org-4.0.repo<<EOF
|
|
[mongodb-org]
|
|
name=MongoDB Repository
|
|
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
|
|
gpgcheck=0
|
|
enabled=1
|
|
EOF
|
|
|
|
yum install -y mongodb-org
|
|
|
|
MongoDBDataPath=/data/mogodb-data
|
|
mkdir -p ${MongoDBDataPath} && touch ${MongoDBDataPath}/mongod.log
|
|
chown -R mongod:mongod ${MongoDBDataPath}
|
|
|
|
systemctl daemon-reload
|
|
systemctl start mongod
|
|
|
|
mv /etc/mongod.conf /etc/mongod.conf_bak
|
|
cat >>/etc/mongod.conf <<EOF
|
|
# 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: /data/mogodb-data/mongod.log
|
|
|
|
# Where and how to store data.
|
|
storage:
|
|
dbPath: /data/mogodb-data
|
|
journal:
|
|
enabled: true
|
|
# engine:
|
|
# mmapv1:
|
|
wiredTiger:
|
|
engineConfig:
|
|
cacheSizeGB: 4
|
|
|
|
# how the process runs
|
|
processManagement:
|
|
fork: true # fork and run in background
|
|
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
|
|
timeZoneInfo: /usr/share/zoneinfo
|
|
|
|
# network interfaces
|
|
net:
|
|
port: 27017
|
|
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
|
|
|
|
|
|
security:
|
|
authorization: enabled
|
|
|
|
#operationProfiling:
|
|
|
|
#replication:
|
|
|
|
#sharding:
|
|
|
|
## Enterprise-Only Options
|
|
|
|
#auditLog:
|
|
|
|
#snmp:
|
|
EOF
|
|
|
|
systemctl restart mongod
|
|
|
|
|
|
echo "
|
|
use admin
|
|
|
|
db.createUser(
|
|
{
|
|
user: "etour",
|
|
pwd: "eTour@27017",
|
|
roles: [
|
|
{ role: "userAdminAnyDatabase", db: "admin" },
|
|
{ role: "userAdmin", db: "admin" },
|
|
{ role: "dbAdminAnyDatabase", db: "admin" }
|
|
]
|
|
}
|
|
)
|
|
" | mongo --port 27017
|
|
|
|
db.grantRolesToUser( "etour" , [ { role: "userAdmin", db: "admin" } ])
|
|
db.grantRolesToUser( "etour" , [ { role: "dbAdminAnyDatabase", db: "admin" } ])
|
|
db.grantRolesToUser( "etour" , [ { role: "root", db: "admin" } ])
|
|
|