Environment: Ubuntu 16.04
For example, php-fpm
and nginx
are run by the www
user, redis
is used The redis
user runs. When it comes to mongodb
, it seems that the user cannot be specified. By default, it is run as the root
user. A warning will be given every time when entering mongo
[initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
Attached is the mongodb startup script. Can this script be modified to specify a user to run mongodb?
#!/bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mongodb
# Description: mongo db server
### END INIT INFO
. /lib/lsb/init-functions
PROGRAM=/usr/local/mongodb/bin/mongod
MONGOPID=`ps -ef | grep 'mongod' | grep -v grep | awk '{print }'`
test -x $PROGRAM || exit 0
case "" in
start)
ulimit -n 3000
log_begin_msg "Starting MongoDB server"
$PROGRAM -f /usr/local/mongodb/mongo.conf
log_end_msg 0
;;
stop)
log_begin_msg "Stopping MongoDB server"
if [ ! -z "$MONGOPID" ]; then
kill -15 $MONGOPID
fi
log_end_msg 0
;;
status)
;;
*)
log_success_msg "Usage: /etc/init.d/mongodb {start|stop|status}"
exit 1
esac
exit 0
This is actually not a problem with mongodb, it should be considered more suitable for Linux. At least you can use the
sudo
来指定用户:sudo -u mongo $PROGRAM -f /usr/local/mongodb/mongo.conf
如果是用RPM安装,本身就带了
init.d
script, and you can refer to it for reference. Especially if it has been configured to disable NUMA, you need to pay attention to it.I don’t know if I understand what you mean. If you want to authorize users to log in, you only need to add users and add the --auth parameter when mongod starts to enable login authorization. At this time, log in in the default way, that is, log in as an unauthenticated user, and you will be prompted that you have no permissions when performing queries and other operations.
Considering security, all are allocated according to rights. As many permissions as needed are allocated. This is the basic principle of Linux security.