av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

最詳細(xì)的CentOS6與7對比(二):服務(wù)管理對比

本主題將從3個角度進(jìn)行對比

成都創(chuàng)新互聯(lián)為客戶提供專業(yè)的成都網(wǎng)站設(shè)計、成都網(wǎng)站制作、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項目涵蓋了網(wǎng)頁設(shè)計、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、手機網(wǎng)站開發(fā)等網(wǎng)站方面業(yè)務(wù)。

  1. 常見設(shè)置(centos 6 vs CentOS 7)
  2. 服務(wù)管理(Sysvinit vs Upstart vs Systemd)
  3. 性能測試(cpu/mem/io/oltp)

本文為第二部分:服務(wù)管理的對比

1. sysvinit、upstart、systemd簡介

/ CentOS 5 CentOS 6 CentOS 7 備注
sysvinit 第一代,傳統(tǒng),兼容最多(/etc/init.d/、/etc/rc.X)
upstart 第二代,形似systemd雛形(/etc/init)
systemd 第三代,配合cgroup,systemd完全接管整個系統(tǒng)(/usr/lib/systemd)

2. sysvinit、upstart、systemd常用命令

動作 sysvinit upstart systemd
查看 service mytest status initctl status mytest systemctl status mytest.service
啟動 service mytest start initctl start mytest systemctl start mytest.service
關(guān)閉 service mytest stop initctl stop mytest systemctl stop mytest.service
強殺進(jìn)程 kill -9 PID kill -9 PID systemctl kill mytest.service --signal=9
重啟 service mytest restart initctl restart mytest systemctl restart mytest.service
重載 service mytest reload initctl reload mytest systemctl reload mytest.service
開機啟動 chkconfig mytest on /etc/init/mytest.conf里配置start on runlevel [3] systemctl enable mytest.service

3. runlevel運行級別

運行級別 CentOS 6 CentOS 7
0 halt runlevel0.target -> poweroff.target
1 Single user mode runlevel1.target -> rescue.target
2 Multiuser, without NFS runlevel2.target -> multi-user.target
3 Full multiuser mode runlevel3.target -> multi-user.target
4 unused runlevel4.target -> multi-user.target
5 X11 runlevel5.target -> graphical.target
6 reboot runlevel6.target -> reboot.target
查看 cat /etc/inittab systemctl get-default
開機生效 編輯/etc/inittab systemctl set-default multi-user.target
立即切換 init 5 systemctl isolate graphical.target

4. 日志查詢

CentOS 6: 手工在/var/log/messages、/var/log/dmesg、/var/log/secure中g(shù)rep,麻煩且效率低

CentOS 7: 統(tǒng)一使用journalctl,可以使用多個因素匹配,比如時間段、服務(wù)名、日志級別等等。另外,systemd日志默認(rèn)經(jīng)過壓縮,是二進(jìn)制文件,無法直接查看

journalctl常用命令 作用 CentOS 6比
journalctl 所有日志,包含系統(tǒng)、內(nèi)核等等 手動在對應(yīng)日志文件中g(shù)rep
journalctl --dmesg 查看當(dāng)前開機后的內(nèi)核日志 dmesg
journalctl --boot 查看當(dāng)前開機后的日志 先查當(dāng)前開機啟動時間,然后cat /var/log/...
journalctl --boot=-1 查看上一次啟動的日志 查詢上次開機到當(dāng)前開機之間時間,然后cat /var/log/...
journalctl --since="2018-08-01 12:00:00" 查看從指定時間開始到當(dāng)前的日志 手動在日志里grep
journalctl --since=yesterday --until=today 查看昨天0-24點的日志 手動在日志里grep
journalctl -n 20 查看最后10行 tail -n 20
journalctl -f 實時滾動顯示最新日志 tail -f
journalctl -e 直接翻到最后 tail
journalctl -u mytest.service 查看指定服務(wù)日志 先查詢?nèi)罩颈4媛窂?,然后再cat查看
journalctl -p 0 查看指定日志級別的日志,日志級別從0到7 通過syslog將不同級別的日志放到不同文件中
journalctl -u mytest.service -o json-pretty或-o verbose 查看每條日志詳細(xì)信息(包含元信息)
journalctl --disk-usage 查看日志所在的磁盤空間 du -shx /var/log/messages等

