基于systemd配置服务开机自启

nacos

bash 复制代码
cat > /usr/lib/systemd/system/nacos.service <<'EOF'
[Unit]
Description=nacos server
After=network.target

[Service]
Type=forking
User=root
Environment="JAVA_HOME=/opt/java/jdk1.8.0_391"
ExecStart=/opt/nacos/bin/startup.sh -m standalone
ExecStop=shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now nacos

redis

bash 复制代码
cat > /usr/lib/systemd/system/redis.service <<'EOF'
[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
Type=forking
User=root
ExecStart=/opt/redis/bin/redis-server /opt/redis/bin/redis.conf

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now redis

rabbitmq-server

bash 复制代码
cat > /usr/lib/systemd/system/rabbitmq-server.service <<'EOF'
[Unit]
Description=RabbitMQ broker
After=syslog.target network.target

[Service]
Type=forking
User=root
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/erlang/bin:/opt/rabbitmq_server-3.13.1/sbin:/root/bin"
ExecStart=/opt/rabbitmq_server-3.13.1/sbin/rabbitmq-server -detached
ExecStop=/opt/rabbitmq_server-3.13.1/sbin/rabbitmqctl shutdown

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now rabbitmq-server

kkFileView

bash 复制代码
cat > /usr/lib/systemd/system/kkFileView.service <<'EOF'
[Unit]
Description=kkFileView server
After=network.target

[Service]
Type=forking
User=root
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/erlang/bin:/opt/rabbitmq_server-3.13.1/sbin:/root/bin"
ExecStart=/opt/kkFileView-4.3.0/bin/startup.sh
ExecStop=/opt/kkFileView-4.3.0/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now kkFileView

nginx

bash 复制代码
cat > /usr/lib/systemd/system/nginx.service <<'EOF'
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/opt/nginx/sbin/nginx -s reload

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now nginx

tomcat

bash 复制代码
cat > /usr/lib/systemd/system/tomcat.service <<'EOF'
[Unit]
Description=tomcat server
After=network.target

[Service]
Type=forking
User=root
Environment="JAVA_HOME=/opt/java/jdk1.8.0_371"
Environment="CLASSPATH=.:/opt/jdk1.8.0_371/lib/dt.jar:/opt/jdk1.8.0_371/lib/tools.jar"
Environment="PATH=/opt/jdk1.8.0_371/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin"
ExecStartPre=sleep 10
ExecStart=/opt/apache-tomcat-8.5.75/bin/startup.sh
ExecStop=/opt/apache-tomcat-8.5.75/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

systemctl enable --now tomcat
相关推荐
mit6.82437 分钟前
[Redis#3] 通用命令 | 数据类型 | 内部编码 | 单线程 | 快的原因
linux·redis·分布式
^Lim1 小时前
esp32 JTAG 串口 bootload升级
java·linux·网络
小林熬夜学编程1 小时前
【Linux系统编程】第五十弹---构建高效单例模式线程池、详解线程安全与可重入性、解析死锁与避免策略,以及STL与智能指针的线程安全性探究
linux·运维·服务器·c语言·c++·安全·单例模式
玖玖玖 柒染1 小时前
windows下sqlplus连接到linux oracle不成功
linux·windows·oracle
LuckyTHP1 小时前
CentOS 9 无法启动急救方法
linux·运维·centos
Bonne journée1 小时前
centos和ubuntu有什么区别?
linux·ubuntu·centos
vvw&1 小时前
如何在 Ubuntu 22.04 上安装带有 Nginx 的 ELK Stack
linux·运维·nginx·ubuntu·elk·elasticsearch·开源项目
Linux运维老纪1 小时前
交换机配置从IP(Switch Configuration from IP)
linux·服务器·网络·安全·运维开发·ip
OneSea1 小时前
Debian源码管理
linux
加载中loading...1 小时前
C/C++实现tcp客户端和服务端的实现(从零开始写自己的高性能服务器)
linux·运维·服务器·c语言·网络