linux编译安装的服务程序使用systemctl管理——筑梦之路

这里主要举例nginx、redis、frp,其他类似。

nginx编译安装:

useradd -s /bin/false -M nginx

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_v2_module \
  --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
  
make && make install

##nginx 注册服务
cat  /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

systemctl daemon-reload

systemctl start nginx
systemctl enable nginx
systemctl stop nginx

redis编译安装:

cd redis-xxx

make && make test && make install

###redis 注册服务
cat /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis server v5.0.8  daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /data/redis/conf/redis.conf --daemonize yes 
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/bin/redis-cli -p 6379 -a password shutdown
User=root
Group=root
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl daemon-reload

systemctl start redis
systemctl enable redis
systemctl stop redis

frp注册服务:
cat /usr/lib/systemd/system/frpc.service 
[Unit]
Description=Frp Client Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/opt/frp/frpc -c /opt/frp/frpc.ini
ExecReload=/opt/frp/frpc reload -c /opt/frp/frpc.ini

[Install]
WantedBy=multi-user.target

systemctl start frpc
systemctl enable frpc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值