centos7下systemctl管理springboot微服务的基础配置

一. 关于systemctl的基本命令参考:http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html

二. 写service配置,两种方式:设定working目录,springboot会在working目录下寻找application.yml加载;不设定working目录,指定springboot配置文件
2.1 设定working目录:

vi /lib/systemd/system/test.service

[Unit]
Description=test 

[Service]
WorkingDirectory=/usr/local/test
PrivateTmp=true
Restart=always
Type=simple
ExecStart=/usr/local/java/jdk1.8.0_101/bin/java -jar /usr/local/test/test.jar
ExecStop=/usr/bin/kill -15  $MAINPID

[Install]
WantedBy=multi-user.target

2.2 指定springboot配置文件目录

[Unit]
Description=test 

[Service]
WorkingDirectory=/usr/local/test
PrivateTmp=true
Restart=always
Type=simple
ExecStart=/usr/local/java/jdk1.8.0_101/bin/java -jar /usr/local/test/test.jar --spring.config.location=/usr/local/test/application.yml
ExecStop=/usr/bin/kill -15  $MAINPID

[Install]
WantedBy=multi-user.target

三. systemctl 管理,让配置生效。若是修改配置文件,需要reload:

sudo systemctl daemon-reload
sudo systemctl enable test.service

启动服务

systemctl start test

四. 在CentOS 7 / RHEL 7的系统中,使用Systemd替代了之前的SysV,因此 /etc/security/limits.conf 文件的配置作用域缩小了一些。limits.conf的配置,只适用于通过PAM认证登录用户的资源限制,对systemd的service的资源限制不生效,所以这里需要在[Service]中配置limits:

[Service]
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=100000

运行命令使其生效:

systemctl daemon-reload
systemctl restart test.service

查看该进程的limits:

cat /proc/PID/limits

systemd官方文档: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html

你可能感兴趣的:(运维,springBoot,centos7)