การจัดการบริการบน 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