{"id":135745,"date":"2019-02-15T09:03:55","date_gmt":"2019-02-15T01:03:55","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=135745"},"modified":"2019-02-11T15:05:15","modified_gmt":"2019-02-11T07:05:15","slug":"centos7-systemct-server","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos7-systemct-server.html","title":{"rendered":"CentOS7\u5229\u7528systemctl\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7cfb\u7edf\u670d\u52a1"},"content":{"rendered":"
CentOS7\u7684\u670d\u52a1systemctl\u811a\u672c\u5b58\u653e\u5728:\/usr\/lib\/systemd\/,\u6709\u7cfb\u7edf\uff08system\uff09\u548c\u7528\u6237\uff08user\uff09\u4e4b\u5206,\u9700\u8981\u5f00\u673a\u4e0d\u767b\u9646\u5c31\u80fd\u8fd0\u884c\u7684\u7a0b\u5e8f\uff0c\u5b58\u5728\u7cfb\u7edf\u670d\u52a1\u91cc\uff0c\u5373\uff1a\/usr\/lib\/systemd\/system\u76ee\u5f55\u4e0b.
\nCentOS7\u7684\u6bcf\u4e00\u4e2a\u670d\u52a1\u4ee5.service\u7ed3\u5c3e\uff0c\u4e00\u822c\u4f1a\u5206\u4e3a3\u90e8\u5206\uff1a[Unit]\u3001[Service]\u548c[Install]<\/div>\n
[Unit]<\/strong><\/span><\/div>\n

\u90e8\u5206\u4e3b\u8981\u662f\u5bf9\u8fd9\u4e2a\u670d\u52a1\u7684\u8bf4\u660e\uff0c\u5185\u5bb9\u5305\u62ecDescription\u548cAfter\uff0cDescription \u7528\u4e8e\u63cf\u8ff0\u670d\u52a1\uff0cAfter\u7528\u4e8e\u63cf\u8ff0\u670d\u52a1\u7c7b\u522b<\/p>\n

[Service]\u90e8\u5206\u662f\u670d\u52a1\u7684\u5173\u952e\uff0c\u662f\u670d\u52a1\u7684\u4e00\u4e9b\u5177\u4f53\u8fd0\u884c\u53c2\u6570\u7684\u8bbe\u7f6e.
\nType=forking\u662f\u540e\u53f0\u8fd0\u884c\u7684\u5f62\u5f0f\uff0c
\nUser=users\u662f\u8bbe\u7f6e\u670d\u52a1\u8fd0\u884c\u7684\u7528\u6237,
\nGroup=users\u662f\u8bbe\u7f6e\u670d\u52a1\u8fd0\u884c\u7684\u7528\u6237\u7ec4,
\nPIDFile\u4e3a\u5b58\u653ePID\u7684\u6587\u4ef6\u8def\u5f84\uff0c
\nExecStart\u4e3a\u670d\u52a1\u7684\u5177\u4f53\u8fd0\u884c\u547d\u4ee4,
\nExecReload\u4e3a\u91cd\u542f\u547d\u4ee4\uff0c
\nExecStop\u4e3a\u505c\u6b62\u547d\u4ee4\uff0c
\nPrivateTmp=True\u8868\u793a\u7ed9\u670d\u52a1\u5206\u914d\u72ec\u7acb\u7684\u4e34\u65f6\u7a7a\u95f4<\/p>\n

[Service]<\/strong><\/span><\/div>\n

\u6ce8\u610f\uff1a[Service]\u90e8\u5206\u7684\u542f\u52a8\u3001\u91cd\u542f\u3001\u505c\u6b62\u547d\u4ee4\u5168\u90e8\u8981\u6c42\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\uff0c\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u5219\u4f1a\u62a5\u9519\uff01<\/p>\n

[Install]<\/strong><\/span><\/div>\n

[Install]\u90e8\u5206\u662f\u670d\u52a1\u5b89\u88c5\u7684\u76f8\u5173\u8bbe\u7f6e\uff0c\u53ef\u8bbe\u7f6e\u4e3a\u591a\u7528\u6237\u7684
\n\u9996\u5148\uff0c\u4f7f\u7528systemctl start [ \u670d\u52a1\u540d(\u4e5f\u662f\u6587\u4ef6\u540d) ] \u53ef\u6d4b\u8bd5\u670d\u52a1\u662f\u5426\u53ef\u4ee5\u6210\u529f\u8fd0\u884c\uff0c\u5982\u679c\u4e0d\u80fd\u8fd0\u884c\u5219\u53ef\u4ee5\u4f7f\u7528systemctl status [ \u670d\u52a1\u540d(\u4e5f\u662f\u6587\u4ef6\u540d) ]\u67e5\u770b\u9519\u8bef\u4fe1\u606f\u548c\u5176\u4ed6\u670d\u52a1\u4fe1\u606f\uff0c\u7136\u540e\u6839\u636e\u62a5\u9519\u8fdb\u884c\u4fee\u6539\uff0c\u76f4\u5230\u53ef\u4ee5start\uff0c\u5982\u679c\u4e0d\u653e\u5fc3\u8fd8\u53ef\u4ee5\u6d4b\u8bd5restart\u548cstop\u547d\u4ee4\u3002<\/p>\n

\u63a5\u7740\uff0c\u53ea\u8981\u4f7f\u7528systemctl enable xxxxx\u5c31\u53ef\u4ee5\u5c06\u6240\u7f16\u5199\u7684\u670d\u52a1\u6dfb\u52a0\u81f3\u5f00\u673a\u542f\u52a8\u5373\u53ef\u3002<\/p>\n

\u5b9e\u4f8b\uff1a\u670d\u52a1\u7528\u4e8e\u5f00\u673a\u8fd0\u884ctomcat\u9879\u76ee:<\/p>\n

#vim \/usr\/lib\/systemd\/system\/tomcat.service\r\n \r\n[Unit]\r\nDescription=java tomcat project\r\nAfter=tomcat.service\r\n\r\n[Service]\r\nType=forking\r\nUser=users\r\nGroup=users\r\nPIDFile=\/usr\/local\/tomcat\/tomcat.pid\r\nExecStart=\/usr\/local\/tomcat\/bin\/startup.sh\r\nExecReload=\r\nExecStop=\/usr\/local\/tomcat\/bin\/shutdown.sh\r\nPrivateTmp=true\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n
\u670d\u52a1\u64cd\u4f5c<\/strong><\/span><\/div>\n

\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\uff1a<\/p>\n

chmod 754 \/usr\/lib\/systemd\/system\/tomcat.service<\/pre>\n

\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n

#systemctl enable tomcat.service<\/pre>\n

\u5e38\u7528\u6307\u4ee4(\u4ee5tomcat\u670d\u52a1\u4e3a\u4f8b)\uff1a
\n\u542f\u52a8\u67d0\u670d\u52a1<\/p>\n

systemctl start tomcat.service<\/pre>\n

\u505c\u6b62\u67d0\u670d\u52a1<\/p>\n

systemctl stop tomcat.service<\/pre>\n

\u91cd\u542f\u67d0\u670d\u52a1<\/p>\n

service tomcat restart\r\n\r\nsystemctl restart tomcat.service<\/pre>\n

\u4f7f\u67d0\u670d\u52a1\u81ea\u52a8\u542f\u52a8(\u5982tomcat\u670d\u52a1)<\/p>\n

systemctl enable tomcat.service<\/pre>\n

\u4f7f\u67d0\u670d\u52a1\u4e0d\u81ea\u52a8\u542f\u52a8<\/p>\n

systemctl disable tomcat.service<\/pre>\n

\u68c0\u67e5\u670d\u52a1\u72b6\u6001<\/p>\n

systemctl status tomcat.service \uff08\u670d\u52a1\u8be6\u7ec6\u4fe1\u606f\uff09\r\n\r\nsystemctl is-active tomcat.service\uff08\u4ec5\u663e\u793a\u662f\u5426Active)<\/pre>\n

\u663e\u793a\u6240\u6709\u5df2\u542f\u52a8\u7684\u670d\u52a1<\/p>\n

systemctl list-units --type=service<\/pre>\n","protected":false},"excerpt":{"rendered":"

CentOS7\u7684\u670d\u52a1systemctl\u811a\u672c\u5b58\u653e\u5728:\/usr\/lib\/systemd\/,\u6709\u7cfb\u7edf\uff08system\uff09\u548c […]<\/p>\n","protected":false},"author":643,"featured_media":135747,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-135745","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/135745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=135745"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/135745\/revisions"}],"predecessor-version":[{"id":135833,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/135745\/revisions\/135833"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/135747"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=135745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=135745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=135745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}