【MongoDB】解决:“WARNING: You are running this process as the root user, which is not recommended.”
xixuefeng
MongoDB
2016-02-26 14:37:15
7,397 次浏览
MongoDB, 安装
【MongoDB】解决:“WARNING: You are running this process as the root user, which is not recommended.”已关闭评论
首先这个只是个警告,对于一个追求完美的人来说,看到WARNING,终究是很别扭的,所以,在已经以root身份“安装”完成的情况下进行修改,解决这个“瑕疵”
- 在linux下创建用户、修改密码
1 2 3 4 5 6 7 8 9 10 |
[root@xxf ~]# [root@xxf ~]# useradd mdb [root@xxf ~]# [root@xxf ~]# passwd mdb Changing password for user mdb. New UNIX password: BAD PASSWORD: it is based on a dictionary word Retype new UNIX password: passwd: all authentication tokens updated successfully. [root@xxf ~]# |
- 创建存放数据库软件的目录(为了完美,单独创建一个新的目录)
1 2 3 4 5 6 7 8 9 10 |
[root@xxf ~]# [root@xxf ~]# su - mdb [mdb@xxf ~]$ pwd /home/mdb [mdb@xxf ~]$ mkdir mongodb [mdb@xxf ~]$ [mdb@xxf ~]$ ls -l total 4 drwxrwxr-x 2 mdb mdb 4096 Jan 9 10:48 mongodb [mdb@xxf ~]$ |
- 将数据库软件剪切到新创建的目录下
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@xxf /]# cd /usr/local/mongodb/mongodb-linux-x86_64-rhel55-3.2.1 [root@xxf mongodb-linux-x86_64-rhel55-3.2.1]# mv * /home/mdb/mongodb [root@xxf mongodb-linux-x86_64-rhel55-3.2.1]# [root@xxf mongodb-linux-x86_64-rhel55-3.2.1]# cd /home/mdb/mongodb/ [root@xxf mongodb]# [root@xxf mongodb]# ls -l total 100 drwxr-xr-x 2 root root 4096 Jan 9 10:13 bin -rw-r--r-- 1 1046 1046 34520 Jan 12 2016 GNU-AGPL-3.0 -rw-r--r-- 1 1046 1046 16726 Jan 12 2016 MPL-2 -rw-r--r-- 1 1046 1046 1359 Jan 12 2016 README -rw-r--r-- 1 1046 1046 35910 Jan 12 2016 THIRD-PARTY-NOTICES [root@xxf mongodb]# |
- 修改MongoDB软件的属主和属组
1 2 3 4 5 6 7 8 9 |
[root@xxf mongodb]# chown -R mdb.mdb * [root@xxf mongodb]# ls -l total 100 drwxr-xr-x 2 mdb mdb 4096 Jan 9 10:13 bin -rw-r--r-- 1 mdb mdb 34520 Jan 12 2016 GNU-AGPL-3.0 -rw-r--r-- 1 mdb mdb 16726 Jan 12 2016 MPL-2 -rw-r--r-- 1 mdb mdb 1359 Jan 12 2016 README -rw-r--r-- 1 mdb mdb 35910 Jan 12 2016 THIRD-PARTY-NOTICES [root@xxf mongodb]# |
- 修改存放数据文件的目录的属主和属组
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
[root@xxf /]# ls -l |grep data drwxr-xr-x 3 root root 4096 Jan 9 10:13 data [root@xxf /]# [root@xxf /]# chown -R mdb:mdb /data [root@xxf /]# [root@xxf /]# ls -l |grep data drwxr-xr-x 3 mdb mdb 4096 Jan 9 10:13 data [root@xxf /]# [root@xxf /]# cd data [root@xxf data]# ls -l total 4 drwxr-xr-x 4 mdb mdb 4096 Jan 9 10:35 db [root@xxf data]# [root@xxf data]# cd db [root@xxf db]# ls -l total 152 -rw-r--r-- 1 mdb mdb 16384 Jan 9 10:35 collection-0-4830785095500701746.wt drwxr-xr-x 2 mdb mdb 4096 Jan 9 10:35 diagnostic.data -rw-r--r-- 1 mdb mdb 16384 Jan 9 10:35 index-1-4830785095500701746.wt drwxr-xr-x 2 mdb mdb 4096 Jan 9 10:14 journal -rw-r--r-- 1 mdb mdb 16384 Jan 9 10:35 _mdb_catalog.wt -rw-r--r-- 1 mdb mdb 0 Jan 9 10:35 mongod.lock -rw-r--r-- 1 mdb mdb 32768 Jan 9 10:35 sizeStorer.wt -rw-r--r-- 1 mdb mdb 95 Jan 9 10:14 storage.bson -rw-r--r-- 1 mdb mdb 49 Jan 9 10:14 WiredTiger -rw-r--r-- 1 mdb mdb 4096 Jan 9 10:35 WiredTigerLAS.wt -rw-r--r-- 1 mdb mdb 21 Jan 9 10:14 WiredTiger.lock -rw-r--r-- 1 mdb mdb 918 Jan 9 10:35 WiredTiger.turtle -rw-r--r-- 1 mdb mdb 45056 Jan 9 10:35 WiredTiger.wt [root@xxf db]# |
- mdb用户添加环境变量
1 2 3 4 5 6 7 8 9 |
[root@xxf db]# su - mdb [mdb@xxf ~]$ [mdb@xxf ~]$ [mdb@xxf ~]$ vi .bash_profile export PATH=/home/mdb/mongodb/bin:$PATH [mdb@xxf ~]$ . .bash_profile [mdb@xxf ~]$ |
- 启动MongoDB服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[mdb@xxf ~]$ mongod 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] MongoDB starting : pid=3197 port=27017 dbpath=/data/db 64-bit host=xxf 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] db version v3.2.1 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] allocator: tcmalloc 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] modules: none 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] build environment: 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] distmod: rhel55 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] distarch: x86_64 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] target_arch: x86_64 2016-01-09T13:29:29.806+0800 I CONTROL [initandlisten] options: {} 2016-01-09T13:29:29.833+0800 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2016-01-09T13:29:29.834+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 2016-01-09T13:29:33.337+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data' 2016-01-09T13:29:33.338+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker 2016-01-09T13:29:33.341+0800 I NETWORK [initandlisten] waiting for connections on port 27017 |
- 启动MongoDB shell(警告已经没有了)
1 2 3 4 5 6 7 8 9 10 |
[mdb@xxf ~]$ mongo MongoDB shell version: 3.2.1 connecting to: test Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user > |
- 我们用root用户再启动shell测试(效果完美)
1 2 3 4 5 6 7 8 9 |
[mdb@xxf ~]$ exit logout [root@xxf ~]# [root@xxf ~]# cd /home/mdb/mongodb/bin/ [root@xxf bin]# ./mongo MongoDB shell version: 3.2.1 connecting to: test > |
- 小结:MongoDB3.2在安装时,最好指定一个非root用户来进行部署。