การจัดการบริการบน CentOS Linux 7.0 ด้วย Systemd
โพสต์: อังคาร 07 ก.ค. 2015 07:56
การจัดการบริการบน CentOS Linux 7.0 ด้วย Systemd
โพสต์โดย slwt2002 » พุธ 29 ต.ค. 2014 12:51 pm
การจัดการบริการบน CentOS Linux 7.0 ด้วย Systemd
การจัดการบริการหรือ Services บนระบบปฏิบัติการ CentOS Linux รีลีสเก่าๆ (CentOS 6.x ลงมา) ในการจัดการบริการต่างๆ จะใช้รูปแบบดังนี้
การเปิดและปิดบริการ
การเปิดใช้งานบนบู๊ตระบบ
ใน 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 )
รูปภาพ
การเปิดบริการ (Activates a service)
ตัวอย่าง เช่น
การปิดบริการ (Deactivates a service)
ตัวอย่าง เช่น
การปรับใช้งานบริการใหม่ (Reload a service)
* ใช้ในกรณีหลังการปรับแต่งค่าบริการหรือ config file โดยไม่ให้รบกวนบริการที่กำลังทำงานอยู่
ตัวอย่าง เช่น
การเรียกใช้งานบริการใหม่ (Restarts a service)
ตัวอย่าง เช่น
การเริ่มบริการที่มีอยู่แล้วให้ทำงานใหม่ (Restarts if the service is already running)
ตัวอย่าง เช่น
การตรวจสอบดูสถานะของบริการ (Shows status of a service)
# systemctl status service_name[/code]
ตัวอย่าง เช่น
การเปิดใช้งานบริการตอนบู๊ตระบบ
การเปิดบริการตอนบู๊ตเครื่อง (Enables a service to be started on bootup)
ตัวอย่าง เช่น
การปิดบริการตอนบู๊ตเครื่อง (Disables a service to not start during bootup)
ตัวอย่าง เช่น
การเปิดบริการแบบ Manual (masked)
ตัวอย่าง เช่น
การตรวจสอบว่าบริการที่มีอยู่ถูกเปิดใช้งานอยู่หรือไม่
หรือ
โดยที่
0 มีการเปิดใช้งาน
1 มีการปิดการใช้งาน
ตัวอย่าง เช่น
โค้ด: เลือกทั้งหมด
systemctl is-enabled httpd
masked
โค้ด: เลือกทั้งหมด
systemctl is-enabled httpd ; echo $?
masked
1
เปรียบเทียบคำสั่ง CentOS 6.x down vs CentOS 7.x up
service service_name start = systemctl start service_name
service service_name stop = systemctl stop service_name
service service_name restart = systemctl restart service_name
service service_name reload = systemctl reload service_name
service service_name status = systemctl status service_name
chkconfig service_name on = systemctl enable service_name
chkconfig service_name off = systemctl disable service_name
chkconfig --list service_name = systemctl is-enabled service_name
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
โพสต์โดย 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 service_name start = systemctl start service_name
service service_name stop = systemctl stop service_name
service service_name restart = systemctl restart service_name
service service_name reload = systemctl reload service_name
service service_name status = systemctl status service_name
chkconfig service_name on = systemctl enable service_name
chkconfig service_name off = systemctl disable service_name
chkconfig --list service_name = systemctl is-enabled service_name
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