2019年11月24日 星期日

Linux command top

top

top 指令說明

b  Batch mode
d  指定更新時間(單位:秒)
o  指定要輸出的欄位名稱
p  指定要觀察的pid
u  指定要觀察的使用者名稱

top -b -d 2 -p 6164  //使用batch mode,觀察pid 6164的行程並每2秒更新一次
top -d 2 -u abc   //觀察使用者abc所執行的行程並每2秒更新一次
top -b -o +%MEM | head -n 17     //使用batch mode,以記憶體做為排序依據,並只列出前17行

top上半部欄位說明

第1行
08:15:01:目前時間
up 44 min:主機開機時間
1 user:目前登入系統使用者數
load average: 1.00, 1.23, 0.86:系統每1分鐘、5分鐘、15分鐘的負載情況。
      load average資料是每隔5秒鐘檢查一次活躍的進程數,然後按特定演算法計算出的數值。
      如果這個數除以邏輯CPU的數量,結果高於5的時候就表明系統在超負荷運轉了。

第2行
Tasks:  63 total,   1 running,  62 sleeping,   0 stopped,   0 zombie:
  目前系統共63個行程,1個正在執行(running),62個休眠狀態(sleeping),
  0個已停止(stopped),0個僵屍狀態(zombie)

第3行
%Cpu(s):  1.1 us,  0.3 sy,  0.0 ni,100.0 id,  0.4 wa,  0.02 hi,  0.1 si,  0.0 st:
1.1% us — user cpu time(or)%CPU time spent in user space
0.3% sy — system cpu time(or)% CPU time spent in kernel space
0.0% ni — user nice cpu time(or) % CPU time spent on low priority processes
100% id -idle cpu time(or)%CPU time spent idle
0.4% wa — io wait cpu time(or)% CPU time spent in wait (on disk)
0.1% hi — hardware irq(or)%CPU time spent servicing/handling hardware interrupts
0.0% si — hardware irq(or)%CPU time spent servicing/handling hardware interrupts
0.0% st - steal time % CPU time in involuntary wait by virtual 
       cpu while hypervisor is servicing another processor (or) % 
      CPU time stolen from a virtual machine

第4行
KiB Mem :  1741400 total,  1600560 free,    73184 used,    67656 buff/cach
記憶體使用狀態:
1741400 total:實體記憶體容量
1600560 free:剩餘的記憶體容量
73184 used:已使用的記憶體容量
67656 buff/cache:linux用作block dev寫入buffer/block dev讀取cache記憶體容量
第5行
KiB Swap:        0 total,        0 free,        0 used.  1557120 avail Mem 
swap使用狀態:
0 total:swap總容量
0 free:剩餘的swap容量
0 used:已使用swap容量
1557120 avail Mem (available)新process在不使用swap請況下啟動
              可配置多少記憶體,應是mem free + buff/cache

top下半部欄位說明

PID — 行程id(Process ID)
USER — 該行程使用者
PR — 行程優先順序
NI — nice值(值越小優先權優高)
VIRT — 該行程使用的虛擬記憶體總量,單位kb(VIRT=SWAP+RES)
RES — 該行程使用的、未被換出的實體記憶體大小,單位kb(RES=CODE+DATA)
SHR — 共用記憶體大小(單位kb)
S — 行程狀態。D=不可中斷的睡眠狀態 R=運行 S=睡眠 T=跟蹤/停止 Z=僵屍進程
%CPU — 上次更新到現在的CPU時間佔用百分比
%MEM — 行程使用的實體記憶體百分比
TIME+ — 行程使用的CPU時間總計,單位1/100秒
COMMAND — 行程名稱

e/E  時間顯示單位切換,可分s,ms,gs,ts,ps
f/F  Fields Management可自行選擇要顯示的欄位
h  叫出help說明
k  刪除指定行程
l  隱藏/顯示load average(第1行)資訊切換
L  尋找字串
M  隱藏/顯示memory info (第4行)資訊切換
P  依據cpu用量進行排序
q  離開top
R  修改nice值
S  更改延遲時間(預設3秒)
t  隱藏/顯示tasks(第2.3行)資訊切換
T  依據Time+時間/累計時間進行排序

top按鈕說明

Summary Area Commands

按鍵  說明
c show scroll coordinates toggle
l load average/uptime toggle
t task/cpu statues toggle
m  memroy/swap toggle
1  single/seprate cpu states toggle
   顯示單一/多cpu使用情形切換
2 numa node /cpu summary toggle
3 expand numa node

Task Area Commands

按鍵  說明
j
J
B  將欄位值做粗體/一般字體切換
x
y
z  顯示顏色切換
Z  更改排序方式/顏色切換時之顏色

Linux 系統資源監控 top mpstat sar uptime

top 監控整體

top裡按1,看每個cpu使用狀況
top裡按2,看每個node使用狀況


//如果是centos,以下須先安裝 yum -y install sysstat

iostat 監控 cpu 及 block 設備(及分割槽) io

# iostat -xz 1 
Linux 2.6.32-696.el6.x86_64 (DX_JQ_2) 12/07/2018 _x86_64_   (32 CPU)

