天天看點

liunx開機服務

1、重要的開機服務

1、sshd

2、rsyslog收集清理管理相關的日志

3、network

4、crond   定時任務 相當于鬧鐘

5、sysstat   軟體內建包   

iostat 

mpstat

Sar

 [root@oldboy rc3.d]# chkconfig --list|grep 3:on|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}' 

chkconfig abrt-ccpp off

chkconfig abrtd off

chkconfig acpid off

chkconfig atd off

chkconfig auditd off

chkconfig blk-availability off

chkconfig cpuspeed off

chkconfig haldaemon off

chkconfig ip6tables off

chkconfig irqbalance off

chkconfig kdump off

chkconfig lvm2-monitor off

chkconfig mdmonitor off

chkconfig messagebus off

chkconfig netfs off

chkconfig postfix off

chkconfig udev-post off

[root@oldboy rc3.d]# chkconfig --list|grep 3:on|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash

[root@oldboy rc3.d]# chkconfig --list|grep 3:on

crond           0:off   1:off   2:on    3:on    4:on    5:on    6:off

network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off

sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

sysstat         0:off   1:on    2:on    3:on    4:on    5:on    6:off 

開機啟動管理  

setup第四項(不重要)可以設定

2、開機過程圖解

3、chkconfig 指令主要用來更新(啟動或停止)和查詢系統服務的運作級資訊。

chkconfig[--add][--del][--list][系統服務] 或 chkconfig [--level <等級代号>][系統服務][on/off/reset]

--add增加服務

--del删除所指定的系統服務

--level《等級号》指定讀系統服務要在哪一個執行等級中開啟或關閉

--list 顯示所有服務  

 --list sshd 産看指定服務是否開機自啟動

主要管理/etc/init.d/sshdstart 下的檔案

原理實作:

!!!腳本開頭必須包含chkconfig管理的代碼

         chkconfig :12345 13 98

         description: oldboy test

1、把腳本放到/etc/init.d下面,并且可執行,希望被chkcofig管理,就用添加進去chkconfig --add sshd

2、添加進去的預設在哪個級别上啟動看開發腳本中chkconfig的配置,服務啟動順序和關閉順序也是看腳本中的chkconfig的配置

3、chkconfig  --level 3 sshd on實質

rm -f /etc/rc.d/rc3.d/Knnsshd       ln -s/etc/init.d/sshd   /etc/rc.d/rc3.d/Snnsshd

4、關閉chkconfig  --level 3 sshd off 

rm -f /etc/rc.d/rc3.d/Snnsshd     ln -s/etc/init.d/sshd   /etc/rc.d/rc3.d/Knnsshd 

[root@zhang ~]# chkconfig --list crond

crond          0:off   1:off   2:off   3:off   4:off   5:off  6:off

[root@zhang ~]# chkconfig --level 3crond on 

crond          0:off   1:off   2:off   3:on    4:off   5:off  6:off

[root@zhang ~]# chkconfig --level 245crond off 

[root@zhang init.d]# vi oldboy

# chkconfig: 2345 91 61

echo "Welcome to oldboytraining:"

[root@zhang init.d]# cat oldboy

[root@zhang init.d]# chmod +x oldboy

[root@zhang init.d]# /etc/init.d/oldboystrt

Welcome to oldboy training:

[root@zhang init.d]# /etc/init.d/oldboy start

[root@zhang init.d]# chkconfig --addoldboy

[root@zhang init.d]# chkconfig --listoldboy

oldboy         0:off   1:off   2:on    3:on    4:on   5:on    6:off

4、打包壓縮包 tar

tarzcvf 【路徑】/筐 【相對路徑】一堆蘋果

tartf  接壓縮包路徑檢視壓縮包内容

--exclude=data/2排除   過濾data下的檔案2其餘都打包

-X(從檔案中排除相當于--exclude-from)

[root@Oldboy ~]# tar zcvf/tmp/zhang.tar.gz data --exclude=4.txt

data/

data/7.txt

data/8.txt

-z壓縮(gzip壓縮)

-v顯示詳細輸出過程

-c建立檔案  

-f檔案

-x解壓

-p保持屬性

-C指定解壓的目錄  (大寫   指定解壓的路徑)

-j壓縮(bzip壓縮)

-t檢視解壓封包件清單

1、盡量切換到打包目錄的上一級目錄,然後用相對路徑打包,除非是你想保留完整路徑

X打包排除