5. 實現(xiàn)守護(hù)進(jìn)程

CentOS 6

  • sysvinit需要自行實現(xiàn)
    • nohup &
    • screen
    • supervisor
  • upstart和systemd類似,將程序運行在前臺即可

CentOS 7

  • 由systemd啟動,將程序運行在前臺即可

6. sysvinit、upstart、systemd例子

sysvinit

cat > /etc/init.d/mytest <

upstart

cat > /etc/init/mytest.conf <

systemd

cat > /usr/lib/systemd/system/mytest.service <

7. PID管理

  • sysvinit: 需要生成PID文件,用于后期關(guān)閉、重啟等使用
  • upstart: 無需PID文件,upstart會記錄主進(jìn)程ID,子進(jìn)程ID沒有記錄
  • systemd: 無需PID文件,所有進(jìn)程ID由cgroup統(tǒng)一接管

8. 內(nèi)置的資源限制

CentOS 6: 除了ulimit,沒有其他限制進(jìn)程資源的簡便方法
CentOS 7: 除了ulimit,還支持部分cgroup限制,可對進(jìn)程做內(nèi)存限制和cpu資源限制等

[Service]
ExecStart=...
MemoryLimit=500M
CPUShares=100

另外,CentOS 7可以通過systemd-cgtop命令查看cgroup里的性能數(shù)據(jù)

9. 服務(wù)異常自動重啟

upstart

start on runlevel [3]

description "mytest"

exec /root/mytest.sh
post-stop exec sleep 5
respawn
respawn limit unlimited

systemd

[Unit]
Description=mytest
 [Service]
Type=simple
ExecStart=/root/mytest.sh
Restart=always
RestartSec=5
StartLimitInterval=0
 [Install]
WantedBy=multi-user.target

上面2種方式均表示,無限次自動重啟,每次重啟前等待5秒

10. 寫日志方式

CentOS 6: 自行輸出到文件中,或通過syslog記錄(如logger命令)

CentOS 7: 只要程序由systemd啟動,只需將輸出日志到標(biāo)準(zhǔn)輸出或標(biāo)準(zhǔn)錯誤

  • 建議centos7只將應(yīng)用程序的一些元信息輸出到標(biāo)準(zhǔn)輸出或標(biāo)準(zhǔn)錯誤,比如啟動成功、啟動失敗等等
  • 不建議將業(yè)務(wù)日志輸出到j(luò)ournal。因為journal中所有日志都存在一個文件中,會導(dǎo)致2個問題:
    • 如果沒有做日志持久化,則默認(rèn)存在內(nèi)存中,會導(dǎo)致最多一半的內(nèi)存被占用
    • 存儲量很大,會導(dǎo)致查詢其他日志很耗時
  • 解決辦法:輸出到syslog,[Service]支持StandardOutput=syslog

11. 指定每條日志級別

CentOS 6: 通過syslog將不同級別的日志輸出到不同文件

CentOS 7: 只需在輸出的每一行開頭加<日志級別>,比如

echo '<0>hello, emerg'
echo '<1>hello, alert'
echo '<2>hello, crit'
echo '<3>hello, err'
echo '<4>hello, warning'
echo '<5>hello, notice'
echo '<6>hello, info'
echo '<7>hello, debug'

12. systemd日志永久保存

systemd日志默認(rèn)保存在內(nèi)存中,因此當(dāng)服務(wù)器重啟后,就無法通過journalctl來查看之前的日志,解決方法:

mkdir -p /var/log/journal
systemctl restart systemd-journald

新聞名稱:最詳細(xì)的CentOS6與7對比(二):服務(wù)管理對比
網(wǎng)頁網(wǎng)址:http://uogjgqi.cn/article/djpssoi.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流