一、配置 Nginx 自启动
1.创建 Nginx 自启动脚本 /lib/systemd/system/nginx.service
cd /lib/systemd/system
vi nginx.service
内容如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.如果 Nginx 进程存在,先删掉进程
pkill -9 nginx
3.设置开机自启动
systemctl enable nginx
4.启动服务
systemctl start nginx
二、配置 Redis 自启动
1.创建 Redis 自启动脚本 /lib/systemd/system/redis.service
cd /lib/systemd/system
vi redis.service
内容如下:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis-6.2.6/src/redis-server /usr/local/redis-6.2.6/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.如果 Redis 进程存在,先删掉进程
pkill -9 redis
3.设置开机自启动
systemctl enable redis
4.启动服务
systemctl start redis
三、配置 Elasticsearch 自启动
1.创建 Elasticsearch 自启动脚本 /lib/systemd/system/elasticsearch.service
cd /lib/systemd/system
vi elasticsearch.service
内容如下:
[Unit]
Description=elasticsearch
[Service]
Type=forking
User=es
LimitNOFILE=65536
LimitNPROC=65536
ExecStart=/usr/local/elasticsearch-7.15.2/bin/elasticsearch -d
[Install]
WantedBy=multi-user.target
2.如果 Elasticsearch 进程存在,先删掉进程
ps -ef|grep elasticsearch
kill -9 18736
3.设置开机自启动
systemctl enable elasticsearch
4.启动服务
systemctl start elasticsearch
四、配置 MongoDB 自启动
1.创建 MongoDB 自启动脚本 /lib/systemd/system/mongodb.service
cd /lib/systemd/system
vi mongodb.service
内容如下:
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb-linux-x86_64-rhel80-5.0.4/bin/mongod -f /usr/local/mongodb-linux-x86_64-rhel80-5.0.4/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb-linux-x86_64-rhel80-5.0.4/bin/mongod --shutdown --config /usr/local/mongodb-linux-x86_64-rhel80-5.0.4/mongodb.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.如果 MongoDB 进程存在,先删掉进程
ps -ef|grep mongodb
kill -9 18778
3.设置开机自启动
systemctl enable mongodb
4.启动服务
systemctl start mongodb
五、配置 RocketMQ 自启动
1.创建 RocketMQ 自启动脚本 /lib/systemd/system/rocketmqname.service 和 rocketmqbroker.service
cd /lib/systemd/system
vi rocketmqname.service
内容如下:
[Unit]
Description=rocketmq-nameserver
Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
After=network.target
[Service]
Type=sample
User=root
ExecStart=/usr/local/rocketmq-4.9.2/bin/mqnamesrv
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
vi rocketmqbroker.service
内容如下:
[Unit]
Description=rocketmq-broker
Documentation=http://mirror.bit.edu.cn/apache/rocketmq/
After=network.target
[Service]
Type=sample
User=root
ExecStart=/usr/local/rocketmq-4.9.2/bin/mqbroker -n localhost:9876
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=0
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
2.如果 RocketMQ 进程存在,先删掉进程
ps -ef|grep mqnamesrv
ps -ef|grep mqbroker
kill -9 18996 18997
3.设置开机自启动
systemctl enable rocketmqname
systemctl enable rocketmqbroker
4.启动服务
systemctl start rocketmqname
systemctl start rocketmqbroker
六、配置 Logstash 自启动
1.创建 Logstash 自启动脚本 /lib/systemd/system/logstash.service
cd /lib/systemd/system
vi logstash.service
内容如下:
[Unit]
Description=logstash
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=/usr/local/logstash-7.16.2/bin/logstash -f /usr/local/logstash-7.16.2/config/logstash-sample.conf
Restart=always
[Install]
WantedBy=multi-user.target
2.如果 Logstash 进程存在,先删掉进程
ps -ef|grep logstash
kill -9 19123
3.设置开机自启动
systemctl enable logstash
4.启动服务
systemctl start logstash
七、配置 Filebeat 自启动
1.创建 Filebeat 自启动脚本 /lib/systemd/system/filebeat.service
cd /lib/systemd/system
vi filebeat.service
内容如下:
[Unit]
Description=filebeat
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=/usr/local/filebeat-7.15.2-linux-x86_64/filebeat -e -c /usr/local/filebeat-7.15.2-linux-x86_64/filebeat.yml
Restart=always
[Install]
WantedBy=multi-user.target
2.如果 Filebeat 进程存在,先删掉进程
ps -ef|grep filebeat
kill -9 19125
3.设置开机自启动
systemctl enable filebeat
4.启动服务
systemctl start filebeat
八、配置 XXLJOB 自启动
1.创建 XXLJOB 自启动脚本 /lib/systemd/system/xxljobadmin.service 和 xxljobexecutor.service
cd /lib/systemd/system
vi xxljobadmin.service
内容如下:
[Unit]
Description=xxl-job-admin
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=java -jar /home/source/xxl-job/xxl-job-master/xxl-job-admin/target/xxl-job-admin-2.3.1-SNAPSHOT.jar
Restart=always
[Install]
WantedBy=multi-user.target
vi xxljobexecutor.service
内容如下:
[Unit]
Description=xxl-job-executor
Wants=network-online.target
After=network-online.target
[Service]
User=root
ExecStart=java -jar /home/source/xxl-job/xxl-job-master/xxl-job-executor-samples/xxl-job-executor-sample-springboot/target/xxl-job-executor-sample-springboot-2.3.1-SNAPSHOT.jar
Restart=always
[Install]
WantedBy=multi-user.target
2.如果 XXLJOB 进程存在,先删掉进程
ps -ef|grep xxl-job-executor
kill -9 19129
3.设置开机自启动
systemctl enable xxljobexecutor
4.启动服务
systemctl start xxljobexecutor
|