0
votes

I installed mongodb on a fresh centos 7
I run sudo service mongod start without any problem
When I change the port in /etc/mongod.conf and I restart the mongod service I get the following error

From /var/log/mongodb/mongod.log

2014-11-11T07:38:29.495+0000 [initandlisten] MongoDB starting : pid=12401 port=27022 dbpath=/var/lib/mongo 64-bit host=awscm001
2014-11-11T07:38:29.495+0000 [initandlisten] db version v2.6.5
2014-11-11T07:38:29.495+0000 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-11T07:38:29.495+0000 [initandlisten] build info: Linux build8.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-11-11T07:38:29.495+0000 [initandlisten] allocator: tcmalloc
2014-11-11T07:38:29.495+0000 [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27021 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } } 2014-11-11T07:38:29.497+0000 [initandlisten] journal dir=/var/lib/mongo/journal
2014-11-11T07:38:29.497+0000 [initandlisten] recover : no journal files present, no recovery needed
2014-11-11T07:38:29.679+0000 [initandlisten] ERROR: listen(): bind() failed errno:13 Permission denied for socket: 0.0.0.0:27022
2014-11-11T07:38:29.680+0000 [initandlisten] now exiting
2014-11-11T07:38:29.680+0000 [initandlisten] dbexit:
2014-11-11T07:38:29.680+0000 [initandlisten] shutdown: going to close listening sockets...
2014-11-11T07:38:29.680+0000 [initandlisten] shutdown: going to flush diaglog...

I am able though to run with a different port with the following command

sudo mongod -f /etc/mongod.conf

When I run as a service user mongod runs mongodb
When I run from command line root runs mongodb

How can run the mongodb service with a different port?
By the way I succeeded on centos 6.5
Thanks

1
Check if this port is in use by some other application using netstat command.vmr
I did netstat | grep 27022, nothing returnedashersz
Try with some other port??vmr
I tried already, it does not work, there is nothing special about 27022, but it seems that there is something special about 27017ashersz
Looks like mongod has not stopped properly. You can try 'sudo mongod stop' or 'pkill mongod' and then relogin and verify.vmr

1 Answers

0
votes

for those people having problem like me.. my fix is allow mongodb custom port on semanage

semanage port --list | grep mongo
mongod_port_t                  tcp      27017-27019, 28017-28019

as you can see, only 27017-27019, 28017-28019 is allowed. in order to add a custom port for mongodb

semanage port -a -t mongod_port_t -p tcp 21010

you now have added the custom port

 semanage port --list | grep mongo

 mongod_port_t                  tcp      21010, 27017-27019, 28017-28019    

make sure to restart mongodb