May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Centos 7 SYSTEMCTL && Run level && hostname

Centos 7 SYSTEMCTL && Run level && hostname

Centos 7 SYSTEMCTL && Run level && hostname

systemctl start httpd.service (service httpd start)

systemctl stop httpd.service ( service httpd stop)

systemctl restart httpd.service ( service httpd stop)

systemctl status httpd.service ( service httpd status)

systemctl enable httpd.service (chkconfig httpd on)

systemctl disable httpd.service (chkconfig httpd off)

job chkconfig?service systemctl
Service boot from the start chkconfig –level 3 httpd on systemctl enable httpd
Service does not boot from the start chkconfig –level 3 httpd off systemctl disable httpd

Service Status service httpd status systemctl status HTTP d (service details)

systemctl is-active httpd

Start the status of all services chkconfig –list systemctl list-units –type=service
Start Service service httpd start systemctl start httpd
Out of service service httpd stop systemctl stop httpd
Restart the service service httpd restart systemctl restart httpd

[root@keeplive ~]# cat /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /etc/systemd/system/ctrl-alt-del.target
#
# systemd uses ‘targets’ instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To set a default target, run:
#
# ln -sf /lib/systemd/system/.target /etc/systemd/system/default.target

From the command-line switch to the window level level command unchanged: init 5 or startx

Level by the window switch to the command line level commands unchanged: init 3

The new version of the run level is defined in the /lib/systemd/system:

[root@keeplive ~]# ls -ltr /lib/systemd/system/runlevel*.target
lrwxrwxrwx. 1 root root 15 Nov 13 08:46 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Nov 13 08:46 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Nov 13 08:46 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Nov 13 08:46 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Nov 13 08:46 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Nov 13 08:46 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Nov 13 08:46 /lib/systemd/system/runlevel6.target -> reboot.target

You can set different run levels for different needs:

init 3

[root@keeplive ~]# ln -svf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
‘/etc/systemd/system/default.target’ -> ‘/lib/systemd/system/runlevel3.target’
[root@keeplive ~]# ln -svf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
‘/etc/systemd/system/default.target’ -> ‘/lib/systemd/system/multi-user.target’
[root@keeplive ~]# systemctl set-default multi-user.target
rm ‘/etc/systemd/system/default.target’
ln -s ‘/usr/lib/systemd/system/multi-user.target’ ‘/etc/systemd/system/default.target’
[root@keeplive ~]#

INIT5

[root@keeplive ~]# ln -svf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
‘/etc/systemd/system/default.target’ -> ‘/lib/systemd/system/runlevel5.target’
[root@keeplive ~]# ln -svf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
‘/etc/systemd/system/default.target’ -> ‘/lib/systemd/system/graphical.target’
[root@keeplive ~]# systemctl set-default graphical.target
rm ‘/etc/systemd/system/default.target’
ln -s ‘/usr/lib/systemd/system/graphical.target’ ‘/etc/systemd/system/default.target’

Modify the system run level:
1, 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.
You can use the following command to switch to “run level 3”:
multi-user.target systemctl isolate or systemctl isolate runlevel3.target

You can use the following command to switch to the “Run Level 5”:
systemctl isolate graphical.target or systemctl isolate runlevel5.target

2, how to change the default runlevel?
systemd 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
default startup run level 3:
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target

systemd does not use /etc/inittab file.

Modify CentOS 7 hostname

In CentOS, there are three definitions hostname: static (static), transient (transient), and flexible (pretty). “Static” host name is also called kernel hostname, is the system at boot time from /etc/hostname
automatic initialization of the host name. “Transient” host name is in the system is running temporarily assigned host name, for example, assigned by DHCP or mDNS server.
Static hostname and transient hostname comply with the same character as the Internet domain restriction rules. On the other hand, a “flexible” is allowed to use
the hostname of free-form (including special / whitespace) host name, to show to the end user (eg Linuxidc).

In CentOS 7, a man named hostnamectl command-line tool that allows you to view or modify the host name associated with the configuration.