avg-cpu: %user %nice %system %iowait %steal %idle
           0.05 0.00 0.07 0.01 0.00 99.87

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 0.00 3.29 0.02 1.13 1.28 35.30 31.88 0.02 20.90 7.84 21.13 5.19 0.60
dm-0 0.00 0.00 0.02 4.41 1.27 35.29 8.25 0.07 14.68 8.78 14.70 1.34 0.60

avg-cpu: %user %nice %system %iowait %steal %idle
           0.06 0.00 0.06 0.00 0.00 99.87
iostat [參數] [間隔秒][次數] 
iostat -x 1 10 //監控詳細信息,間隔1秒,共10次
iostat -C
iostat -dk

    -C 显示 CPU 使用情况
    -d 显示磁盘使用情况
    -k 以 KB 为单位显示
    -m 以 M 为单位显示
    -N 显示磁盘阵列(LVM) 信息
    -n 显示 NFS 使用情况
    -p[磁盘] 显示磁盘和分区的情况
    -t 显示终端和 CPU 的信息
    -x 显示详细信息
    -V 显示版本信息

監控cpu的屬性
%user  CPU 处在用户模式下的时间百分比
%nice  CPU 处在带 NICE 值的用户模式下的时间百分比
%system  CPU 处在系统模式下的时间百分比
%iowait  CPU 等待输入输出完成时间的百分比
%steal  管理程序维护另一个虚拟处理器时,虚拟 CPU 的无意识等待时间百分比
%idle  CPU 空闲时间百分比

監控disk的屬性
Device  监测设备名称
rrqm/s  每秒需要读取需求的数量
wrqm/s  每秒需要写入需求的数量
r/s  每秒实际读取需求的数量
w/s  每秒实际写入需求的数量
rsec/s  每秒读取区段的数量
wsec/s  每秒写入区段的数量
rkB/s  每秒实际读取的大小,单位为 KB
wkB/s  每秒实际写入的大小,单位为 KB
rMB/s  每秒实际读取的大小,单位为 MB
wMB/s  每秒实际写入的大小,单位为 MB
avgrq-sz  需求的平均大小区段
avgqu-sz  需求的平均队列长度
await  等待 I/O 平均的时间(milliseconds)
svctm  I/O 需求完成的平均时间
%util  被 I/O 需求消耗的 CPU 百分比


tps屬性
tps  该设备每秒的传输次数
kB_read/s  每秒从设备读取的数据量
kB_wrtn/s  每秒向设备写入的数据量
kB_read  读取的总数据量
kB_wrtn  写入的总数据量

mpstat 監控cpu

mpstat -A //監控所有狀態
mpstat -P 0/1/ALL   // 指定cpu編號
mpstat -P ALL 2 3  //每兩秒產生一次所有cpu資料,共3次


範例 mpstat -P All 2

11時38分44秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
11時38分46秒  all   55.25    0.00    1.00    0.75    0.00    0.25    0.00    0.00    0.00   42.75
11時38分46秒    0   10.10    0.00    1.52    1.52    0.00    0.00    0.00    0.00    0.00   86.87
11時38分46秒    1  100.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00

%user      在internal时间段里,用户态的CPU时间(%),不包含nice值为负进程  (usr/total)*100
%nice      在internal时间段里,nice值为负进程的CPU时间(%)   (nice/total)*100
%sys       在internal时间段里,内核时间(%)       (system/total)*100
%iowait    在internal时间段里,硬盘IO等待时间(%) (iowait/total)*100
%irq       在internal时间段里,硬中断时间(%)     (irq/total)*100
%soft      在internal时间段里,软中断时间(%)     (softirq/total)*100
%idle      在internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间(%) (idle/total)*100

sar 監控cpu,mem,i/o,net io

sar -P All 1 2  //監控所有cpu狀態,間隔1秒,共2次
sar -u 2 3      //監控所有cpu狀態,間隔2秒,共3次
sar -r //記憶體使用統計
sar -R //記憶體整體統計
sar -W //swap統計
sar -b //I/O及傳輸率統計
sar -d //block device statistics. 
       //block device is a kind of file,
       //which represents a device of some kind, with data 
       //that can be read or written to it in block.
       //可用block形式讀寫資料的裝置(linux中都當成檔案)


 -b I/O and transfer rate statistics
 -B Paging statistics
 -d Block device statistics
 -F [ MOUNT ]
  Filesystems statistics
 -H Hugepages utilization statistics
 -I {  | SUM | ALL | XALL }
  Interrupts statistics
 -m { [,...] | ALL }
  Power management statistics
  Keywords are:
  CPU CPU instantaneous clock frequency
  FAN Fans speed
  FREQ CPU average clock frequency
  IN Voltage inputs
  TEMP Devices temperature
  USB USB devices plugged into the system
 -n {  [,...] | ALL }
  Network statistics
  Keywords are:
  DEV Network interfaces
  EDEV Network interfaces (errors)
  NFS NFS client
  NFSD NFS server
  SOCK Sockets (v4)
  IP IP traffic (v4)
  EIP IP traffic (v4) (errors)
  ICMP ICMP traffic (v4)
  EICMP ICMP traffic (v4) (errors)
  TCP TCP traffic (v4)
  ETCP TCP traffic (v4) (errors)
  UDP UDP traffic (v4)
  SOCK6 Sockets (v6)
  IP6 IP traffic (v6)
  EIP6 IP traffic (v6) (errors)
  ICMP6 ICMP traffic (v6)
  EICMP6 ICMP traffic (v6) (errors)
  UDP6 UDP traffic (v6)
 -q Queue length and load average statistics
 -r Memory utilization statistics
 -R Memory statistics
 -S Swap space utilization statistics
 -u [ ALL ]
  CPU utilization statistics
 -v Kernel table statistics
 -w Task creation and system switching statistics
 -W Swapping statistics
 -y TTY device statistics

