今天被问到 mongodb,centos 7.6的自启动,报错
Jun 16 11:34:39 localhost rc.local: ERROR: child process failed, exited with error number 1 Jun 16 11:34:39 localhost rc.local: To see additional information in this output, start without the "--fork" option.
查看log日志
2020-06-16T11:49:50.545+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory ‘/home/ceiec/mongodb/mongodb-3.6.9/data/diagnostic.data‘ 2020-06-16T11:49:50.546+0800 I NETWORK [initandlisten] waiting for connections on port 27017 2020-06-16T11:50:16.684+0800 I CONTROL [signalProcessingThread] got signal 1 (Hangup), will terminate after current cmd ends 2020-06-16T11:50:16.684+0800 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...
发现是启动mongodb后,被某个进程给kill掉了
一开始的启动脚本
在/etc/init.d 下面一个脚本,比如auto_mongo.sh,
/usr/bin/mongod --fork -f /etc/mongod.conf
然后添加chkconfig,单独运行脚本是可以的,就是开机启动不行。
检查了涉及到的文件和文件夹的权限
chown -R mongod:mongod /home/data/mongodb
chown -R mongod:mongod /usr/bin/mongo
在启动的时候 也显式的加了--fork,还是报错
于是新找了一台centos 7.4 ,进行rpm安装
[root@iscsi opt]# rpm -ivh mongodb-org-* warning: mongodb-org-3.6.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mongodb-org-tools-3.6.13-1.el7 ################################# [ 20%] 2:mongodb-org-shell-3.6.13-1.el7 ################################# [ 40%] error: %pre(mongodb-org-server-3.6.13-1.el7.x86_64) scriptlet failed, exit status 1 error: mongodb-org-server-3.6.13-1.el7.x86_64: install failed 3:mongodb-org-mongos-3.6.13-1.el7 ################################# [ 60%] 4:mongodb-org-3.6.13-1.el7 ################################# [ 80%] [root@iscsi opt]# rpm -qa |grep mongodb mongodb-org-mongos-3.6.13-1.el7.x86_64 mongodb-org-3.6.13-1.el7.x86_64 mongodb-org-tools-3.6.13-1.el7.x86_64 mongodb-org-shell-3.6.13-1.el7.x86_64 [root@iscsi opt]# vim /etc/selinux/config [root@iscsi opt]# setenforce 0 [root@iscsi opt]# getenforce Permissive [root@iscsi opt]# yum localinstall mongodb-org-*.rpm [root@iscsi opt]# rpm -ivh mongodb-org-server-3.6.13-1.el7.x86_64.rpm warning: mongodb-org-server-3.6.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY Preparing... ################################# [100%] error: %pre(mongodb-org-server-3.6.13-1.el7.x86_64) scriptlet failed, exit status 1 error: mongodb-org-server-3.6.13-1.el7.x86_64: install failed --https://www.bbsmax.com/A/kjdw6X9A5N/ 使用root权限都不能编辑某个文件,很可能是使用chattr命令锁定该文件了。通过chattr命令修改属性能够提高系统的安全性, 但是它并不适合所有的目录。chattr命令不能保护/、/dev、/tmp、/var目录。lsattr命令是显示chattr命令设置的文件属性。 # chattr +i /etc/shadow ##使用chattr -i file加锁 [root@iscsi opt]# lsattr /etc/shadow ----i----------- /etc/shadow [root@iscsi opt]# chattr -i /etc/shadow [root@iscsi opt]# groupdel mongod [root@iscsi opt]# rpm -ivh mongodb-org-server-3.6.13-1.el7.x86_64.rpm warning: mongodb-org-server-3.6.13-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 91fa4ad5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:mongodb-org-server-3.6.13-1.el7 ################################# [100%] Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service. [root@iscsi opt]# rpm -qa|grep mongod mongodb-org-mongos-3.6.13-1.el7.x86_64 mongodb-org-3.6.13-1.el7.x86_64 mongodb-org-shell-3.6.13-1.el7.x86_64 mongodb-org-server-3.6.13-1.el7.x86_64 mongodb-org-tools-3.6.13-1.el7.x86_64 [root@iscsi opt]# whereis mongod mongod: /usr/bin/mongod /etc/mongod.conf /usr/share/man/man1/mongod.1
cat >> /etc/hosts << EOF 10.15.7.20 iscsi EOF echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag cat >> /etc/rc.d/rc.local << EOF #toku,mongodb3.6 echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag EOF # /usr/local/mongodb/bin/mongostat --host=10.11.48.65 --port=27017 # /usr/local/mongodb/bin/mongotop --host=10.11.48.65 --port=27017 cat >> /etc/profile << EOF export PATH=/usr/bin:$PATH EOF source /etc/profile cat >> /etc/profile << EOF export HISTTIMEFORMAT=‘%F %T ‘ EOF mkdir -p /home/data/mongodb [root@iscsi opt]# id mongod uid=990(mongod) gid=985(mongod) groups=985(mongod) chown -R mongod:mongod /home/data/mongodb chown -R mongod:mongod /usr/bin/mongo cd /home/data/mongodb/ mkdir data chown -R mongod:mongod /home/data/mongodb/ [mongodb@localhost mongodb]$ vim mongodb.conf port=27017 bind_ip=10.15.7.20 logpath=/home/data/mongodb/mongodb01.log dbpath=/home/data/mongodb/data logappend=true pidfilepath=/home/data/mongodb/mongodb01.pid fork=true oplogSize=1024 replSet=MyMongo /usr/bin/mongod -f /home/data/mongodb/mongodb.conf [root@iscsi mongodb]# vim /etc/rc.d/rc.local [root@iscsi mongodb]# chmod +x /etc/rc.d/rc.local
然后重启是ok的。
-----------------
在出问题的机器上进行调试
在/etc/rc.d/rc.local加入strace命令,进行启动程序跟踪(在正常启动与不正常的日志中进行对比)
strace -tt -s 10000 -f -o mongo.txt /usr/bin/mongod --fork -f /etc/mongod.conf
发现有涉及selinux;;这个时候,他们说他们安装的时候没有关闭selinux,于是他们关闭了selinux,然后自启动,就可以了~~~~
请注意:我在另外安装rpm的时候,一开始就关闭selinux,所以没有第一时间想到这里,走了一定的弯路。。。。
Mongodb rpm安装,自启动报错--got signal 1 (Hangup), will terminate after current cmd ends