[root@zhang /]# tar zcvf /tmp/root.tar.gz ./root 

[root@zhang /]# ls /tmp

456.txt  oldboy.tar.gz  ssh-AKUVKh1729 zhang.txt

oldboy   root.tar.gz    test.txt

[root@zhang /]# tar tf /tmp/root.tar.gz

./root/

./root/install.log.syslog

./root/.tcshrc

./root/test.txt

./root/anaconda-ks.cf

[root@zhang ~]# tar zcvf data.tar.gz./data --exclude=data/2

./data/

./data/4

./data/5

./data/6

./data/3

./data/10

./data/1

./data/9

./data/7

./data/8

 [root@oldboy opt]# mkdir test

[root@oldboy opt]# cd test/

[root@oldboy test]# touch stu{01..10}

[root@oldboy test]# ls

stu01  stu02  stu03  stu04  stu05  stu06  stu07  stu08  stu09  stu10

[root@oldboy opt]# mkdir test

[root@oldboy test]# ls -l

total 0

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu01

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu02

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu03

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu04

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu05

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu06

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu07

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu08

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu09

-rw-r--r-- 1 root root 0 Mar 15 05:49 stu10

[root@oldboy test]# cd ../

[root@oldboy opt]# tar zcvf test.tar.gz ./test

./test/

./test/stu03

./test/stu01

./test/stu02

./test/stu09

./test/stu06

./test/stu08

./test/stu10

./test/stu07

./test/stu05

./test/stu04

[root@oldboy opt]# ls

etc  rh  test  test.tar.gz

[root@oldboy opt]# tar jcvf test.tar.bz ./test  

[root@oldboy opt]# ll

total 20

drwxr-xr-x  82 root root 4096 Mar 15 04:22 etc

drwxr-xr-x.  2 root root 4096 Mar 26  2015 rh

drwxr-xr-x   2 root root 4096 Mar 15 05:49 test

-rw-r--r--   1 root root  211 Mar 15 05:51 test.tar.bz

-rw-r--r--   1 root root  231 Mar 15 05:50 test.tar.gz

[root@oldboy opt]# tar zxf test.tar.gz  

[root@oldboy opt]# tar zxf test.tar.bz 

gzip: stdin: not in gzip format

tar: Child returned status 1

tar: Error is not recoverable: exiting now

[root@oldboy opt]# tar jxf test.tar.bz  

[root@oldboy opt]# tar xf test.tar.bz  

[root@oldboy opt]# cat paichu.log

stu05  

stu06  

stu07

tar zcvfX data/data.tar.gz root/paichu.txt ./root

[root@oldboy opt]# tar zcvfX paichuX.tar.gz paichu.log ./test 

[root@oldboy opt]# tar tf paichuX.tar.gz 

tar zcvf /tmp/etc4.tar.gz --exclude=services --exclude=111 etc 

17:43:50

find /root/ -type d -name "oldboy"|xargs tar zcvf oldboy.tar.gz

 1064  find root -type f ! -name "*.txt"|xargs tarzcvf root/hello.gar.gz

find /root/ -type d -name "oldboy" -exec tar zcvf oldboy.tar.gz {} \;(錯誤的方法)

tar zcvf oldboy.tar.gz `find /root/ -type d -name "oldboy"` 

解壓縮包

 tarzxvf框         xf最簡解包看不到過程

-x 從歸檔檔案中解壓檔案

[root@zhang ~]# tar zxvf/tmp/root.tar.gz 

./root/anaconda-ks.cfg

./root/.bashrc

./root/123.txt

[root@zhang data]# touch `seq 10`

[root@zhang data]# ls

1  10  2  3  4 5  6  7  8  9

[root@zhang ~]# ls kk

data.tar.gz

[root@zhang ~]# tar tf kk/data.tar.gz

./data/2

5、cut

可以講一段文本的某一段 切 出來,處理的資訊是以行為機關

-d:指定分隔符與-f一起使用

-f依據-d分隔符将一段資訊切割成為數段,用-f取出第幾段的意思

-c以字元的機關取出固定字元段(幾到幾)

[root@zhang ~]# ifconfig eth0|sed -n '2p'|cut -d ':' -f 2

10.0.0.128  Bcast

[root@zhang ~]# ifconfig eth0|sed -n '2p'|cut -d ':' -f 2|cut -d ' ' -f 1

6、wc計算行數、字元數等

-l行數

-c位元組

-m字元

egrep等于grep-E

egrep 查找字元串