[root@keeplive ~]# hostnamectl
Static hostname: keeplive
Icon name: computer
Chassis: n/a
Machine ID: 2b48dba259f2428ca8038f7aeb1d7f15
Boot ID: 57772bec11854cd08ee72db54a1441d3
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.9.3.el7.x86_64
Architecture: x86_64
[root@keeplive ~]# hostnamectl status
Static hostname: keeplive
Icon name: computer
Chassis: n/a
Machine ID: 2b48dba259f2428ca8038f7aeb1d7f15
Boot ID: 57772bec11854cd08ee72db54a1441d3
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.9.3.el7.x86_64
Architecture: x86_64
[root@keeplive ~]# hostnamectl –static
keeplive
[root@keeplive ~]# hostnamectl –transient
keeplive
[root@keeplive ~]# hostnamectl –pretty

 
[root@rhel7 ~]# systemctl list-unit-files|grep enabled
cups.path enabled
abrt-ccpp.service enabled
abrt-oops.service enabled
abrt-vmcore.service enabled
abrt-xorg.service enabled
abrtd.service enabled
accounts-daemon.service enabled
atd.service enabled
auditd.service enabled
avahi-daemon.service enabled
bluetooth.service enabled
chronyd.service enabled
crond.service enabled
cups.service enabled
dbus-org.bluez.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled
dbus-org.freedesktop.Avahi.service enabled
dbus-org.freedesktop.ModemManager1.service enabled
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
display-manager.service enabled
dmraid-activation.service enabled
firewalld.service enabled
firstboot-graphical.service enabled
gdm.service enabled
getty@.service enabled
hypervkvpd.service enabled
hypervvssd.service enabled
irqbalance.service enabled
iscsi.service enabled
ksm.service enabled
ksmtuned.service enabled
libstoragemgmt.service enabled
libvirtd.service enabled
lvm2-monitor.service enabled
mdmonitor.service enabled
microcode.service enabled
ModemManager.service enabled
multipathd.service enabled
NetworkManager-dispatcher.service enabled
NetworkManager.service enabled
nfs-lock.service enabled
packagekit-offline-update.service enabled
postfix.service enabled
rhsmcertd.service enabled
rngd.service enabled
rpcbind.service enabled
rsyslog.service enabled
rtkit-daemon.service enabled
smartd.service enabled
spice-vdagentd.service enabled
sshd.service enabled
sysstat.service enabled
systemd-readahead-collect.service enabled
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
tuned.service enabled
vmtoolsd.service enabled
avahi-daemon.socket enabled
cups.socket enabled
dm-event.socket enabled
iscsid.socket enabled
iscsiuio.socket enabled
lvm2-lvmetad.socket enabled
rpcbind.socket enabled
default.target enabled
graphical.target enabled
nfs.target enabled
remote-fs.target enabled

[root@rhel7 ~]# systemctl stop firewalld.service
[root@rhel7 ~]# systemctl disable firewalld.service
[root@rhel7 ~]# systemctl status firewalld.service
firewalld.service – firewalld – dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
Active: inactive (dead)

DEC 29 22:25:43 rhel7 systemd[1]: Started firewalld – dynamic firewall daemon.
DEC 29 22:43:29 rhel7 systemd[1]: Stopping firewalld – dynamic firewall daemon…
DEC 29 22:43:29 rhel7 systemd[1]: Stopped firewalld – dynamic firewall daemon.
DEC 29 22:44:14 rhel7 systemd[1]: Stopped firewalld – dynamic firewall daemon.
DEC 29 22:44:15 rhel7 systemd[1]: Stopped firewalld – dynamic firewall daemon.
DEC 29 22:44:19 rhel7 systemd[1]: Starting firewalld – dynamic firewall daemon…
DEC 29 22:44:19 rhel7 systemd[1]: Started firewalld – dynamic firewall daemon.
DEC 29 22:44:21 rhel7 systemd[1]: Stopping firewalld – dynamic firewall daemon…
DEC 29 22:44:21 rhel7 systemd[1]: Stopped firewalld – dynamic firewall daemon.
DEC 29 22:44:32 rhel7 systemd[1]: Stopped firewalld – dynamic firewall daemon.

systemctl start firewalld.service
systemctl stop firewalld.service
systemctl restart firewalld.service
systemctl status firewalld.service
systemctl enable firewalld.service
systemctl disable firewalld.service
systemctl is-enabled firewalld.service;echo $?
systemctl list-unit-files|grep enabled

 

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>