文件夹位置
一些可能的文件夹位置:
Ubuntu 18.04.2 LTS: /lib/systemd/system
CentOS Linux 7 (Core): /usr/lib/systemd/system
使用方法
sudo systemctl daemon-reload
sudo systemctl start redis
sudo systemctl status redis
自动启动
# 成功后将显示:
# /etc/systemd/system/multi-user.target.wants/mongod.service → /lib/systemd/system/mongod.service
# 然后可实现开机自动启动
sudo systemctl enable mongod
配置文件参考
Redis: cat redis.service
[Unit]
Description=Redis In-Memory Data Store - by zhanglintc
After=multi-user.target
Documentation=https://redis.io/
[Service]
Environment="OPTIONS=--bind 127.0.0.1 --port 6379"
ExecStart=/usr/local/bin/redis-server $OPTIONS
ExecStartPre=/bin/mkdir -p /var/run/redis
ExecStartPre=/bin/chmod -R 0755 /var/run/redis
PIDFile=/var/run/redis/redis.pid
Restart=always
[Install]
WantedBy=multi-user.target
MongoDB(vbox, auto generated): cat mongod.service
[Unit]
Description=MongoDB Database Server
After=multi-user.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
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
MongoDB(ali, modified): cat mongod.service
[Unit]
Description=MongoDB Database Server - by zhanglintc
After=multi-user.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=root
Group=root
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod -f /etc/mongod.conf
ExecStartPre=/bin/mkdir -p /var/run/mongodb
ExecStartPre=/bin/chown mongodb:mongodb /var/run/mongodb
ExecStartPre=/bin/chmod 0755 /var/run/mongodb
Restart=always
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
# Type=forking
# Type=oneshot
RemainAfterExit=yes
# 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
Comments