MongoBD 3.6 Linux下二进制安装

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/vkingnew/article/details/82056735
1.下载软件:
# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.6.tgz
2.解压:
# tar -xzf mongodb-linux-x86_64-rhel70-3.6.6.tgz  -C /usr/local/
# mv /usr/local/mongodb-linux-x86_64-rhel70-3.6.6/ /usr/local/mongodb
# vim /etc/profile.d/mongo.sh
export PATH=$PATH:/usr/local/mongodb/bin
# source  /etc/profile.d/mongo.sh 
--验证设置的环境变量信息:
# mongo --version
MongoDB shell version v3.6.6
git version: 6405d65b1d6432e138b44c13085d0c2fe235d6bd
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

3.参数文件设置:
注释:在MongoDB2.6版本之前仅支持conf配置文件,在2.6版本开始支持YAML格式和conf配置文件。
YAML格式:
processManagement:
   fork: true
net:
   bindIp: localhost
   port: 27017
storage:
   dbPath: /data/mongodb
systemLog:
   destination: file
   path: "/data/mongodb/mongod.log"
   logAppend: true
storage:
   journal:
      enabled: true
conf格式:
fork = true
bind_ip = localhost
port = 27017
quiet = true
dbpath = /data/mongodb
logpath = /data/mongodb/mongod.log
logappend = true
journal = true

这里采用传统的conf配置文件模式。

4.启动mongodb:
# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongod.conf 
about to fork child process, waiting until server is ready for connections.
forked process: 23970
child process started successfully, parent exiting
5.验证mongodb启动:
[root@node1 bin]# ps -ef | grep -i mongo
root      23970      1  4 06:32 ?        00:00:01 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongod.conf
root      24026   8252  0 06:33 pts/2    00:00:00 grep --color=auto -i mongo
[root@node1 bin]# netstat -nultp | grep -i mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      23970/mongod      

5.登录mongoDB:
# mongo
MongoDB shell version v3.6.6
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.6
Server has startup warnings: 
2018-08-25T06:44:52.559+0800 I STORAGE  [initandlisten] 
2018-08-25T06:44:52.559+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-08-25T06:44:52.560+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] 
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] 
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] 
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] 
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-08-25T06:44:53.948+0800 I CONTROL  [initandlisten] 
> 

6.修改操作系统的配置:
# vim /etc/security/limits.conf
* soft    nproc   65536
* hard    nproc   65536
* soft    nofile  65536
* hard    nofile  65536

# vim /etc/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
设置上述完毕之后重启操作系统。

7.设置monogdb的root用户和密码:
> use admin
switched to db admin
> db.createUser({user:"root",pwd:"root",roles: [{role:"userAdminAnyDatabase", db: "admin" } ]})
--新建数据库ycsb,并创建用户和密码,授权:
> use ycsb
switched to db ycsb
> db.createUser({user:"ycsb",pwd:"ycsb",roles: [{role:"readWrite", db: "ycsb" } ]})

8.重新登录moongoDB:
# mongo
MongoDB shell version v3.6.6
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.6
Server has startup warnings: 
2018-08-26T01:11:03.116+0800 I STORAGE  [initandlisten] 
2018-08-26T01:11:03.116+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-08-26T01:11:03.116+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2018-08-26T01:11:06.842+0800 I CONTROL  [initandlisten] 
2018-08-26T01:11:06.842+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-26T01:11:06.842+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-08-26T01:11:06.842+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-08-26T01:11:06.842+0800 I CONTROL  [initandlisten] 
> 

提示使用root用户不被推荐,数据库的访问控制伟开启。

9.关闭mongodb数据库:
--方法1:使用--shutdown 命令
# mongod --shutdown --config /usr/local/mongodb/bin/mongod.conf 
killing process with pid: 23970
--方法2:使用mongodb提供的命令:
>
use admin
db.shutdownServer()

--方法3:使用系统的kill 命令杀掉进程。


10.设置日志轮训:
>db.adminCommand( { logRotate : 1 } )

猜你喜欢

转载自blog.csdn.net/vkingnew/article/details/82056735
今日推荐