- 配置MongoDB的yum源信息
- 创建文件
sudo touch /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
- 安装
sudo yum install -y mongodb-org
稍等片刻,安装完成
安装完成
- 查看一下MongoDB的配置文件
cat /etc/mongod.conf
# 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: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# 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: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
这里需要注意的是,使用yum安装MongoDB后,会自动创建mongod用户和mongod组,可以查看/etc/passwd
和 /etc/group
,里面新增了mongod
/etc/passwd
mongod:x:988:983:mongod:/var/lib/mongo:/bin/false
/etc/group
mongod:x:983:
- 启动
sudo systemctl start mongod.service
启动成功.
问题:
- 后来修改配置文件中的dbPath后,启动报错
修改配置文件中路径时,要注意把目录的所属组和用户变更为mongod,否则启动不起来(原本以为是这样)
修改MongoDB的dbPath为 /data
- 创建 /data目录
sudo mkdir -p /data
- 修改目录的权限
sudo chown -R mongod:mongod data
- 修改/etc/mongod.conf 文件,dbPath为
/data
sudo vim /etc/mongod.conf
启动失败!
查看日志,显示
2018-01-17T14:45:13.084+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] MongoDB starting : pid=21281 port=27017 dbpath=/data/ 64-bit host=hadoop1
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] db version v3.6.2
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] allocator: tcmalloc
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] modules: none
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] build environment:
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] distmod: rhel70
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] distarch: x86_64
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-01-17T14:45:13.095+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid", timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/data/", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2018-01-17T14:45:13.096+0800 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/, terminating
2018-01-17T14:45:13.096+0800 I CONTROL [initandlisten] now exiting
2018-01-17T14:45:13.096+0800 I CONTROL [initandlisten] shutting down with code:100
但是我已经设置/data文件所属组和用户了,目录权限是0755
然后我在/var/lib目录下创建了另外一个目录, /var/lib/testmongo',然后修改所属组和用户,修改
/etc/mongo.conf`,启动,还是不行.
2018-01-17T14:58:51.684+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] MongoDB starting : pid=24456 port=27017 dbpath=/var/lib/mongo/testmongo 64-bit host=hadoop1
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] db version v3.6.2
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] allocator: tcmalloc
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] modules: none
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] build environment:
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] distmod: rhel70
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] distarch: x86_64
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-01-17T14:58:51.698+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid", timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/var/lib/mongo/testmongo", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2018-01-17T14:58:51.698+0800 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /var/lib/mongo/testmongo not found., terminating
2018-01-17T14:58:51.699+0800 I CONTROL [initandlisten] now exiting
2018-01-17T14:58:51.699+0800 I CONTROL [initandlisten] shutting down with code:100
但是在/var/lib/mongo这个目录就可以,这是怎么回事?
查看 /etc/passwd mongod 用户的主目录是/var/lib/mongo ,和这个有关系吗? 我重新删除MongoDB后,先创建mongod 用户和组,并且指定家目录为/home/mongod,重新安装,还是不行....
用systemctl
启动不能修改路径,很奇怪.
后来重新下载mongodb-linux-x86_64-rhel70-3.6.2
,修改
vim /usr/lib/systemd/system/mongod.service
修改:
ExecStart=/home/hadoop/apps/mongodb-linux-x86_64-rhel70-3.6.2/bin/mongod -f /etc/mongod.conf
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
#User=hadoop
#Group=hadoop
#Environment="OPTIONS=-f /etc/mongod.conf"
#ExecStart=/usr/bin/mongod -f /etc/mongod.conf
ExecStart=/home/hadoop/apps/mongodb-linux-x86_64-rhel70-3.6.2/bin/mongod -f /etc/mongod.conf
PermissionsStartOnly=true
Type=forking
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target
使用systemctl daemon-reload
后重新启动systemctl start mongod.service
,则启动成功.
遇到的问题:
centos7 使用yum安装MongoDB后,修改默认的/etc/mongod.conf
中的dbPath
后,重新修改权限和用户,组,使用systemctl start mongod
启动失败,日志显示权限问题.直接使用 /usr/bin/mongod -f /etc/mongod.conf
则可以启动,
暂未解决.
网友评论