Python数据分析及可视化实例之CentOS7.2+MongoDB V3.4 安装

Python数据分析及可视化实例之CentOS7.2+MongoDB V3.4 安装

系列文章总目录:Python数据分析及可视化实例目录


我不是程序员,也不是设计师,我只是碰巧有一些想法和一台电脑。
I am not a designer nor a coder. I'm just a guy with a point-of-view and a computer.

Step1.配置 yum

vim /etc/yum.repos.d/MongoDB-org-3.4.repo

在其中输入

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/testing/x86_64/
gpgcheck=1
enabled=1 
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc


然后输入如下命令进行安装

sudo yum install -y mongodb-org


如果想要安装其他版本的Mongodb可以点开参考链接里面有更详细的安装指南。

服务管理

service mongod start #启动
service mongod stop #停止
service mongod restart #重启


Step2.配置Mongodb

配置文件路径: /etc/mongod.conf。

若要自己指定数据存储位置和日志的存储位置,我们可以修改MongoDB的配置文件。

举个例子:

若要将数据文件存储在 /home/data/mongo

日志文件存储在 /home/data/log/mongodb.log

注意: 这两个存储的位置要给MongoDB足够的权限来操作,否则会报错

则将配置文件对应部分修改,其他不变

# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/data/log/mongod.log
# Where and how to store data.
storage:
dbPath: /home/data/mongo
journal:
enabled: true


然后,通过指定配置文件启动MongoDB。

mongod -f /etc/mongod.conf


默认会在后台运行,出现信息

about to fork child process, waiting until server is ready for connections.

forked process: 10286

child process started successfully, parent exiting

如果没有后台运行,可以检查配置文件中

# how the process runs

processManagement:

fork: true # 这里是不是 true

直接使用命令来后台运行MongoDB

mongod –fork –dbpath [dbpath] –logpath [logpath]

这里 [dbpath] 是数据文件夹的路径,[logpath] 是日志文件的路径。
例如,还是上面的存储位置,
数据文件存储在 /home/data/mongo
日志文件存储在 /home/data/log/mongodb.log
mongod –fork –dbpath /home/data/mongo –logpath /home/data/log/mongodb.log
关闭后台运行


Step3.终端运行

mongo
use admin
db.shutdownServer()

提示:

启动服务前,先查看一下端口是否被占用,若被占用可以添加 –port 参数来指定端口。

netstat -ap | grep [port]


关闭后台运行的指定了其他端口的MongoDB,连接数据库时也要加端口号。

mongo localhost:port

Step4.消除警告

[root@yeayee.com ~]# mongo

MongoDB shell version v3.4.0

connecting to: mongodb://127.0.0.1:27017

MongoDB server version: 3.4.0

Server has startup warnings:

2016-12-13T15:46:47.201+0800 I STORAGE [initandlisten]

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten]

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** Read
and write access to data and configuration is unrestricted.

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** WARNING: You
are running this process as the root user, which is not recommended.

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten]

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten]

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.

2016-12-13T15:46:47.889+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'

2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten]

2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.

2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'

2016-12-13T15:46:47.890+0800 I CONTROL [initandlisten]


消除警告

vi /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

ulimit -u 65535


[root@yeayee.com ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled

[root@yeayee.com ~]# echo never > /sys/kernel/mm/transparent_hugepage/defrag

停止服务:

> use admin

switched to db admin

> db.shutdownServer();

server should be down...

2016-12-13T16:22:14.996+0800 I NETWORK [main] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed

2016-12-13T16:22:14.997+0800 W NETWORK [main] Failed to connect to 127.0.0.1:27017, reason: Connection refused

2016-12-13T16:22:14.997+0800 I NETWORK [main] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed


>

>

>

> quit

function quit() {

[native code]

}

> exit

bye


胶水语言博大精深,

本主只得一二为新人带路,

老鸟可去另一专栏:Python中文社区

新手可查阅历史目录:

Python数据分析及可视化实例目录



最后,别只收藏不关注哈

编辑于 2017-10-13

文章被以下专栏收录