การจัดการบริการบน CentOS Linux 7.0 ด้วย Systemd

โพสต์โดย slwt2002 » พุธ 29 ต.ค. 2014 12:51 pm

การจัดการบริการบน CentOS Linux 7.0 ด้วย Systemd

การจัดการบริการหรือ Services บนระบบปฏิบัติการ CentOS Linux รีลีสเก่าๆ (CentOS 6.x ลงมา) ในการจัดการบริการต่างๆ จะใช้รูปแบบดังนี้

การเปิดและปิดบริการ


service service_name start/stop/restart

การเปิดใช้งานบนบู๊ตระบบ

chkconfig service_name on/off
chkconfig -list

ใน CentOS Linux 7.0 และ RHEL 7.0 ขึ้นมาจะใช้การควบคุมบริการด้วย Systemd แทน ดังนั้นการควบคุมบริการทั้งหมดจะถูกเปลี่ยนแปลงไป โดยการจัดการบริการทั้งหมดจะใช้คำสั่ง systemctl แทนคำสั่ง service และ chkconfig ที่ใช้ในรีลีสก่อนหน้า โดยในปัจจุบันมีระบบปฏิบัติการหลายตัวได้หันมาใช้งาน Systemd

ระบบปฏิบัติการที่เปลี่ยนมาใช้งาน Systemd

  • Arch Linux / October 2012
  • CentOS Linux เวอร์ชั่น 7.0 ขึ้นไป / July 2014
  • CoreOS / July 2013
  • Debian GNU/Linux / April 2012
  • Fedora เวอร์ชั่น 15 ขึ้นไป / May 2011
  • Frugalware Linux เวอร์ชั่น 1.5 ขึ้นไป / August 2011
  • Gentoo Linux / 2011
  • Mageia เวอร์ชั่น 2.0 ขึ้นไป / May 2012
  • openSUSE เวอร์ชั่น 11.4 ขึ้นไป / March 2011
  • Red Hat Enterprise Linux เวอร์ชั่น 7.0 ขึ้นไป / June 2014
  • Sabayon Linux เวอร์ชั่น 13.08 ขึ้นไป / August 2013
  • Ubuntu เวอร์ชั่น 13.04 ขึ้นไป / April 2013

รูปภาพ

องค์ประกอบของ Systemd

รูปภาพ

คำสั่งการใช้งานของ Systemd โดยมีรายละเอียดคำสั่งคร่าวๆ ดังนี้

การตรวจสอบรายชื่อบริการ (List all running services )


systemctl

รูปภาพ

การเปิดบริการ (Activates a service)

systemctl start service_name

ตัวอย่าง เช่น

systemctl start httpd

การปิดบริการ (Deactivates a service)

systemctl stop service_name

ตัวอย่าง เช่น

systemctl stop httpd
systemctl stop iptables
systemctl stop ip6tables

การปรับใช้งานบริการใหม่ (Reload a service)

  • ใช้ในกรณีหลังการปรับแต่งค่าบริการหรือ config file โดยไม่ให้รบกวนบริการที่กำลังทำงานอยู่

systemctl reload service_name

ตัวอย่าง เช่น

systemctl reload httpd

การเรียกใช้งานบริการใหม่ (Restarts a service)

systemctl restart service_name

ตัวอย่าง เช่น

systemctl restart httpd

การเริ่มบริการที่มีอยู่แล้วให้ทำงานใหม่ (Restarts if the service is already running)

systemctl condrestart service_name

ตัวอย่าง เช่น

systemctl condrestart httpd

การตรวจสอบดูสถานะของบริการ (Shows status of a service)

systemctl status service_name[/code]

ตัวอย่าง เช่น

systemctl status httpd
systemctl status iptables

การเปิดใช้งานบริการตอนบู๊ตระบบ

การเปิดบริการตอนบู๊ตเครื่อง (Enables a service to be started on bootup)

systemctl enable service_name

ตัวอย่าง เช่น

systemctl enable httpd

การปิดบริการตอนบู๊ตเครื่อง (Disables a service to not start during bootup)


systemctl disable service_name

ตัวอย่าง เช่น


systemctl disable httpd

การเปิดบริการแบบ Manual (masked)

systemctl mask service_name

ตัวอย่าง เช่น

systemctl mask dovecot

การตรวจสอบว่าบริการที่มีอยู่ถูกเปิดใช้งานอยู่หรือไม่

systemctl is-enabled service_name

หรือ

systemctl is-enabled service_name; echo $?

โดยที่

0 มีการเปิดใช้งาน

1 มีการปิดการใช้งาน

ตัวอย่าง เช่น

โค้ด: เลือกทั้งหมด

systemctl is-enabled httpd

masked

โค้ด: เลือกทั้งหมด

systemctl is-enabled httpd ; echo $?

masked

1

เปรียบเทียบคำสั่ง CentOS 6.x down vs CentOS 7.x up

service servicename start = systemctl start servicename

service servicename stop = systemctl stop servicename

service servicename restart = systemctl restart servicename

service servicename reload = systemctl reload servicename

service servicename status = systemctl status servicename

chkconfig servicename on = systemctl enable servicename

chkconfig servicename off = systemctl disable servicename

chkconfig --list servicename = systemctl is-enabled servicename

chkconfig --list = systemctl list-unit-files --type=service

ที่มา:

  • http://www.freedesktop.org/wiki/Softwar ... tibilities
  • https://fedoraproject.org/wiki/Systemd
  • http://www.freedesktop.org/software/sys ... emctl.html
  • http://fedoraproject.org/wiki/SysVinit_ ... Cheatsheet
  • http://www.sysadmin.in.th/node/309#sthash.7vXS4tTG.dpuf