uptime

檢視服務器負載狀況
uptime
 22:37:31 up 65 days, 3:15, 1 user, load average: 40.00, 25.01, 10.05
檢視當前服務器1min, 5min, 15min 平均負載
是cpu負載、IO負載的整體評估
如果1min 的值大於 15min的值,表示負載越來越高。

dmesg

檢視資訊
$ dmesg |tail
[ 2567.534310] IPv6: ADDRCONF(NETDEV_UP): em3: link is not ready
[ 2570.386536] tg3 0000:02:00.0 em3: Link is up at 1000 Mbps, full duplex
[ 2570.386550] tg3 0000:02:00.0 em3: Flow control is off for TX and off for RX
[ 2570.386555] tg3 0000:02:00.0 em3: EEE is disabled
[ 2570.386584] IPv6: ADDRCONF(NETDEV_CHANGE): em3: link becomes ready
[20907.774686] perf: interrupt took too long (2502 > 2500), lowering kernel.perf_event_max_sample_rate to 79000
[50276.167405] perf: interrupt took too long (3173 > 3127), lowering kernel.perf_event_max_sample_rate to 63000
[96662.454537] perf: interrupt took too long (4010 > 3966), lowering kernel.perf_event_max_sample_rate to 49000
[143249.558510] perf: interrupt took too long (5025 > 5012), lowering kernel.perf_event_max_sample_rate to 39000
[204028.503117] perf: interrupt took too long (6286 > 6281), lowering kernel.perf_event_max_sample_rate to 31000

vmstat

檢視虛擬記憶體狀況
記憶體、分頁、IO、cpu
$ vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r b swpd free buff cache si so bi bo in cs us sy id wa st
 0 0 0 3082644 2076 4156120 0 0 1 210 12 9 1 0 99 0 0
 0 0 0 3083180 2076 4156112 0 0 0 473 2231 2420 1 0 99 0 0
 0 0 0 3083212 2076 4156112 0 0 0 12510 3946 3945 1 2 97 0 0
 0 0 0 3083684 2076 4156096 0 0 0 1403 2333 1725 1 0 99 0 0
 1 0 0 3082868 2076 4156388 0 0 0 505 2307 1795 4 1 95 0 0
 0 0 0 3083508 2076 4156040 0 0 0 475 1888 1570 1 1 99 0 0
 0 0 0 3083152 2076 4156040 0 0 0 8090 1694 1910 1 1 99 0 0

procs

r:在cpu上執行和等待執行的程式數量
b:阻塞的程式

memory

swpd:虛擬記憶體使用大小
free:空閒的記憶體大小
buffer:用作 buffer 的記憶體大小
cache:用作 cache 的記憶體大小

swap

si:每秒從交換區寫道記憶體的大小
so:每秒寫入到交換區的大小

IO

bi:block device 每秒接收的 block 數量
bo:block device 每秒傳送的 block 數量

system

in:每秒 cpu 中斷次數
cs:每秒 content 切換次數(越小越好)

CPU

us:使用者的 cpu 時間
sy:系統核心執行 cpu 時間
id:空閒的 cpu 時間
wa:等待 IO 的時間
st:從虛擬機中偷走的時間?

free

檢視系統整體記憶體
$ free -h
    total used free shared buff/cache available
Mem: 7.6G   697M   3.0G   23M   3.9G    6.5G
Swap: 8.0G   0B   8.0G
buffer cache 是block device 的記憶體快取
page cache 是檔案資料的快取

2019年11月13日 星期三

Gitlab and Sourcetree

Generate ssh key

cd ~/.ssh
ssh-keygen -t rsa -C "email@ex.com"  //email 可隨便打
//產生 id_rsa //密鑰
//id_rsa.pub //公鑰
//檔名一定要是id_rsa,因為sourcetree 不能匯入ssh key, 只會找預設的key

Gitlab ssh setting

登入gitlab,
左側欄有SSH Keys,
貼上 id_rsa.pub的內容,
最後的email不用貼

Testing

ssh://git@host/test.git
//user 一定要是git,這是自架的gitlab預設的
//有反應就是設定正確

Sourcetree setting

在sourcetree的設定裡,改成跟ssh 測試一樣。
ssh://git@host/test.git

問題

1 如果domain不行,改用ip
2 記得user 要用git