[root@wallet01 ~]# vi /etc/yum.repos.d/mongodb-org-3.6.repo
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
[root@wallet01 ~]# yum install -y mongodb-org
[root@wallet01 ~]# rpm -qa | grep mongodb-org
mongodb-org-3.6.12-1.el6.x86_64
mongodb-org-shell-3.6.12-1.el6.x86_64
mongodb-org-mongos-3.6.12-1.el6.x86_64
mongodb-org-tools-3.6.12-1.el6.x86_64
mongodb-org-server-3.6.12-1.el6.x86_64
[root@wallet01 ~]# vi /etc/mongod.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# 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: 192.168.40.34 # Listen to local interface only, comment to listen on all interfaces.
[root@king01 ~]# cat >> /etc/security/limits.conf <<EOF
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
EOF
[root@wallet01 ~]# service mongod start
Starting mongod: [ OK ]
[root@wallet01 ~]# service mongod status
mongod (pid 9007) is running...
[root@wallet01 ~]# netstat -tunlp | grep mongod
tcp 0 0 192.168.40.34:27017 0.0.0.0:* LISTEN 9393/mongod
[root@wallet01 ~]# mongo 192.168.40.34
MongoDB shell version v3.6.12
connecting to: mongodb://192.168.40.34:27017/test?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("294788b8-6cc9-4cc3-9dc8-c397d47ae040") }
MongoDB server version: 3.6.12
Server has startup warnings:
2019-05-22T09:35:10.938+0800 I STORAGE [initandlisten]
2019-05-22T09:35:10.938+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-05-22T09:35:10.938+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten]
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten]
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten]
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten]
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-05-22T09:35:12.308+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
[root@wallet01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@wallet01 ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
[root@wallet01 ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@wallet01 ~]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
[root@wallet01 ~]# vim /etc/rc.d/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
[root@wallet01 ~]# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
[root@wallet01 ~]# mongo 192.168.40.34
MongoDB shell version v3.6.12
connecting to: mongodb://192.168.40.34:27017/test?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("b8092e3a-4aa6-437a-8cae-f5b0697469e9") }
MongoDB server version: 3.6.12
Server has startup warnings:
2019-05-22T09:48:31.329+0800 I STORAGE [initandlisten]
2019-05-22T09:48:31.329+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-05-22T09:48:31.329+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-05-22T09:48:32.648+0800 I CONTROL [initandlisten]
2019-05-22T09:48:32.648+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-05-22T09:48:32.648+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-05-22T09:48:32.648+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.createUser(
... ... {
... ... user: "admin",
... ... pwd: "abcd.1234",
... ... roles: [ { role: "root", db: "admin" } ]
... ... }
... ... )
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
[root@wallet01 ~]# vi /etc/mongod.conf
security:
authorization: enabled
[root@wallet01 ~]# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
[root@wallet01 ~]# mongo 192.168.40.34 -u "admin" -p "abcd.1234" --authenticationDatabase "admin"
MongoDB shell version v3.6.12
connecting to: mongodb://192.168.40.34:27017/test?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("dd93844b-dfe2-46fd-bbdb-04ca46d930f6") }
MongoDB server version: 3.6.12
Server has startup warnings:
2019-05-22T10:00:20.307+0800 I STORAGE [initandlisten]
2019-05-22T10:00:20.307+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-05-22T10:00:20.307+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
> use tpccdb
switched to db tpccdb
> db.createUser(
... ... {
... ... user: "tpcc",
... ... pwd: "tpcc",
... ... roles: [ { role: "readWrite", db: "testdb" } ]
... ... }
... ... )
Successfully added user: {
"user" : "tpcc",
"roles" : [
{
"role" : "readWrite",
"db" : "testdb"
}
]
}
> db.auth('tpcc','tpcc')
1
XFS
[root@wallet01 ~]# yum install -y xfsprogs
[root@wallet01 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7cf0a5c7.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443):
Using default value 10443
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@wallet01 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=5242711 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=20970841, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=10239, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@wallet01 ~]# mount -t xfs /dev/sdb1 /var/lib/mongo
[root@wallet01 ~]# chown mongod:mongod /var/lib/mongo
[root@wallet01 ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda3 ext4 74109136 6575780 63768776 10% /
tmpfs tmpfs 1962432 0 1962432 0% /dev/shm
/dev/sda1 ext4 198337 34060 154037 19% /boot
/dev/sdb1 xfs 83842408 32928 83809480 1% /var/lib/mongo
[root@wallet01 ~]# vi /etc/fstab
/dev/sdb1 /var/lib/mongo xfs defaults 0 0
转载于:https://blog.51cto.com/13598811/2083092