{"id":3722,"date":"2014-11-16T11:26:37","date_gmt":"2014-11-16T03:26:37","guid":{"rendered":"http:\/\/rmohan.com\/?p=3722"},"modified":"2015-12-30T15:52:24","modified_gmt":"2015-12-30T07:52:24","slug":"centos-7-systemctl","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3722","title":{"rendered":"Centos 7 SYSTEMCTL  &#038;&#038;  Run level &#038;&#038; hostname"},"content":{"rendered":"<p><strong>Centos 7 SYSTEMCTL &amp;&amp; Run level &amp;&amp; hostname <\/strong><\/p>\n<p>Centos 7 SYSTEMCTL &amp;&amp; Run level &amp;&amp; hostname<\/p>\n<p>systemctl start httpd.service (service httpd start)<\/p>\n<p>systemctl stop httpd.service ( service httpd stop)<\/p>\n<p>systemctl restart httpd.service ( service httpd stop)<\/p>\n<p>systemctl status httpd.service ( service httpd status)<\/p>\n<p>systemctl enable httpd.service (chkconfig httpd on)<\/p>\n<p>systemctl disable httpd.service (chkconfig httpd off)<\/p>\n<p>job chkconfig?service systemctl<br \/>\nService boot from the start chkconfig &#8211;level 3 httpd on systemctl enable httpd<br \/>\nService does not boot from the start chkconfig &#8211;level 3 httpd off systemctl disable httpd<\/p>\n<p>Service Status service httpd status systemctl status HTTP d (service details)<\/p>\n<p>systemctl is-active httpd<\/p>\n<p>Start the status of all services chkconfig &#8211;list systemctl list-units &#8211;type=service<br \/>\nStart Service service httpd start systemctl start httpd<br \/>\nOut of service service httpd stop systemctl stop httpd<br \/>\nRestart the service service httpd restart systemctl restart httpd<\/p>\n<p>[root@keeplive ~]# cat \/etc\/inittab<br \/>\n# inittab is no longer used when using systemd.<br \/>\n#<br \/>\n# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.<br \/>\n#<br \/>\n# Ctrl-Alt-Delete is handled by \/etc\/systemd\/system\/ctrl-alt-del.target<br \/>\n#<br \/>\n# systemd uses &#8216;targets&#8217; instead of runlevels. By default, there are two main targets:<br \/>\n#<br \/>\n# multi-user.target: analogous to runlevel 3<br \/>\n# graphical.target: analogous to runlevel 5<br \/>\n#<br \/>\n# To set a default target, run:<br \/>\n#<br \/>\n# ln -sf \/lib\/systemd\/system\/.target \/etc\/systemd\/system\/default.target<\/p>\n<p>From the command-line switch to the window level level command unchanged: init 5 or startx<\/p>\n<p>Level by the window switch to the command line level commands unchanged: init 3<\/p>\n<p>The new version of the run level is defined in the \/lib\/systemd\/system:<\/p>\n<p>[root@keeplive ~]# ls -ltr \/lib\/systemd\/system\/runlevel*.target<br \/>\nlrwxrwxrwx. 1 root root 15 Nov 13 08:46 \/lib\/systemd\/system\/runlevel0.target -&gt; poweroff.target<br \/>\nlrwxrwxrwx. 1 root root 13 Nov 13 08:46 \/lib\/systemd\/system\/runlevel1.target -&gt; rescue.target<br \/>\nlrwxrwxrwx. 1 root root 17 Nov 13 08:46 \/lib\/systemd\/system\/runlevel2.target -&gt; multi-user.target<br \/>\nlrwxrwxrwx. 1 root root 17 Nov 13 08:46 \/lib\/systemd\/system\/runlevel4.target -&gt; multi-user.target<br \/>\nlrwxrwxrwx. 1 root root 17 Nov 13 08:46 \/lib\/systemd\/system\/runlevel3.target -&gt; multi-user.target<br \/>\nlrwxrwxrwx. 1 root root 16 Nov 13 08:46 \/lib\/systemd\/system\/runlevel5.target -&gt; graphical.target<br \/>\nlrwxrwxrwx. 1 root root 13 Nov 13 08:46 \/lib\/systemd\/system\/runlevel6.target -&gt; reboot.target<\/p>\n<p>You can set different run levels for different needs:<\/p>\n<p>init 3<\/p>\n<p>[root@keeplive ~]# ln -svf \/lib\/systemd\/system\/runlevel3.target \/etc\/systemd\/system\/default.target<br \/>\n\u2018\/etc\/systemd\/system\/default.target\u2019 -&gt; \u2018\/lib\/systemd\/system\/runlevel3.target\u2019<br \/>\n[root@keeplive ~]# ln -svf \/lib\/systemd\/system\/multi-user.target \/etc\/systemd\/system\/default.target<br \/>\n\u2018\/etc\/systemd\/system\/default.target\u2019 -&gt; \u2018\/lib\/systemd\/system\/multi-user.target\u2019<br \/>\n[root@keeplive ~]# systemctl set-default multi-user.target<br \/>\nrm &#8216;\/etc\/systemd\/system\/default.target&#8217;<br \/>\nln -s &#8216;\/usr\/lib\/systemd\/system\/multi-user.target&#8217; &#8216;\/etc\/systemd\/system\/default.target&#8217;<br \/>\n[root@keeplive ~]#<\/p>\n<p>INIT5<\/p>\n<p>[root@keeplive ~]# ln -svf \/lib\/systemd\/system\/runlevel5.target \/etc\/systemd\/system\/default.target<br \/>\n\u2018\/etc\/systemd\/system\/default.target\u2019 -&gt; \u2018\/lib\/systemd\/system\/runlevel5.target\u2019<br \/>\n[root@keeplive ~]# ln -svf \/lib\/systemd\/system\/graphical.target \/etc\/systemd\/system\/default.target<br \/>\n\u2018\/etc\/systemd\/system\/default.target\u2019 -&gt; \u2018\/lib\/systemd\/system\/graphical.target\u2019<br \/>\n[root@keeplive ~]# systemctl set-default graphical.target<br \/>\nrm &#8216;\/etc\/systemd\/system\/default.target&#8217;<br \/>\nln -s &#8216;\/usr\/lib\/systemd\/system\/graphical.target&#8217; &#8216;\/etc\/systemd\/system\/default.target&#8217;<\/p>\n<p>Modify the system run level:<br \/>\n1, systemd use than run the target level sysvinit more liberal alternative. Run Level 3 replaced by multi-user.target. Run Level 5 replaced by graphical.target. runlevel3.target and runlevel5.target are directed multi-user.target and graphical.target symbolic links.<br \/>\nYou can use the following command to switch to &#8220;run level 3&#8221;:<br \/>\nmulti-user.target systemctl isolate or systemctl isolate runlevel3.target<\/p>\n<p>You can use the following command to switch to the &#8220;Run Level 5&#8221;:<br \/>\nsystemctl isolate graphical.target or systemctl isolate runlevel5.target<\/p>\n<p>2, how to change the default runlevel?<br \/>\nsystemd use links to point to the default run level. Before creating a new link, can use the following command to remove the presence of link: rm \/etc\/systemd\/system\/default.target<br \/>\ndefault startup run level 3:<br \/>\nln -sf \/lib\/systemd\/system\/multi-user.target \/etc\/systemd\/system\/default.target<\/p>\n<p>ln -sf \/lib\/systemd\/system\/graphical.target \/etc\/systemd\/system\/default.target<\/p>\n<p>systemd does not use \/etc\/inittab file.<\/p>\n<p>Modify CentOS 7 hostname<\/p>\n<p>In CentOS, there are three definitions hostname: static (static), transient (transient), and flexible (pretty). &#8220;Static&#8221; host name is also called kernel hostname, is the system at boot time from \/etc\/hostname<br \/>\nautomatic initialization of the host name. &#8220;Transient&#8221; host name is in the system is running temporarily assigned host name, for example, assigned by DHCP or mDNS server.<br \/>\nStatic hostname and transient hostname comply with the same character as the Internet domain restriction rules. On the other hand, a &#8220;flexible&#8221; is allowed to use<br \/>\nthe hostname of free-form (including special \/ whitespace) host name, to show to the end user (eg Linuxidc).<\/p>\n<p>In CentOS 7, a man named hostnamectl command-line tool that allows you to view or modify the host name associated with the configuration.<\/p>\n<p>[root@keeplive ~]# hostnamectl<br \/>\nStatic hostname: keeplive<br \/>\nIcon name: computer<br \/>\nChassis: n\/a<br \/>\nMachine ID: 2b48dba259f2428ca8038f7aeb1d7f15<br \/>\nBoot ID: 57772bec11854cd08ee72db54a1441d3<br \/>\nVirtualization: vmware<br \/>\nOperating System: CentOS Linux 7 (Core)<br \/>\nCPE OS Name: cpe:\/o:centos:centos:7<br \/>\nKernel: Linux 3.10.0-123.9.3.el7.x86_64<br \/>\nArchitecture: x86_64<br \/>\n[root@keeplive ~]# hostnamectl status<br \/>\nStatic hostname: keeplive<br \/>\nIcon name: computer<br \/>\nChassis: n\/a<br \/>\nMachine ID: 2b48dba259f2428ca8038f7aeb1d7f15<br \/>\nBoot ID: 57772bec11854cd08ee72db54a1441d3<br \/>\nVirtualization: vmware<br \/>\nOperating System: CentOS Linux 7 (Core)<br \/>\nCPE OS Name: cpe:\/o:centos:centos:7<br \/>\nKernel: Linux 3.10.0-123.9.3.el7.x86_64<br \/>\nArchitecture: x86_64<br \/>\n[root@keeplive ~]# hostnamectl &#8211;static<br \/>\nkeeplive<br \/>\n[root@keeplive ~]# hostnamectl &#8211;transient<br \/>\nkeeplive<br \/>\n[root@keeplive ~]# hostnamectl &#8211;pretty<\/p>\n<p>&nbsp;<br \/>\n[root@rhel7 ~]# systemctl list-unit-files|grep enabled<br \/>\ncups.path enabled<br \/>\nabrt-ccpp.service enabled<br \/>\nabrt-oops.service enabled<br \/>\nabrt-vmcore.service enabled<br \/>\nabrt-xorg.service enabled<br \/>\nabrtd.service enabled<br \/>\naccounts-daemon.service enabled<br \/>\natd.service enabled<br \/>\nauditd.service enabled<br \/>\navahi-daemon.service enabled<br \/>\nbluetooth.service enabled<br \/>\nchronyd.service enabled<br \/>\ncrond.service enabled<br \/>\ncups.service enabled<br \/>\ndbus-org.bluez.service enabled<br \/>\ndbus-org.fedoraproject.FirewallD1.service enabled<br \/>\ndbus-org.freedesktop.Avahi.service enabled<br \/>\ndbus-org.freedesktop.ModemManager1.service enabled<br \/>\ndbus-org.freedesktop.NetworkManager.service enabled<br \/>\ndbus-org.freedesktop.nm-dispatcher.service enabled<br \/>\ndisplay-manager.service enabled<br \/>\ndmraid-activation.service enabled<br \/>\nfirewalld.service enabled<br \/>\nfirstboot-graphical.service enabled<br \/>\ngdm.service enabled<br \/>\ngetty@.service enabled<br \/>\nhypervkvpd.service enabled<br \/>\nhypervvssd.service enabled<br \/>\nirqbalance.service enabled<br \/>\niscsi.service enabled<br \/>\nksm.service enabled<br \/>\nksmtuned.service enabled<br \/>\nlibstoragemgmt.service enabled<br \/>\nlibvirtd.service enabled<br \/>\nlvm2-monitor.service enabled<br \/>\nmdmonitor.service enabled<br \/>\nmicrocode.service enabled<br \/>\nModemManager.service enabled<br \/>\nmultipathd.service enabled<br \/>\nNetworkManager-dispatcher.service enabled<br \/>\nNetworkManager.service enabled<br \/>\nnfs-lock.service enabled<br \/>\npackagekit-offline-update.service enabled<br \/>\npostfix.service enabled<br \/>\nrhsmcertd.service enabled<br \/>\nrngd.service enabled<br \/>\nrpcbind.service enabled<br \/>\nrsyslog.service enabled<br \/>\nrtkit-daemon.service enabled<br \/>\nsmartd.service enabled<br \/>\nspice-vdagentd.service enabled<br \/>\nsshd.service enabled<br \/>\nsysstat.service enabled<br \/>\nsystemd-readahead-collect.service enabled<br \/>\nsystemd-readahead-drop.service enabled<br \/>\nsystemd-readahead-replay.service enabled<br \/>\ntuned.service enabled<br \/>\nvmtoolsd.service enabled<br \/>\navahi-daemon.socket enabled<br \/>\ncups.socket enabled<br \/>\ndm-event.socket enabled<br \/>\niscsid.socket enabled<br \/>\niscsiuio.socket enabled<br \/>\nlvm2-lvmetad.socket enabled<br \/>\nrpcbind.socket enabled<br \/>\ndefault.target enabled<br \/>\ngraphical.target enabled<br \/>\nnfs.target enabled<br \/>\nremote-fs.target enabled<\/p>\n<p>[root@rhel7 ~]# systemctl stop firewalld.service<br \/>\n[root@rhel7 ~]# systemctl disable firewalld.service<br \/>\n[root@rhel7 ~]# systemctl status firewalld.service<br \/>\nfirewalld.service \u2013 firewalld \u2013 dynamic firewall daemon<br \/>\nLoaded: loaded (\/usr\/lib\/systemd\/system\/firewalld.service; disabled)<br \/>\nActive: inactive (dead)<\/p>\n<p>DEC 29 22:25:43 rhel7 systemd[1]: Started firewalld \u2013 dynamic firewall daemon.<br \/>\nDEC 29 22:43:29 rhel7 systemd[1]: Stopping firewalld \u2013 dynamic firewall daemon\u2026<br \/>\nDEC 29 22:43:29 rhel7 systemd[1]: Stopped firewalld \u2013 dynamic firewall daemon.<br \/>\nDEC 29 22:44:14 rhel7 systemd[1]: Stopped firewalld \u2013 dynamic firewall daemon.<br \/>\nDEC 29 22:44:15 rhel7 systemd[1]: Stopped firewalld \u2013 dynamic firewall daemon.<br \/>\nDEC 29 22:44:19 rhel7 systemd[1]: Starting firewalld \u2013 dynamic firewall daemon\u2026<br \/>\nDEC 29 22:44:19 rhel7 systemd[1]: Started firewalld \u2013 dynamic firewall daemon.<br \/>\nDEC 29 22:44:21 rhel7 systemd[1]: Stopping firewalld \u2013 dynamic firewall daemon\u2026<br \/>\nDEC 29 22:44:21 rhel7 systemd[1]: Stopped firewalld \u2013 dynamic firewall daemon.<br \/>\nDEC 29 22:44:32 rhel7 systemd[1]: Stopped firewalld \u2013 dynamic firewall daemon.<\/p>\n<p>systemctl start firewalld.service<br \/>\nsystemctl stop firewalld.service<br \/>\nsystemctl restart firewalld.service<br \/>\nsystemctl status firewalld.service<br \/>\nsystemctl enable firewalld.service<br \/>\nsystemctl disable firewalld.service<br \/>\nsystemctl is-enabled firewalld.service;echo $?<br \/>\nsystemctl list-unit-files|grep enabled<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Centos 7 SYSTEMCTL &amp;&amp; Run level &amp;&amp; hostname <\/p>\n<p>Centos 7 SYSTEMCTL &amp;&amp; Run level &amp;&amp; hostname<\/p>\n<p>systemctl start httpd.service (service httpd start)<\/p>\n<p>systemctl stop httpd.service ( service httpd stop)<\/p>\n<p>systemctl restart httpd.service ( service httpd stop)<\/p>\n<p>systemctl status httpd.service ( service httpd status)<\/p>\n<p>systemctl enable httpd.service (chkconfig httpd on)<\/p>\n<p>systemctl disable httpd.service (chkconfig httpd [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73,4],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3722"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3722"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3722\/revisions"}],"predecessor-version":[{"id":5518,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3722\/revisions\/5518"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}