{"id":4220,"date":"2024-03-12T16:50:00","date_gmt":"2024-03-12T08:50:00","guid":{"rendered":"https:\/\/www.fatesky.com\/?p=4220"},"modified":"2024-03-19T21:59:17","modified_gmt":"2024-03-19T13:59:17","slug":"centosrocky%e8%ae%be%e7%bd%ae%e5%bc%80%e6%9c%ba%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.fatesky.com\/?p=4220","title":{"rendered":"Centos&amp;Rocky\u8bbe\u7f6e\u5f00\u673a\u4fe1\u606f"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.fatesky.com\/wp-content\/uploads\/2024\/03\/image-2.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"433\" data-original=\"https:\/\/www.fatesky.com\/wp-content\/uploads\/2024\/03\/image-2.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-4222\"  sizes=\"auto, (max-width: 774px) 100vw, 774px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_1\u7ed9rclocal\u6743\u9650\"><a href=\"https:\/\/www.wamoyu.com\/#\/Linux\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF?id=_1%e7%bb%99rclocal%e6%9d%83%e9%99%90\">1.\u7ed9rc.local\u6743\u9650<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>chmod +x \/etc\/rc.d\/rc.local<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_2\u521b\u5efa\u5f00\u673a\u811a\u672c\u5e76\u4e14\u8d4b\u6743\"><a href=\"https:\/\/www.wamoyu.com\/#\/Linux\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF?id=_2%e5%88%9b%e5%bb%ba%e5%bc%80%e6%9c%ba%e8%84%9a%e6%9c%ac%e5%b9%b6%e4%b8%94%e8%b5%8b%e6%9d%83\">2.\u521b\u5efa\u5f00\u673a\u811a\u672c\u5e76\u4e14\u8d4b\u6743<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>cd ~&amp;&amp;touch OsInfo.sh&amp;&amp;chmod +x OsInfo.sh<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_3\u811a\u672c\u7f16\u5199\"><a href=\"https:\/\/www.wamoyu.com\/#\/Linux\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF?id=_3%e8%84%9a%e6%9c%ac%e7%bc%96%e5%86%99\">3.\u811a\u672c\u7f16\u5199<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>#!\/bin\/bash<\/strong>\n\n# \u6e05\u7a7a\necho \"\" &gt; \/etc\/issue\necho \"\" &gt; \/etc\/motd\n\n# \u83b7\u53d6\u6240\u6709\u7f51\u5361\u540d\u79f0\u53caIPv4\u5730\u5740\uff0c\u4e0d\u53bb\u6389\u5b50\u7f51\u63a9\u7801\nip=`ip addr | grep inet | grep -v inet6 | awk '{print(\"\\033&#91;34m|\\033&#91;0m\\033&#91;32m\",$NF,\"\\t-&gt;\",$2,\"\\033&#91;0m\")}'`\n\n# \u95f4\u9694\u7b26\nt1=\"\\033&#91;34m+----------------------------\\033&#91;0m\"\nt2=\"\\033&#91;34m|\\033&#91;0m\\033&#91;32m\"\nt3=\"\\033&#91;0m\"\n\n#********************\u4e0b\u65b9\u662f\u5f00\u673a\u63d0\u793a\u4fe1\u606f********************#\necho \"\" &gt;&gt; \/etc\/issue\necho -e \"$t1\" &gt;&gt; \/etc\/issue\necho -e \"$t2 CentOS 7 $3\" &gt;&gt; \/etc\/issue\necho -e \"$t1\" &gt;&gt; \/etc\/issue\necho -e \"$t2 UserName -&gt; root $3\" &gt;&gt; \/etc\/issue\necho -e \"$t2 PassWord -&gt; Test@123 $3\" &gt;&gt; \/etc\/issue\necho -e \"$t1\" &gt;&gt; \/etc\/issue\necho -e \"$t2 NetWork $3\" &gt;&gt; \/etc\/issue\necho -e \"$ip\" &gt;&gt; \/etc\/issue\necho -e \"$t1\" &gt;&gt; \/etc\/issue\necho \"\" &gt;&gt; \/etc\/issue\n\n#********************\u4e0b\u65b9\u662f\u767b\u5165\u540e\u4fe1\u606f********************#\necho \"\" &gt;&gt; \/etc\/motd\necho -e \"$t1\" &gt;&gt; \/etc\/motd\necho -e \"$t2 CentOS 7 $3\" &gt;&gt; \/etc\/motd\necho -e \"$t1\" &gt;&gt; \/etc\/motd\necho -e \"$t2 UserName -&gt; root $3\" &gt;&gt; \/etc\/motd\necho -e \"$t2 PassWord -&gt; Test@123 $3\" &gt;&gt; \/etc\/motd\necho -e \"$t1\" &gt;&gt; \/etc\/motd\necho -e \"$t2 NetWork $3\" &gt;&gt; \/etc\/motd\necho -e \"$ip\" &gt;&gt; \/etc\/motd\necho -e \"$t1\" &gt;&gt; \/etc\/motd\necho \"\" &gt;&gt; \/etc\/motd<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_4\u811a\u672c\u6dfb\u52a0\u5230rclocal\u4e2d\"><a href=\"https:\/\/www.wamoyu.com\/#\/Linux\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF?id=_4%e8%84%9a%e6%9c%ac%e6%b7%bb%e5%8a%a0%e5%88%b0rclocal%e4%b8%ad\">4.\u811a\u672c\u6dfb\u52a0\u5230rc.local\u4e2d<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>vim \/etc\/rc.d\/rc.local<\/code><\/code><\/pre>\n\n\n\n<p>\u5c06\u201c\/root\/hello.sh\u201d\u6dfb\u52a0\u5230rc.local\u7684\u672b\u5c3e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>bash \/root\/OsInfo.sh<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_5\u4f7f\u7528systemd\u670d\u52a1\"><a href=\"https:\/\/www.wamoyu.com\/#\/Linux\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF\/Centos&amp;Rocky%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E4%BF%A1%E6%81%AF?id=_5%e4%bd%bf%e7%94%a8systemd%e6%9c%8d%e5%8a%a1\">5.\u4f7f\u7528Systemd\u670d\u52a1<\/a><\/h2>\n\n\n\n<p>\u5728\u6700\u65b0\u7248\u672c\u7684CentOS\uff08\u5982CentOS 7\u53ca\u66f4\u9ad8\u7248\u672c\uff09\u4e2d\uff0c<code>\/etc\/rc.local<\/code>\u6587\u4ef6\u4e0d\u518d\u9ed8\u8ba4\u5b58\u5728\uff0c\u56e0\u6b64\u4e0d\u518d\u662f\u7cfb\u7edf\u542f\u52a8\u65f6\u6267\u884c\u81ea\u5b9a\u4e49\u811a\u672c\u7684\u63a8\u8350\u65b9\u5f0f\u3002\u53d6\u800c\u4ee3\u4e4b\u7684\u662f\u4f7f\u7528Systemd\u670d\u52a1\u5355\u5143\u6216Cron\u4f5c\u4e1a\u6765\u6267\u884c\u81ea\u5b9a\u4e49\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u66ff\u4ee3\u65b9\u6848\uff1a Systemd\u662f\u73b0\u4ee3Linux\u53d1\u884c\u7248\u4e2d\u5e38\u7528\u7684\u521d\u59cb\u5316\u7cfb\u7edf\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aSystemd\u670d\u52a1\u5355\u5143\uff0c\u4ee5\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u6267\u884c\u81ea\u5b9a\u4e49\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a\u00a0<\/p>\n\n\n\n<p><strong>1. \u521b\u5efa\u4e00\u4e2aSystemd\u670d\u52a1\u5355\u5143\u6587\u4ef6\uff08\u4f8b\u5982\uff0c<code>\/etc\/systemd\/system\/my-custom-script.service<\/code>\uff09\uff0c\u5e76\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00\u5b83\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo nano \/etc\/systemd\/system\/my-custom-script.service<\/code><\/code><\/pre>\n\n\n\n<p><strong>2. \u5728\u8be5\u6587\u4ef6\u4e2d\u5b9a\u4e49\u60a8\u7684\u81ea\u5b9a\u4e49\u811a\u672c\u670d\u52a1\u5355\u5143\u3002\u4f8b\u5982\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\nDescription=My Custom Script\n\n&#91;Service]\nType=oneshot\nExecStart=\/path\/to\/your\/script.sh\n\n&#91;Install]\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\uff0c<code>ExecStart<\/code>\u884c\u6307\u5b9a\u8981\u6267\u884c\u7684\u811a\u672c\u7684\u8def\u5f84\u3002\u00a0<\/p>\n\n\n\n<p><strong>3. \u4fdd\u5b58\u5e76\u5173\u95ed\u6587\u4ef6\u3002<\/strong>\u00a0<\/p>\n\n\n\n<p><strong>4. \u542f\u7528\u5e76\u542f\u52a8Systemd\u670d\u52a1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>sudo systemctl enable my-custom-script<\/code><code>sudo systemctl start my-custom-script<\/code><\/code><\/pre>\n\n\n\n<p> \u7981\u7528SELinux \u5c06SELINUX=enforcing \u6539\u4e3a SELINUX=disabled\uff0c\u4fdd\u5b58\u540e\u91cd\u542f\u5373\u53ef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.fatesky.com\/wp-content\/uploads\/2024\/03\/image-20231006195540020.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"962\" height=\"475\" data-original=\"https:\/\/www.fatesky.com\/wp-content\/uploads\/2024\/03\/image-20231006195540020.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-4221\"  sizes=\"auto, (max-width: 962px) 100vw, 962px\" \/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1.\u7ed9rc.local\u6743\u9650 2.\u521b\u5efa\u5f00\u673a\u811a\u672c\u5e76\u4e14\u8d4b\u6743 3.\u811a\u672c\u7f16\u5199 4.\u811a\u672c\u6dfb\u52a0\u5230rc.local\u4e2d \u5c06\u201c\/r [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[35],"class_list":["post-4220","post","type-post","status-publish","format-standard","hentry","category-2","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts\/4220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4220"}],"version-history":[{"count":1,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts\/4220\/revisions"}],"predecessor-version":[{"id":4223,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=\/wp\/v2\/posts\/4220\/revisions\/4223"}],"wp:attachment":[{"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fatesky.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}