linux常用命令中naned启动失败

等待进程结束wait()和waitpid()函数
上一节最后我们说到若子进程先于父进程结束时,父进程调用wait()函数和不调用wait()函数会产生两种不同的结果:
--如果父进程没有调用wait()和waitpid()函数,子进程就会进入僵死状态。
--如果父进程调用了wait()和waitpid()函数,就不会使子进程变为僵尸进程。
这是为什么呢?现在我们来深入学习wait()函数和waitpid()函数。
一.wait()和waitpid()学习
1.首先我们先看一下它们的函数原型:
在终端输入命令:man 2 wait
就会看到它的函数原型:
wait, waitpid, waitid - wait for process to change state
#include &sys/types.h&
#include &sys/wait.h&
pid_t wait(int *status);
pid_t waitpid(pid_t pid, int *status, int options);
int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
我们可以看到在2.6版本中新增叫了waitid()函数。
2.wait()和waitpid()的功能:
1&wait()函数使父进程暫停执行,直到它的一个子进程结束为止,该函数的返回值是终止运行的子进程的PID. 参数status所指向
的变量存放子进程的退出码,即从子进程的main函数返回的值或子进程中exit()函数的参数。如果status不是一个空指针,状态信息将被写入它指向的变
2& 头文件sys/wait.h中定义了进程退出状态的宏。
我们首先看下官方的解释
a.WIFEXITED(status) r eturns true if the child terminated
normally, that is, by calling exit(3) or _exit(2), or by returning from main()
Tiger-John翻译:
WIFEXITED(status) 若子进程是正常结束时则返回一个非零值。即调用exit(3),_exit(3) 或从main()函数返回的值。
b. WEXITSTATUS(status) returns the exit status of the child.
This consists of the
least significant 8 bits of the status argument that the child
specified in a call to exit(3) or _exit(2) or
as the argument for
a return statement in main().
This macro should only be employed if WIFEXITED returned true.
Tiger-John翻译:
WEXITSTATUS(status) 如果宏 WIFEXIED返回值为非零值时,它返回子进程中exit或_exit参数中的低8位。
c.W IFSIGNALED(status) returns true if the child process was
terminated by a signal.
Tiger-John翻译:
WIFSIGNALED(status) 若子进程异常终止则返回一个非零值。
d. WTERMSIG(status) returns the number of the signal that caused
the child process
to terminate. This macro should
only be employed if WIFSIGNALED returned true.
Tiger-John翻译:
WTERMSIG(status) 如果宏WIFSIGNALED的返回值非零,则返回使子进程异常终止的信号编号。
e.WIFSTOPPED(status) returns true if the child process was stopped
by delivery
is only possible if the call was
done using WUN‐TRACED or when the child is being traced (see ptrace(2)).
Tiger-John翻译:
WIFSTOPPED(status) 若子进程由于异常暫停,则返回一个非零值。当调用 WUN‐TRACED或子进程被跟踪时这才时可能的。
f. WSTOPSIG(status) returns the number of the signal which
caused the child to stop.This macro should only be employed if WIFSTOPPED
returned true.
Tiger-John翻译:
WSTOPSIG(status) 如果宏WIFSTOPPED返回值非零,则返回使子进程暫停的信号编号。
g.WIFCONTINUED(status) (since
Linux 2.6.10) returns
true if the child process was
resumed by delivery of SIGCONT.
Tiger-John翻译:
WIFCONTINUED(status) (从2.6版本后)如果孩子进程通过SIGCONT恢复则返回一个非零
3&waitpid() 函数
(1)我们先来看一个waitpid()的经典例子:当我们下载了A软件的安装程序后,在安装快结束时它又启动了另外一个流氓软件安装程序B,当B也安装结束后,才告诉你所有安装都完成了。A和B分别在不同的进程中,A如何启动B并知道B安装完成了呢?可以很简单地在A中用fork启动B,然后用 waitpid()来等待B的结束。
(2)waitpid()也用来等待子进程的结束,但它用于等待某个特定进程结束。参数pid指明要等待的子进程的PID,参数 status的含义与wait()函数中的 status相同。options参数可以用来改变waitpid的行为,若将该参数赋值为WNOHANG,则使父进程不被挂起而立即返回执行其后的代
(3)waitpid()函数中参数pid的取值
还是先看下官方解释:
value of pid can be:
& -1 meaning wait
for any child process whose process group ID is
equal to the absolute value of
-1 meaning wait for any child
0 meaning wait for any child
process whose process group
equal to that of the calling
& 0 meaning wait
for the child
whose process ID is equal to the
value of pid.
Tiger-John翻译:
pid的值可以为下己中情况:
   & -1 等待其组ID等于pid绝对值的任一子进程。
  =-1 等待任一子进程
等待其组ID等于调用进程的组ID的任一进程
   & 0 等待其进程ID等于pid的子进程退出
(4)waitpid()函数的一个应用:
 如果想让父进程周期性地检查某个特定的子进程是否已经退出,可以用下面的方法:
  waitpid(child_pid,(int *) 0,WNOHANG);
如果子进程尚未退出,它将返回0;如果子进程已经结束,则返回child_pid。调用失败时返回-1。失败的原因包括没有该子进程,参数不合法等。
3.wait()和 waitpid() 函数的区别
(1). 在一个子进程终止前,wait()使其调用者阻塞,而waitpid()有一个选项,可使调用者不阻塞。
(2). waitpid()并不等待在其调用之后的第一个终止子进程,它有若干个选项,可以控制它所等待的进程。
(3). 对于wait(),其唯一的出错是调用进程没有子进程;对于waitpid(),若指定的进程或进程组不存在,或者参数pid指定的进程不是调用进程的子进程都可能出错。
(4). waitpid()提供了wait()没有的三个功能:一是waitpid()可等待一个特定的进程;二是waitpid()提供了一个wait()的非阻塞版本(有时希望取的一个子进程的状态,但不想使父进程阻塞,waitpid() 提供了一个这样的选择:WNOHANG,它可以使调用者不阻塞);三是waitpid()支持作业控制。
wait(&status) 的功能就等于waitpid(-1, &status, 0);
函数实例:
有时希望取的一个子进程的状态,但不想使父进程阻塞,waitpid() 提供了一个这样的选择:WNOHANG,它可以使调用者不阻塞
/* 如果是父进程 */
pr=waitpid(pc, NULL, WNOHANG);
/* 使用了WNOHANG参数,waitpid不会在这里等待 */
if(pr==0){ /* 如果没有收集到子进程 */
rintf("No child exited/n");
}while(pr==0); /* 没有收集到子进程,就回去继续尝试 */
if(pr==pc)
printf("successfully get child %d/n", pr);
printf("some error occured/n");
Tiger-John总结
无论进程是否正常终止,内核都会向其父进程发送SIGCHLD 信号, 当调用wait或waitpid函数时
(a) 如果所有的子进程都在run, 可以阻塞父进程。
(b) 如果子进程终止,则wait立即返回子进程终止状态。
(c) 如果没有子进程在运行, 立即返回error。
4.函数实现:
1.(先看一个简单的实例,看看进程调用wait()函数后是如何执行的?)
#include&stdio.h&
#include&sys/types.h&
#include&sys/wait.h&
#include&unistd.h&
#include&stdlib.h&
int main()
child = fork();
12 if(child & 0){
13 printf("create
failed!/n");
14 exit(1);
else if (0 == child){
17 printf("this is the child
process pid= %d/n",getpid());
18 for(i = 0;i&5;i++){
19 printf("this is
the child process print %d !/n",i+1);
printf("the child end/n");
24 printf("this is the father
process,ppid=%d/n",getppid());
25 printf("father wait the
child end/n");
26 wait(&child);
27 printf("father
函数经过编译:
think@ubuntu:~/work/process_thread/wait$ gcc
wait.c -o wait
think@ubuntu:~/work/process_thread/wait$
函数执行结果:
this is the father process,ppid=3303
father wait the child end
this is the child process pid= 3356
this is the child process print 1 !
this is the child process print 2 !
this is the child process print 3 !
this is the child process print 4 !
this is the child process print 5 !
the child end
father end
Tiger-John说明:
从上面的程序我们可以深入的了解wait() 函数的执行过程:
当父进程调用wait()函数后被挂起等待,直到子进程结束为止。
函数实例2(现在我们在通过一个实例,来深入了解wait()函数的执行过程)
#include&stdio.h&
#include&sys/types.h&
#include&sys/wait.h&
#include&unistd.h&
#include&stdlib.h&
int main()
printf("tiger study how to get exit code/n");
pid = fork();
if(0 == pid){
16 msg = " child process is
18 exit_code = 37;
else if(pid &0){
21 exit_code = 0;
24 perror("process creation
failed/n");
25 exit(1);
if(pid & 0){
30 pid_t child_
32 child_pid = wait(&status);
34 printf("child process has
exited,pid = %d/n",child_pid);
35 if(WIFEXITED(status)){
36 printf("child
exited with code %d/n",WEXITSTATUS(status));
39 printf("child
exited abnormally/n");
43 while(i-- & 0){
44 puts(msg);
45 sleep(1);
函数进过编译后:
think@ubuntu:~/work/process_thread/wait$
gcc wait1.c -o wait1
think@ubuntu:~/work/process_thread/wait$
函数执行结果
tiger study how to get exit code
child process is running
child process is running
child process is running
child process is running
child process is running
child process has exited,pid = 3816
child exited with code 0
Tiger-John说明:
父进程调用wait()函数后被挂起(我们可以再开一个终端,输入命令:ps aux,可以看到父进程的执行结果为S)直到子进程结束。子进程结束后,wait()函数返回刚刚结束运行的子进程的pid,宏WEXITSTATUS获取子进程的退出码。
1、利用Linux的进程管理命令ps、top、nice来监视、跟踪进程、修改进程优先级,体会进程状态的关系。
2、实现进程调度在日 零点向所有用户发出新年贺信。
3、实现许昌学院信...
进程的引入由于早期未配置os的系统和单道批处理系统中程序是顺序执行的,然而这种方式浪费资源、系统资源利用率较低,从而出现了多道批处理系统。内存中可以同时装入多个程序,使其共享资源、并发执行。为了能使程...
进程状态及状态转换 我们首先,先来看一下最基本的
状态一共有三个,运行态、 就绪态、
等待态 那么运行态指的是
这个进程已经拥有了CPU 并且在CPU上执行。 就绪态
指的是进程已经具备了运行的条件 ...
屏蔽信号:
在 sigaction 的使用中,我们已经看到了表示信号集的 sigset_t 型数据。在 Linux 上有一组函
数专门用于对信号集进行操作:
Linux进程入门学习1.进程的概念
一个可执行的程序文件(ELF格式)被加载到内存当中,然后让CPU逐条执行其代码,根据代码作出相应的动作,这样一个动态进程就产生了。因此,进程是一个动态变化的...
创建状态:进程在创建时需要申请一个空白PCB,向其中填写控制和管理进程的信息,完成资源分配。如果创建工作无法完成,比如资源无法满足,就无法被调度运行,把此时进程所处状态称为创建状态
就绪状态...
linux中进程有五种状态
1 可运行 (R)
处于可运行状态的进程,一旦有机会,就会访问CPU。多个进程可以(而且经常)处于可运行状态,但是因为...
本文参考书籍
1.操作系统真相还原
2.Linux内核完全剖析:基于0.12内核
3.x86汇编语言
从实模式到保护模式
ps:基于x86硬件的pc系统
进程是一种控制流集合,集合...
这次,我将直接使用sink,而不用add_file_log 函数的帮助。这个例子显示了如何格式化日志,将sink注册到core中,写日志到本地文件。完整的代码在下面。#include
#includ...
创建状态:进程在创建时需要申请一个空白PCB,向其中填写控制和管理进程的信息,完成资源分配。如果创建工作无法完成,比如资源无法满足,就无法被调度运行,把此时进程所处状态称为创建状态就绪状态:进程已经准...
没有更多推荐了,linux吧-百度贴吧--Just 4 Fun--The Linux kernel is a Unix-like computer operating system kernel. It is used
签到排名:今日本吧第个签到,
本吧因你更精彩,明天继续来努力!
本吧排名:
本吧签到人数:4812
可签7级以上的吧50个
本月漏签0次!
成为超级会员,赠送8张补签卡
连续签到:天&&累计签到:天
超级会员单次开通12个月以上,赠送连续签到卡3张
Just 4 Fun
当切换root用户后, 终端提示符变成了&用户名#&, 怎样修改成 &root@用户名:绝对路径# &这样的
就让我沉迷linux无法自拔吧!
官方通知 /steamcommunity.com/games/221410/announcements/detail/9350561 Steam兼容工具Steam Play正式发布,实际就
我觉得很有必要修改一下。
为什么硬盘一共107GB,我才用了30多GB; /dev/mapper/cl-root 挂载在根目录下,但是根目录才27GB,怎么才能扩大容
这个系统要怎么安装呀
小白捣鼓了三天了,还是报错求前辈指点
类似alpine linux,,最好基于debian
在飞机准备起飞的时候正好在开机 直接暴露了这架飞机后台的部分信息 数据库应该是mysql 文件系统只读的
听老哥们的,直接上手删了windows装了ubuntn,现在问题来了。
怎么现在bt软件都下载不了电影了,前几周都可以,现在都不行了。
n卡驱动太难受了,bumblebee不支持vulkan。 so nvidia fxck you
在安装mysql community serverx64后无法启动 我用yum源来安装的求解
有喜欢使用 Manjaro的吗? 说说好处
一楼喂百度。
小白有个问题求指教。。单引号里的不是原样输出吗,那greeting 2和greeting 3为啥结果不一样???
小弟我想学习服务器如何装linux系统,哪个版本更适合服务器装,系统从哪下,安装步骤, 求大神帮助。
大佬们,我在Linux下配置YOLO,但是make darknet的时候总显示无效的选项参数'ofast'
我给单位的终端配环境,结果管it的把外网屏蔽了,一堆东西下不下来,全都显示”Unable to locate package”。
OMG,gnone开机八百多兆占用,CPU百分之进百分之三十不下,kde开机四百多内存,CPU占用十以下,为何差距这
不小心重启了公司服务器咋么办
有大神能百度云共享学习视频和资料的吗
在这之前关机清理过一次磁盘就炸了,今天还好好的。 里边有我重要的NFS文件系统,现在换乌班图了,板
如图所示,现在要个需求,19这台java进程随机生成的会话请求怎么出不去呢?
虚拟机里配置的web服务器,主机访问不了,端口已经开启,win命令能通
男怕入错行,2012年自动化专业大专毕业,从事及学语言编程,后来转行做Java开发,两年了,老实讲国内的
谁跟窝搞基术论坛
考大家一个和弦dm7/g
用的是14,然后也没有挂载的步骤
如何在CmakeLists 中添加动态库,求大神解答
萌新的root用户默认被锁。 但是我的用户没办法登录。。。切换不来。咋搞 如图 密码没错。。
Ubuntu16.04.5安装好之后怎样启动,怎么找不到启动的地方(重启之后进入的是Windows界面)
原本以为这么轻巧的系统会非常省电,会比较适合笔记本用, 结果试了ubuntu,kali 一个比一个耗电厉害,
上课时跟同桌吹比说你知道rm -rf /*命令吗,他说你打出来看看,***就在终端上打了出来,心里想就算按回
写了一个shell脚本,用来进行日志分隔,结果出了点错
ffmpeg要怎么调用qsv硬件加速呢?按照文档上的ffmepg -hwaccel qsv -c:v hevc_qsv -i XXX -c:v h264_qsv YYY老是报错
我是双击打开.rpm包的,系统是刚装的,请大神指教
为什么要设置用户的登录shell,这个我一直不明白,求大佬解答。还有,可以用自己的话说一下吗,百度上
有个问题想请教大家。同一款软件下载的安装包,不同型号手机的下载路径都是不同的吗?还是不同手机
问题报错有几处,主要是不太确定是哪的问题。
基佬们怎么看待这个
WIN10 RS2,内置的是ubuntu 16.04 按照GAYHUB上面14.04的方法不管用 https://github.com/Microsoft/BashOnWindows/issues/637 到执
我通过编写c编写程序test.c 调用shell脚本登录root,为什么不成功?test.c具体代码如下:
ERROR ): Unknown column '?sada?' in 'field list' 创建数据库 create table bbb
你可能感兴趣的吧...
发贴红色标题
签到六倍经验
兑换本吧会员
赠送补签卡1张,获得
助攻总额: 43W
贴吧热议榜
发表后自动分享本贴
使用签名档&bin = BINaries
-----二进制/dev = DEVices -----设备/etc = ETCetera -----诸如此类/lib = LIBrary /proc = PROCesses /sbin = Superuser BINaries /tmp = TeMPorary /usr = Unix Shared Resources /var = VARiable ? FIFO = First In, First Out GRUB = GRand Unified Bootloader IFS = Internal Field Seperators LILO = LInux LOader MySQL = My是最初作者女儿的名字,SQL = Structured Query Language PHP = Personal Home Page Tools = PHP Hypertext Preprocessor PS = Prompt String Perl = "Pratical Extraction and Report Language" = "Pathologically Eclectic Rubbish Lister" Python 得名于电视剧Monty Python's Flying Circus Tcl = Tool Command Language Tk = ToolKit VT = Video Terminal YaST = Yet Another Setup Tool apache = "a patchy" server apt = Advanced Packaging Tool ar = archiver as = assembler awk = "Aho Weiberger and Kernighan" 三个作者的姓的第一个字母 bash = Bourne Again SHell bc = Basic (Better) Calculator bg = BackGround biff = 作者Heidi Stettner在U.C.Berkely养的一条狗,喜欢对邮递员汪汪叫。 cal = CALendar cat = CATenate cd = Change Directory chgrp = CHange GRouP chmod = CHange MODe chown = CHange OWNer chsh = CHange SHell cmp = compare cobra = Common Object Request Broker Architecture comm = common cp = CoPy cpio = CoPy In and Out cpp = C Pre Processor cron = Chronos 希腊文时间 cups = Common Unix Printing System cvs = Current Version System daemon = Disk And Execution MONitor dc = Desk Calculator dd = Disk Dump df = Disk Free diff = DIFFerence dmesg = diagnostic message du = Disk Usage ed = editor egrep = Extended GREP elf = Extensible Linking Format elm = ELectronic Mail emacs = Editor MACroS eval = EVALuate ex = EXtended exec = EXECute fd = file descriptors fg = ForeGround fgrep = Fixed GREP fmt = format fsck = File System ChecK fstab = FileSystem TABle fvwm = F*** Virtual Window Manager gawk = GNU AWK gpg = GNU Privacy Guard groff = GNU troff hal = Hardware Abstraction Layer joe = Joe's Own Editor ksh = Korn SHell lame = Lame Ain't an MP3 Encoder lex = LEXical analyser lisp = LISt Processing = Lots of Irritating Superfluous Parentheses ln = LiNk lpr = Line PRint ls = list lsof = LiSt Open Files m4 = Macro processor Version 4 man = MANual pages mawk = Mike Brennan's AWK mc = Midnight Commander mkfs = MaKe FileSystem mknod = MaKe NODe motd = Message of The Day mozilla = MOsaic GodZILLa mtab = Mount TABle mv = MoVe nano = Nano's ANOther editor nawk = New AWK nl = Number of Lines nm = names nohup = No HangUP nroff = New ROFF od = Octal Dump passwd = PASSWorD pg = pager pico = PIne's message COmposition editor pine = "Program for Internet News & Email" = "Pine is not Elm" ping = 拟声 又 = Packet InterNet Grouper pirntcap = PRINTer CAPability popd = POP Directory pr = pre printf = PRINT Formatted ps = Processes Status pty = pseudo tty pushd = PUSH Directory pwd = Print Working Directory rc = runcom = run command, rc还是plan9的shell rev = REVerse rm = ReMove rn = Read News roff = RunOFF rpm = RPM Package Manager = RedHat Package Manager rsh, rlogin, rvim中的r = Remote rxvt = ouR XVT seamoneky = 我 sed = Stream EDitor seq = SEQuence shar = SHell ARchive slrn = S-Lang rn ssh = Secure SHell ssl = Secure Sockets Layer stty = Set TTY su = Substitute User svn = SubVersioN tar = Tape ARchive tcsh = TENEX C shell tee = T (T形水管接口) telnet = TEminaL over Network termcap = terminal capability terminfo = terminal information tex = τ?χνη的缩写,希腊文art tr = traslate troff = Typesetter new ROFF tsort = Topological SORT tty = TeleTypewriter twm = Tom's Window Manager tz = TimeZone udev = Userspace DEV ulimit = User's LIMIT umask = User's MASK uniq = UNIQue vi = VIsual = Very Inconvenient vim = Vi IMproved wall = write all wc = Word Count wine = WINE Is Not an Emulator xargs = eXtended ARGuments xdm = X Display Manager xlfd = X Logical Font Description xmms = X Multimedia System xrdb = X Resources DataBase xwd = X Window Dump yacc = yet another compiler compiler
linux中如何以一个命令的输出作为另外一个命令的输入---用``
在linux中, 我们经常用到xargs命令, 这个命令很重要, 它可以以一个命令的输出作为另外一个命令的输入, 其实, 用``也能实现类似功能。 请注意这个符号, 它不是引号, 而是倒引号, 它在电...
Linux部分命令缩写解释
bin = BINaries /dev = DEVices /etc = ETCetera /lib = LIBrary /proc = PROCesses /sbin = Superuser BIN...
Linux20个常用命令
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了。当然你也可以在使用时去找一下...
Linux 命令缩写部分解释
linux 部分缩写命令释义,加深对linux命令的理解、记忆和使用
Linux多命令顺序执行连接符(; || && |)
当我们需要一次执行多个命令的时候,命令之间需要用连接符连接,不同的连接符有不同的效果。下面我们总结一下,加以区分。
分号,没有任何逻辑关系的连接符。当多个命令用分号连接时,各命令之...
linux 命令缩写
不废话直接上例子
drwxrwxrwx
4096 Oct 16 11:32 style
前面十位字符,分成四段 d | rwx |rwx |rwx
第一段代表文件的类型,...
文章来源:http://www.cnblogs.com/luyajin/p/5557262.html
1、linux命令:
默认进入系统,我们会看到这样的字符: [root@localhost ~...
没有更多推荐了,
(window.slotbydup=window.slotbydup || []).push({
id: "5865577",
container: s,
size: "300,250",
display: "inlay-fix"linux的named服务启动不啦,_百度知道
linux的named服务启动不啦,
这个是错误提示...
这个是错误提示
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
xinzhongqiang
xinzhongqiang
采纳数:67
获赞数:130
如果你出现启动服务失败:这里有几种失败的原因你可以参考一下:1、你DNS的配置文件出现了错误。2、声明文件中的文件名与你在/var/named/chroot/var/named/这个文件中的文件名不对应。3、可能是你在正向或反向解析的配置文件配置的不对。(包括各式不对、多了逗号,分号都不行。)所以你在自习检查一下。
QQ爱老婆去
QQ爱老婆去
采纳数:136
获赞数:255
配置文件不全啊
zone文件的配置错误,按照defualt格式的文件进行编辑,改写
为你推荐:
其他类似问题
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。&figure&&img src=&https://pic1.zhimg.com/v2-e5bcc8d9b433a114d5e29_b.jpg& data-rawwidth=&720& data-rawheight=&340& class=&origin_image zh-lightbox-thumb& width=&720& data-original=&https://pic1.zhimg.com/v2-e5bcc8d9b433a114d5e29_r.jpg&&&/figure&&p&systemd 意即 &i&系统守护进程(system daemon)&/i&,是一个新的初始化系统和系统管理工具,它现在非常流行,大部分的 Linux 发行版开始使用这种新的初始化系统。&/p&&p&&code&systemctl&/code& 是一个 systemd 的工具,它可以帮助我们管理 systemd 守护进程。 它控制系统的启动程序和服务,使用并行化方式,为启动的服务激活套接字和 D-Bus,提供守护进程的按需启动,使用 Linux 控制组跟踪进程,维护挂载和自动挂载点。&/p&&p&此外,它还提供了日志守护进程、用于控制基本系统配置的功能,如主机名、日期、地区、维护已登录用户列表和运行容器和虚拟机、系统帐户、运行时目录和设置,以及管理简单网络配置、网络时间同步、日志转发和名称解析的守护进程。&/p&&h2&&b&什么是 chkservice&/b&&/h2&&p&&a href=&http://link.zhihu.com/?target=https%3A//github.com/linuxenko/chkservice& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&chkservice&/a& 是一个基于 ncurses 的在终端中管理 systemd 单元的工具。它提供了一个非常全面的 systemd 服务的视图,使得它们非常容易修改。&/p&&p&只有拥有超级管理权限才能够改变 systemd 单元的状态和 sysv 系统启动脚本。&/p&&h2&&b&在 Linux 安装 chkservice&/b&&/h2&&p&我们可以通过两种方式安装 &code&chkservice&/code&,通过包安装或者手动安装。&/p&&p&对于 Debian/Ubuntu,使用 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/apt-get-apt-cache-command-examples-manage-packages-debian-ubuntu-systems/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&APT-GET 命令&/a& 或 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/apt-command-examples-manage-packages-debian-ubuntu-systems/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&APT 命令&/a& 安装 &code&chkservice&/code&。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo add-apt-repository ppa:linuxenko/chkservice
$ sudo apt-get update
$ sudo apt-get install chkservice
&/code&&/pre&&/div&&p&对于 Arch Linux 系的系统,使用 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/install-yaourt-aur-helper-on-arch-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Yaourt 命令&/a& 或 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/install-packer-aur-helper-on-arch-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Packer 命令&/a& 从 AUR 库安装 &code&chkservice&/code&。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ yaourt -S chkservice
$ packer -S chkservice
&/code&&/pre&&/div&&p&对于 Fedora,使用 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/dnf-command-examples-manage-packages-fedora-system/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&DNF 命令&/a& 安装 &code&chkservice&/code&。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo dnf copr enable srakitnican/default
$ sudo dnf install chkservice
&/code&&/pre&&/div&&p&对于 Debian 系系统,使用 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/dpkg-command-to-manage-packages-on-debian-ubuntu-linux-mint-systems/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&DPKG 命令&/a& 安装 &code&chkservice&/code&。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ wget https://github.com/linuxenko/chkservice/releases/download/0.1/chkservice_0.1.0-amd64.deb
$ sudo dpkg -i chkservice_0.1.0-amd64.deb
&/code&&/pre&&/div&&p&对于 RPM 系的系统,使用 &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/rpm-command-examples/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&DNF 命令&/a& 安装 &code&chkservice&/code&。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo yum install https://github.com/linuxenko/chkservice/releases/download/0.1/chkservice_0.1.0-amd64.rpm
&/code&&/pre&&/div&&h2&&b&如何使用 chkservice&/b&&/h2&&p&只需输入以下命令即可启动 &code&chkservice&/code& 工具。 输出分为四部分。&/p&&ul&&li&&b&第一部分:&/b& 这一部分显示了守护进程的状态,比如可用的 &code&[X]&/code& 或者不可用的 &code&[ ]&/code& 或者静态的 &code&[s]&/code& 或者被掩藏的 &code&-m-&/code&&/li&&li&&b&第二部分:&/b& 这一部分显示守护进程的状态例如开始 &code&&&/code& 或者停止 &code&=&/code&&/li&&li&&b&第三部分:&/b& 这一部分显示单元的名称&/li&&li&&b&第四部分:&/b& 这一部分简短地显示了守护进程的一些信息&/li&&/ul&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo chkservice
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-179fabe866fa09baf23557f_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1049& data-rawheight=&577& class=&origin_image zh-lightbox-thumb& width=&1049& data-original=&https://pic4.zhimg.com/v2-179fabe866fa09baf23557f_r.jpg&&&/figure&&p&&br&&/p&&p&要查看帮助页面,按下 &code&?&/code&。 这将向您显示管理 systemd 服务的可用选项。&/p&&p&&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-c7d3b2dacf0_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&540& data-rawheight=&387& class=&origin_image zh-lightbox-thumb& width=&540& data-original=&https://pic1.zhimg.com/v2-c7d3b2dacf0_r.jpg&&&/figure&&p&&br&&/p&&p&选择要启用或禁用的守护进程,然后点击空格键。&/p&&p&&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-72c2fb171a50_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1049& data-rawheight=&577& class=&origin_image zh-lightbox-thumb& width=&1049& data-original=&https://pic1.zhimg.com/v2-72c2fb171a50_r.jpg&&&/figure&&p&&br&&/p&&p&选择你想开始或停止的守护进程,然后按下 &code&s&/code&。&/p&&p&&br&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-a384ed8abb2a6f53f7b9_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1049& data-rawheight=&577& class=&origin_image zh-lightbox-thumb& width=&1049& data-original=&https://pic2.zhimg.com/v2-a384ed8abb2a6f53f7b9_r.jpg&&&/figure&&p&&br&&/p&&p&选择要重新启动的守护进程,然后按下 &code&r&/code&,之后,您可以在顶部看到更新的提示。&/p&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-cacef3da7bdbfc9ce73867_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&1049& data-rawheight=&577& class=&origin_image zh-lightbox-thumb& width=&1049& data-original=&https://pic4.zhimg.com/v2-cacef3da7bdbfc9ce73867_r.jpg&&&/figure&&p&&br&&/p&&p&按下 &code&q&/code& 退出。&/p&&hr&&p&via: &a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/chkservice-a-tool-for-managing-systemd-units-from-linux-terminal/& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&https://www.&/span&&span class=&visible&&2daygeek.com/chkservice&/span&&span class=&invisible&&-a-tool-for-managing-systemd-units-from-linux-terminal/&/span&&span class=&ellipsis&&&/span&&/a&&/p&&p&作者:&a href=&http://link.zhihu.com/?target=https%3A//www.2daygeek.com/author/ramya/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Ramya Nuvvula&/a& 译者:&a href=&http://link.zhihu.com/?target=https%3A//github.com/amwps290& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&amwps290&/a& 校对:&a href=&http://link.zhihu.com/?target=https%3A//github.com/wxy& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&wxy&/a&&/p&&p&本文由 &a href=&http://link.zhihu.com/?target=https%3A//github.com/LCTT/TranslateProject& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&LCTT&/a& 原创编译,&a href=&http://link.zhihu.com/?target=https%3A//linux.cn/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux中国&/a& 荣誉推出&/p&
systemd 意即 系统守护进程(system daemon),是一个新的初始化系统和系统管理工具,它现在非常流行,大部分的 Linux 发行版开始使用这种新的初始化系统。systemctl 是一个 systemd 的工具,它可以帮助我们管理 systemd 守护进程。 它控制系统的启动程序和服…
&figure&&img src=&https://pic1.zhimg.com/v2-06fbeaae434ae6af34257bd_b.jpg& data-rawwidth=&1920& data-rawheight=&1080& class=&origin_image zh-lightbox-thumb& width=&1920& data-original=&https://pic1.zhimg.com/v2-06fbeaae434ae6af34257bd_r.jpg&&&/figure&&p&您需要监控 Linux 服务器的性能吗?试试用这些内置命令和附加工具吧!大多数 Linux 发行版都附带了大量的监控工具。这些工具提供了获取系统活动的相关指标。您可以使用这些工具来查找性能问题的可能原因。本文提到的是一些基本的命令,用于系统分析和服务器调试等,例如:&/p&&ol&&li&找出系统瓶颈&/li&&li&磁盘(存储)瓶颈&/li&&li&CPU 和内存瓶颈&/li&&li&网络瓶颈&/li&&/ol&&h2&&b&1. top - 进程活动监控命令&/b&&/h2&&p&&code&top&/code& 命令会显示 Linux 的进程。它提供了一个运行中系统的实时动态视图,即实际的进程活动。默认情况下,它显示在服务器上运行的 CPU 占用率最高的任务,并且每五秒更新一次。&/p&&p&&br&&/p&&figure&&img src=&https://pic3.zhimg.com/v2-0e35c52fbbc456c19d79bda_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&643& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic3.zhimg.com/v2-0e35c52fbbc456c19d79bda_r.jpg&&&figcaption&图 01:Linux top 命令&/figcaption&&/figure&&h2&&code&top 的常用快捷键&/code&&/h2&&p&常用快捷键列表:&/p&&figure&&img src=&https://pic1.zhimg.com/v2-86ad2f9d2fe7ff225eb842_b.jpg& data-caption=&& data-size=&normal& data-rawwidth=&604& data-rawheight=&336& class=&origin_image zh-lightbox-thumb& width=&604& data-original=&https://pic1.zhimg.com/v2-86ad2f9d2fe7ff225eb842_r.jpg&&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux 如何查看 CPU 利用率?&/a&&/p&&h2&&b&2. vmstat - 虚拟内存统计&/b&&/h2&&p&&code&vmstat&/code& 命令报告有关进程、内存、分页、块 IO、中断和 CPU 活动等信息。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# vmstat 3
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 2 32 4 2 4 1 96 0 0
&/code&&/pre&&/div&&h2&&code&显示 Slab 缓存的利用率&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# vmstat -m
&/code&&/pre&&/div&&h2&&code&获取有关活动和非活动内存页面的信息&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# vmstat -a
&/code&&/pre&&/div&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&如何查看 Linux 的资源利用率从而找到系统瓶颈?&/a&&/p&&h2&&b&3. w - 找出登录的用户以及他们在做什么&/b&&/h2&&p&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/unix-linux-w-command-examples-syntax-usage-2/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&w 命令&/a& 显示了当前登录在该系统上的用户及其进程。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# w username
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&17:58:47 up 5 days, 20:28, 2 users, load average: 0.36, 0.26, 0.24
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.1.3.145 14:55 5.00s 0.04s 0.02s vim /etc/resolv.conf
root pts/1 10.1.3.145 17:43 0.00s 0.03s 0.00s w
&/code&&/pre&&/div&&h2&&b&4. uptime - Linux 系统运行了多久&/b&&/h2&&p&&code&uptime&/code& 命令可以用来查看服务器运行了多长时间:当前时间、已运行的时间、当前登录的用户连接数,以及过去 1 分钟、5 分钟和 15 分钟的系统负载平均值。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# uptime
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&18:02:41 up 41 days, 23:42, 1 user, load average: 0.00, 0.00, 0.00
&/code&&/pre&&/div&&p&&code&1&/code& 可以被认为是最佳负载值。不同的系统会有不同的负载:对于单核 CPU 系统来说,&code&1&/code& 到 &code&3&/code& 的负载值是可以接受的;而对于 SMP(对称多处理)系统来说,负载可以是 &code&6&/code& 到 &code&10&/code&。&/p&&h2&&b&5. ps - 显示系统进程&/b&&/h2&&p&&code&ps&/code& 命令显示当前运行的进程。要显示所有的进程,请使用 &code&-A&/code& 或 &code&-e&/code& 选项:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -A
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&PID TTY TIME CMD
1 ? 00:00:02 init
2 ? 00:00:02 migration/0
3 ? 00:00:01 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 migration/1
6 ? 00:00:15 ksoftirqd/1
4881 ? 00:53:28 java
4885 tty1 00:00:00 mingetty
4886 tty2 00:00:00 mingetty
4887 tty3 00:00:00 mingetty
4888 tty4 00:00:00 mingetty
4891 tty5 00:00:00 mingetty
4892 tty6 00:00:00 mingetty
4893 ttyS1 00:00:00 agetty
12853 ? 00:00:00 cifsoplockd
12854 ? 00:00:00 cifsdnotifyd
14231 ? 00:10:34 lighttpd
14232 ? 00:00:00 php-cgi
54981 pts/0 00:00:00 vim
55465 ? 00:00:00 php-cgi
55546 ? 00:00:00 bind9-snmp-stat
55704 pts/1 00:00:00 ps
&/code&&/pre&&/div&&p&&code&ps&/code& 与 &code&top&/code& 类似,但它提供了更多的信息。&/p&&h2&&code&显示长输出格式&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -Al
&/code&&/pre&&/div&&p&显示完整输出格式(它将显示传递给进程的命令行参数):&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -AlF
&/code&&/pre&&/div&&h2&&code&显示线程(轻量级进程(LWP)和线程的数量(NLWP))&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -AlFH
&/code&&/pre&&/div&&h2&&code&在进程后显示线程&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -AlLm
&/code&&/pre&&/div&&h2&&code&显示系统上所有的进程&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps ax
&/code&&/pre&&/div&&h2&&code&显示进程树&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -ejH
&/code&&/pre&&/div&&h2&&code&显示进程的安全信息&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -eo euser,ruser,suser,fuser,f,comm,label
&/code&&/pre&&/div&&h2&&code&显示指定用户(如 vivek)运行的进程&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -U vivek -u vivek u
&/code&&/pre&&/div&&h2&&code&设置用户自定义的输出格式&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
# ps -eopid,tt,user,fname,tmout,f,wchan
&/code&&/pre&&/div&&h2&&code&显示某进程(如 lighttpd)的 PID&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -C lighttpd -o pid=
&/code&&/pre&&/div&&p&或&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# pgrep lighttpd
&/code&&/pre&&/div&&p&或&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# pgrep -u vivek php-cgi
&/code&&/pre&&/div&&h2&&code&显示指定 PID(如 55977)的进程名称&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -p 55977 -o comm=
&/code&&/pre&&/div&&h2&&code&找出占用内存资源最多的前 10 个进程&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -auxf | sort -nr -k 4 | head -10
&/code&&/pre&&/div&&h2&&code&找出占用 CPU 资源最多的前 10 个进程&/code&&/h2&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ps -auxf | sort -nr -k 3 | head -10
&/code&&/pre&&/div&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/show-all-running-processes-in-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&显示 Linux 上所有运行的进程&/a&&/p&&h2&&b&6. free - 内存使用情况&/b&&/h2&&p&&code&free&/code& 命令显示了系统的可用和已用的物理内存及交换内存的总量,以及内核用到的缓存空间。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# free
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&total used free shared buffers cached
-/+ buffers/cache: 1096
&/code&&/pre&&/div&&p&相关链接: 1. &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/linux-check-the-size-of-pagesize/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&获取 Linux 的虚拟内存的内存页大小(PAGESIZE)&/a& 2. &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/cpu-usage-limiter-for-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&限制 Linux 每个进程的 CPU 使用率&/a& 3. &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/how-much-ram-does-my-linux-system.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&我的 Ubuntu 或 Fedora Linux 系统有多少内存?&/a&&/p&&h2&&b&7. iostat - CPU 平均负载和磁盘活动&/b&&/h2&&p&&code&iostat&/code& 命令用于汇报 CPU 的使用情况,以及设备、分区和网络文件系统(NFS)的 IO 统计信息。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# iostat
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)
06/26/2009
avg-cpu: %user %nice %system %iowait %steal %idle
3.50 0.09 0.51 0.03 0.00 95.86
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 22.04 31.88 512.03 102868
sda1 0.00 0.00 0.00
sda2 22.04 31.87 512.03 102688
sda3 0.00 0.00 0.00 1615 0
&/code&&/pre&&/div&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/howto-linux-track-nfs-client-disk-metrics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&如何跟踪 Linux 系统的 NFS 目录或磁盘的 IO 负载情况&/a&&/p&&h2&&b&8. sar - 监控、收集和汇报系统活动&/b&&/h2&&p&&code&sar&/code& 命令用于收集、汇报和保存系统活动信息。要查看网络统计,请输入:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# sar -n DEV | more
&/code&&/pre&&/div&&p&显示 24 日的网络统计:&/p&&p&&code&# sar -n DEV -f /var/log/sa/sa24 | more&/code&&/p&&p&您还可以使用 &code&sar&/code& 显示实时使用情况:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# sar 4 5
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)
06/26/2009
06:45:12 PM CPU %user %nice %system %iowait %steal %idle
06:45:16 PM all 2.00 0.00 0.22 0.00 0.00 97.78
06:45:20 PM all 2.07 0.00 0.38 0.03 0.00 97.52
06:45:24 PM all 0.94 0.00 0.28 0.00 0.00 98.78
06:45:28 PM all 1.56 0.00 0.22 0.00 0.00 98.22
06:45:32 PM all 3.53 0.00 0.25 0.03 0.00 96.19
Average: all 2.02 0.00 0.27 0.01 0.00 97.70
&/code&&/pre&&/div&&p&相关链接:&/p&&ul&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/howto-write-system-utilization-data-to-file.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&如何将 Linux 系统资源利用率的数据写入文件中&/a&&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/identifying-linux-bottlenecks-sar-graphs-with-ksar.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&如何使用 kSar 创建 sar 性能图以找出系统瓶颈&/a&&/li&&/ul&&h2&&b&9. mpstat - 监控多处理器的使用情况&/b&&/h2&&p&&code&mpstat&/code& 命令显示每个可用处理器的使用情况,编号从 0 开始。命令 &code&mpstat -P ALL&/code& 显示了每个处理器的平均使用率:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# mpstat -P ALL
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&Linux 2.6.18-128.1.14.el5 (www03.nixcraft.in)
06/26/2009
06:48:11 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
06:48:11 PM all 3.50 0.09 0.34 0.03 0.01 0.17 0.00 95.86 1218.04
06:48:11 PM 0 3.44 0.08 0.31 0.02 0.00 0.12 0.00 96.04 1000.31
06:48:11 PM 1 3.10 0.08 0.32 0.09 0.02 0.11 0.00 96.28 34.93
06:48:11 PM 2 4.16 0.11 0.36 0.02 0.00 0.11 0.00 95.25 0.00
06:48:11 PM 3 3.77 0.11 0.38 0.03 0.01 0.24 0.00 95.46 44.80
06:48:11 PM 4 2.96 0.07 0.29 0.04 0.02 0.10 0.00 96.52 25.91
06:48:11 PM 5 3.26 0.08 0.28 0.03 0.01 0.10 0.00 96.23 14.98
06:48:11 PM 6 4.00 0.10 0.34 0.01 0.00 0.13 0.00 95.42 3.75
06:48:11 PM 7 3.30 0.11 0.39 0.03 0.01 0.46 0.00 95.69 76.89
&/code&&/pre&&/div&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/linux-mpstat-command-report-processors-related-statistics/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&多处理器的 Linux 上单独显示每个 CPU 的使用率&/a&.&/p&&h2&&b&10. pmap - 监控进程的内存使用情况&/b&&/h2&&p&&code&pmap&/code& 命令用以显示进程的内存映射,使用此命令可以查找内存瓶颈。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# pmap -d PID
&/code&&/pre&&/div&&p&显示 PID 为 47394 的进程的内存信息,请输入:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# pmap -d 47394
&/code&&/pre&&/div&&p&输出示例:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&47394: /usr/bin/php-cgi
Address Kbytes Mode Offset Device Mapping
r-x-- 02 php-cgi
rw--- 02 php-cgi
a9000 52 rw--- a00 [ anon ]
aa8000 76 rw--- a02 php-cgi
rw--- 00 [ anon ]
r-x-- 02 ld-2.5.so
b000 4 r---- b000 008:00002 ld-2.5.so
c000 4 rw--- c000 008:00002 ld-2.5.so
aa r-x-- 02 libc-2.5.so
ab4c000 2048 ----- c000 008:00002 libc-2.5.so
0fd000 4 rw--- 02 xsl.so
0c000 40 r-x-- 02 libnss_files-2.5.so
0 ----- a000 008:00002 libnss_files-2.5.so
0b15000 4 r---- 02 libnss_files-2.5.so
0b16000 4 rw--- a000 008:00002 libnss_files-2.5.so
0b rw-s- 09 zero (deleted)
00007fffc95fe000 84 rw--- 00007ffffffea000 000:00000 [ stack ]
ffffffffff2 ----- 00 [ anon ]
mapped: 933712K writeable/private: 4304K shared: 768000K
&/code&&/pre&&/div&&p&最后一行非常重要:&/p&&ul&&li&&code&mapped: 933712K&/code& 映射到文件的内存量&/li&&li&&code&writeable/private: 4304K&/code& 私有地址空间&/li&&li&&code&shared: 768000K&/code& 此进程与其他进程共享的地址空间&/li&&/ul&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/howto-find-memory-used-by-program.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&使用 pmap 命令查看 Linux 上单个程序或进程使用的内存&/a&&/p&&h2&&b&11. netstat - Linux 网络统计监控工具&/b&&/h2&&p&&code&netstat&/code& 命令显示网络连接、路由表、接口统计、伪装连接和多播连接等信息。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# netstat -tulpn
# netstat -nat
&/code&&/pre&&/div&&h2&&b&12. ss - 网络统计&/b&&/h2&&p&&code&ss&/code& 命令用于获取套接字统计信息。它可以显示类似于 &code&netstat&/code& 的信息。不过 &code&netstat&/code& 几乎要过时了,&code&ss&/code& 命令更具优势。要显示所有 TCP 或 UDP 套接字:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ss -t -a
&/code&&/pre&&/div&&p&或&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ss -u -a
&/code&&/pre&&/div&&p&显示所有带有 SELinux 安全上下文&i&Security Context&/i&的 TCP 套接字:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# ss -t -a -Z
&/code&&/pre&&/div&&p&请参阅以下关于 &code&ss&/code& 和 &code&netstat&/code& 命令的资料:&/p&&ul&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/linux-investigate-sockets-network-connections.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&ss:显示 Linux TCP / UDP 网络套接字信息&/a&&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/netstat-command-tutorial-examples.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&使用 netstat 命令获取有关特定 IP 地址连接的详细信息&/a&&/li&&/ul&&h2&&b&13. iptraf - 获取实时网络统计信息&/b&&/h2&&p&&code&iptraf&/code& 命令是一个基于 ncurses 的交互式 IP 网络监控工具。它可以生成多种网络统计信息,包括 TCP 信息、UDP 计数、ICMP 和 OSPF 信息、以太网负载信息、节点统计信息、IP 校验错误等。它以简单的格式提供了以下信息:&/p&&ul&&li&基于 TCP 连接的网络流量统计&/li&&li&基于网络接口的 IP 流量统计&/li&&li&基于协议的网络流量统计&/li&&li&基于 TCP/UDP 端口和数据包大小的网络流量统计&/li&&li&基于二层地址的网络流量统计&/li&&/ul&&p&&br&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-a178dd4e7e355c9f0d43_b.jpg& data-size=&normal& data-rawwidth=&600& data-rawheight=&347& class=&origin_image zh-lightbox-thumb& width=&600& data-original=&https://pic2.zhimg.com/v2-a178dd4e7e355c9f0d43_r.jpg&&&figcaption&图 02:常规接口统计:基于网络接口的 IP 流量统计&/figcaption&&/figure&&figure&&img src=&https://pic3.zhimg.com/v2-a857bca5b9ff_b.jpg& data-size=&normal& data-rawwidth=&600& data-rawheight=&416& class=&origin_image zh-lightbox-thumb& width=&600& data-original=&https://pic3.zhimg.com/v2-a857bca5b9ff_r.jpg&&&figcaption&图 03:基于 TCP 连接的网络流量统计&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/install-iptraf-centos-redhat-fedora-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&在 Centos / RHEL / Fedora Linux 上安装 IPTraf 以获取网络统计信息&/a&&/p&&h2&&b&14. tcpdump - 详细的网络流量分析&/b&&/h2&&p&&code&tcpdump&/code& 命令是简单的分析网络通信的命令。您需要充分了解 TCP/IP 协议才便于使用此工具。例如,要显示有关 DNS 的流量信息,请输入:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# tcpdump -i eth1 'udp port 53'
&/code&&/pre&&/div&&p&查看所有去往和来自端口 80 的 IPv4 HTTP 数据包,仅打印真正包含数据的包,而不是像 SYN、FIN 和仅含 ACK 这类的数据包,请输入:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)&&2)) - ((tcp[12]&0xf0)&&2)) != 0)'
&/code&&/pre&&/div&&p&显示所有目标地址为 202.54.1.5 的 FTP 会话,请输入:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# tcpdump -i eth1 'dst 202.54.1.5 and (port 21 or 20'
&/code&&/pre&&/div&&p&打印所有目标地址为 192.168.1.5 的 HTTP 会话:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# tcpdump -ni eth0 'dst 192.168.1.5 and tcp and port http'
&/code&&/pre&&/div&&p&使用 &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/linux-unix-bsd-apache-tcpdump-http-packets-sniffing/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&wireshark&/a& 查看文件的详细内容,请输入:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# tcpdump -n -i eth1 -s 0 -w output.txt src or dst port 80
&/code&&/pre&&/div&&h2&&b&15. iotop - I/O 监控&/b&&/h2&&p&&code&iotop&/code& 命令利用 Linux 内核监控 I/O 使用情况,它按进程或线程的顺序显示 I/O 使用情况。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo iotop
&/code&&/pre&&/div&&p&输出示例:&/p&&p&&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-8b03ddcdac_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&464& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic1.zhimg.com/v2-8b03ddcdac_r.jpg&&&figcaption&iotop monitoring linux disk read write IO&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/hardware/linux-iotop-simple-top-like-io-monitor/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux iotop:什么进程在增加硬盘负载&/a&&/p&&h2&&b&16. htop - 交互式的进程查看器&/b&&/h2&&p&&code&htop&/code& 是一款免费并开源的基于 ncurses 的 Linux 进程查看器。它比 &code&top&/code& 命令更简单易用。您无需使用 PID、无需离开 &code&htop&/code& 界面,便可以杀掉进程或调整其调度优先级。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ htop
&/code&&/pre&&/div&&p&输出示例:&/p&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-cff7d1eed7fd1a46a6b4a_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&570& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic4.zhimg.com/v2-cff7d1eed7fd1a46a6b4a_r.jpg&&&figcaption&htop process viewer for Linux&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/centos-redhat-linux-install-htop-command-using-yum/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&CentOS / RHEL:安装 htop——交互式文本模式进程查看器&/a&&/p&&h2&&b&17. atop - 高级版系统与进程监控工具&/b&&/h2&&p&&code&atop&/code& 是一个非常强大的交互式 Linux 系统负载监控器,它从性能的角度显示最关键的硬件资源信息。您可以快速查看 CPU、内存、磁盘和网络性能。它还可以从进程的级别显示哪些进程造成了相关 CPU 和内存的负载。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ atop
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic2.zhimg.com/v2-fda35e7e7edeb4c4839b_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&741& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic2.zhimg.com/v2-fda35e7e7edeb4c4839b_r.jpg&&&figcaption&atop Command Line Tools to Monitor Linux Performance&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/centos-redhat-linux-install-atop-command-using-yum/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&CentOS / RHEL:安装 atop 工具——高级系统和进程监控器&/a&&/p&&h2&&b&18. ac 和 lastcomm&/b&&/h2&&p&您一定需要监控 Linux 服务器上的进程和登录活动吧。&code&psacct&/code& 或 &code&acct&/code& 软件包中包含了多个用于监控进程活动的工具,包括:&/p&&ol&&li&&code&ac&/code& 命令:显示有关用户连接时间的统计信息&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/linux-unix-lastcomm-command-examples-usage-syntax/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&lastcomm 命令&/a&:显示已执行过的命令&/li&&li&&code&accton&/code& 命令:打开或关闭进程账号记录功能&/li&&li&&code&sa&/code& 命令:进程账号记录信息的摘要&/li&&/ol&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/howto-log-user-activity-using-process-accounting.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&如何对 Linux 系统的活动做详细的跟踪记录&/a&&/p&&h2&&b&19. monit - 进程监控器&/b&&/h2&&p&&code&monit&/code& 是一个免费且开源的进程监控软件,它可以自动重启停掉的服务。您也可以使用 Systemd、daemontools 或其他类似工具来达到同样的目的。&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/how-to-install-and-use-monit-on-ubuntudebian-linux-server/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&本教程演示如何在 Debian 或 Ubuntu Linux 上安装和配置 monit 作为进程监控器&/a&。&/p&&h2&&b&20. NetHogs - 找出占用带宽的进程&/b&&/h2&&p&NetHogs 是一个轻便的网络监控工具,它按照进程名称(如 Firefox、wget 等)对带宽进行分组。如果网络流量突然爆发,启动 NetHogs,您将看到哪个进程(PID)导致了带宽激增。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo nethogs
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic3.zhimg.com/v2-ca00b13614_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&156& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic3.zhimg.com/v2-ca00b13614_r.jpg&&&figcaption&nethogs linux monitoring tools open source&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/linux-find-out-what-process-is-using-bandwidth/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux:使用 Nethogs 工具查看每个进程的带宽使用情况&/a&&/p&&h2&&b&21. iftop - 显示主机上网络接口的带宽使用情况&/b&&/h2&&p&&code&iftop&/code& 命令监听指定接口(如 eth0)上的网络通信情况。&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/linux-display-bandwidth-usage-on-network-interface-by-host.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&它显示了一对主机的带宽使用情况&/a&。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ sudo iftop
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-c5fefff53cee_b.jpg& data-size=&normal& data-rawwidth=&596& data-rawheight=&409& data-thumbnail=&https://pic4.zhimg.com/v2-c5fefff53cee_b.jpg& class=&origin_image zh-lightbox-thumb& width=&596& data-original=&https://pic4.zhimg.com/v2-c5fefff53cee_r.jpg&&&figcaption&iftop in action&/figcaption&&/figure&&h2&&b&22. vnstat - 基于控制台的网络流量监控工具&/b&&/h2&&p&&code&vnstat&/code& 是一个简单易用的基于控制台的网络流量监视器,它为指定网络接口保留每小时、每天和每月网络流量日志。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ vnstat
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-44aed4aadb75f_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&364& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic4.zhimg.com/v2-44aed4aadb75f_r.jpg&&&figcaption&vnstat linux network traffic monitor&/figcaption&&/figure&&p&相关链接:&/p&&ul&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/linux-display-bandwidth-usage-on-network-interface-by-host.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&为 ADSL 或专用远程 Linux 服务器保留日常网络流量日志&/a&&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/centos-redhat-fedora-linux-install-vnstat-bandwidth-monitor/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&CentOS / RHEL:安装 vnStat 网络流量监控器以保留日常网络流量日志&/a&&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/centos-redhat-fedora-linux-vnstat-php-webinterface-frontend-config/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&CentOS / RHEL:使用 PHP 网页前端接口查看 Vnstat 图表&/a&&/li&&/ul&&h2&&b&23. nmon - Linux 系统管理员的调优和基准测量工具&/b&&/h2&&p&&code&nmon&/code& 是 Linux 系统管理员用于性能调优的利器,它在命令行显示 CPU、内存、网络、磁盘、文件系统、NFS、消耗资源最多的进程和分区信息。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ nmon
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic1.zhimg.com/v2-af2c7f1c925cce3d5b0738_b.jpg& data-size=&normal& data-rawwidth=&599& data-rawheight=&513& class=&origin_image zh-lightbox-thumb& width=&599& data-original=&https://pic1.zhimg.com/v2-af2c7f1c925cce3d5b0738_r.jpg&&&figcaption&nmon command&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/nmon-performance-analyzer-linux-server-tool/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&安装并使用 nmon 工具来监控 Linux 系统的性能&/a&&/p&&h2&&b&24. glances - 密切关注 Linux 系统&/b&&/h2&&p&&code&glances&/code& 是一款开源的跨平台监控工具。它在小小的屏幕上提供了大量的信息,还可以工作于客户端-服务器模式下。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&$ glances
&/code&&/pre&&/div&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-78e95d6b600aad211000_b.jpg& data-size=&normal& data-rawwidth=&598& data-rawheight=&657& class=&origin_image zh-lightbox-thumb& width=&598& data-original=&https://pic4.zhimg.com/v2-78e95d6b600aad211000_r.jpg&&&figcaption&Glances&/figcaption&&/figure&&p&相关链接:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/linux-install-glances-monitoring-tool/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux:通过 Glances 监控器密切关注您的系统&/a&&/p&&h2&&b&25. strace - 查看系统调用&/b&&/h2&&p&想要跟踪 Linux 系统的调用和信号吗?试试 &code&strace&/code& 命令吧。它对于调试网页服务器和其他服务器问题很有用。了解如何利用其 &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/linux-strace-command-examples.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&追踪进程&/a& 并查看它在做什么。&/p&&h2&&b&26. /proc 文件系统 - 各种内核信息&/b&&/h2&&p&&code&/proc&/code& 文件系统提供了不同硬件设备和 Linux 内核的详细信息。更多详细信息,请参阅 &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/files/linux-kernel/Documentation/filesystems/proc.txt& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux 内核 /proc&/a& 文档。常见的 &code&/proc&/code& 例子:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&# cat /proc/cpuinfo
# cat /proc/meminfo
# cat /proc/zoneinfo
# cat /proc/mounts
&/code&&/pre&&/div&&h2&&b&27. Nagios - Linux 服务器和网络监控&/b&&/h2&&p&&a href=&https://link.zhihu.com/?target=http%3A//www.nagios.org/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Nagios&/a& 是一款普遍使用的开源系统和网络监控软件。您可以轻松地监控所有主机、网络设备和服务,当状态异常和恢复正常时它都会发出警报通知。&a href=&https://link.zhihu.com/?target=http%3A//fannagioscd.sourceforge.net/drupal/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&FAN&/a& 是“全自动 Nagios”的缩写。FAN 的目标是提供包含由 Nagios 社区提供的大多数工具包的 Nagios 安装。FAN 提供了标准 ISO 格式的 CD-Rom 镜像,使安装变得更加容易。除此之外,为了改善 Nagios 的用户体验,发行版还包含了大量的工具。&/p&&h2&&b&28. Cacti - 基于 Web 的 Linux 监控工具&/b&&/h2&&p&Cacti 是一个完整的网络图形化解决方案,旨在充分利用 RRDTool 的数据存储和图形功能。Cacti 提供了快速轮询器、高级图形模板、多种数据采集方法和用户管理功能。这些功能被包装在一个直观易用的界面中,确保可以实现从局域网到拥有数百台设备的复杂网络上的安装。它可以提供有关网络、CPU、内存、登录用户、Apache、DNS 服务器等的数据。了解如何在 CentOS / RHEL 下 &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/fedora-rhel-install-cacti-monitoring-rrd-software/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&安装和配置 Cacti 网络图形化工具&/a&。&/p&&h2&&b&29. KDE 系统监控器 - 实时系统报告和图形化显示&/b&&/h2&&p&KSysguard 是 KDE 桌面的网络化系统监控程序。这个工具可以通过 ssh 会话运行。它提供了许多功能,比如可以监控本地和远程主机的客户端-服务器模式。前端图形界面使用传感器来检索信息。传感器可以返回简单的值或更复杂的信息,如表格。每种类型的信息都有一个或多个显示界面,并被组织成工作表的形式,这些工作表可以分别保存和加载。所以,KSysguard 不仅是一个简单的任务管理器,还是一个控制大型服务器平台的强大工具。&/p&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-efce13e300e68e66d11ede74_b.jpg& data-size=&normal& data-rawwidth=&600& data-rawheight=&462& class=&origin_image zh-lightbox-thumb& width=&600& data-original=&https://pic4.zhimg.com/v2-efce13e300e68e66d11ede74_r.jpg&&&figcaption&图 05:KDE System Guard {图片来源:维基百科}&/figcaption&&/figure&&p&详细用法,请参阅 &a href=&https://link.zhihu.com/?target=https%3A//docs.kde.org/stable5/en/kde-workspace/ksysguard/index.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&KSysguard 手册&/a&。&/p&&h2&&b&30. GNOME 系统监控器&/b&&/h2&&p&系统监控程序能够显示系统基本信息,并监控系统进程、系统资源使用情况和文件系统。您还可以用其修改系统行为。虽然不如 KDE System Guard 强大,但它提供的基本信息对新用户还是有用的:&/p&&ul&&li&显示关于计算机硬件和软件的各种基本信息&/li&&li&Linux 内核版本&/li&&li&GNOME 版本&/li&&li&硬件&/li&&li&安装的内存&/li&&li&处理器和速度&/li&&li&系统状况&/li&&li&可用磁盘空间&/li&&li&进程&/li&&li&内存和交换空间&/li&&li&网络使用情况&/li&&li&文件系统&/li&&li&列出所有挂载的文件系统及其基本信息&/li&&/ul&&p&&br&&/p&&figure&&img src=&https://pic4.zhimg.com/v2-0a4656caf6dab7824240a_b.jpg& data-size=&normal& data-rawwidth=&600& data-rawheight=&451& class=&origin_image zh-lightbox-thumb& width=&600& data-original=&https://pic4.zhimg.com/v2-0a4656caf6dab7824240a_r.jpg&&&figcaption&图 06:Gnome 系统监控程序&/figcaption&&/figure&&h2&&b&福利:其他工具&/b&&/h2&&p&更多工具:&/p&&ul&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/linux-scanning-network-for-open-ports.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&nmap&/a& - 扫描服务器的开放端口&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/tag/lsof-command& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&lsof&/a& - 列出打开的文件和网络连接等&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/debian-ubuntu-install-ntop-network-traffic-monitoring-software/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&ntop&/a& 基于网页的工具 - &code&ntop&/code& 是查看网络使用情况的最佳工具,与 &code&top&/code& 命令之于进程的方式类似,即网络流量监控工具。您可以查看网络状态和 UDP、TCP、DNS、HTTP 等协议的流量分发。&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//github.com/brndnmtthws/conky& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Conky&/a& - X Window 系统下的另一个很好的监控工具。它具有很高的可配置性,能够监视许多系统变量,包括 CPU 状态、内存、交换空间、磁盘存储、温度、进程、网络接口、电池、系统消息和电子邮件等。&/li&&li&&a href=&https://link.zhihu.com/?target=http%3A//gkrellm.srcbox.net/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&GKrellM&/a& - 它可以用来监控 CPU 状态、主内存、硬盘、网络接口、本地和远程邮箱及其他信息。&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/finding-out-a-bad-or-simply-overloaded-network-link-with-linuxunix-oses.html& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&mtr&/a& - &code&mtr&/code& 将 &code&traceroute&/code& 和 &code&ping&/code& 程序的功能结合在一个网络诊断工具中。&/li&&li&&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/faq/how-to-install-and-use-vtop-graphical-terminal-activity-monitor-on-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&vtop&/a& - 图形化活动监控终端&/li&&/ul&&p&如果您有其他推荐的系统监控工具,欢迎在评论区分享。&/p&&h2&&b&关于作者&/b&&/h2&&p&作者 Vivek Gite 是 nixCraft 的创建者,也是经验丰富的系统管理员,以及 Linux 操作系统和 Unix shell 脚本的培训师。他的客户遍布全球,行业涉及 IT、教育、国防航天研究以及非营利部门等。您可以在 &a href=&https://link.zhihu.com/?target=https%3A//twitter.com/nixcraft& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Twitter&/a&、&a href=&https://link.zhihu.com/?target=https%3A//facebook.com/nixcraft& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Facebook&/a& 和 &a href=&https://link.zhihu.com/?target=https%3A//plus.google.com/%2BCybercitiBiz& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Google+&/a& 上关注他。&/p&&hr&&p&via: &a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/tips/top-linux-monitoring-tools.html& class=& external& target=&_blank& rel=&nofollow noreferrer&&&span class=&invisible&&https://www.&/span&&span class=&visible&&cyberciti.biz/tips/top-&/span&&span class=&invisible&&linux-monitoring-tools.html&/span&&span class=&ellipsis&&&/span&&/a&&/p&&p&作者:&a href=&https://link.zhihu.com/?target=https%3A//www.cyberciti.biz/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Vivek Gite&/a& 译者:&a href=&https://link.zhihu.com/?target=https%3A//github.com/jessie-pang& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&jessie-pang&/a& 校对:&a href=&https://link.zhihu.com/?target=https%3A//github.com/wxy& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&wxy&/a&&/p&&p&本文由 &a href=&https://link.zhihu.com/?target=https%3A//github.com/LCTT/TranslateProject& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&LCTT&/a& 原创编译,&a href=&https://link.zhihu.com/?target=https%3A//linux.cn/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Linux中国&/a& 荣誉推出&/p&
您需要监控 Linux 服务器的性能吗?试试用这些内置命令和附加工具吧!大多数 Linux 发行版都附带了大量的监控工具。这些工具提供了获取系统活动的相关指标。您可以使用这些工具来查找性能问题的可能原因。本文提到的是一些基本的命令,用于系统分析和服务器…
&figure&&img src=&https://pic2.zhimg.com/v2-7b2bd4b9cfbd0c380562cf_b.jpg& data-rawwidth=&720& data-rawheight=&340& class=&origin_image zh-lightbox-thumb& width=&720& data-original=&https://pic2.zhimg.com/v2-7b2bd4b9cfbd0c380562cf_r.jpg&&&/figure&&p&今天,我们要讲的是一款有趣的命令行工具,名叫 Pick。它允许用户通过 ncurses(3X) 界面来从一系列选项中进行选择,而且还支持模糊搜索的功能。当你想要选择某个名字中包含非英文字符的目录或文件时,这款工具就很有用了。你根本都无需学习如何输入非英文字符。借助 Pick,你可以很方便地进行搜索、选择,然后浏览该文件或进入该目录。你甚至无需输入任何字符来过滤文件/目录。这很适合那些有大量目录和文件的人来用。&/p&&h2&&b&安装 Pick&/b&&/h2&&p&对 Arch Linux 及其衍生品来说,Pick 放在 &a href=&https://link.zhihu.com/?target=https%3A//aur.archlinux.org/packages/pick/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&AUR&/a& 中。因此 Arch 用户可以使用类似 &a href=&https://link.zhihu.com/?target=https%3A//www.ostechnix.com/install-pacaur-arch-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Pacaur&/a&,&a href=&https://link.zhihu.com/?target=https%3A//www.ostechnix.com/install-packer-arch-linux-2/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Packer&/a&,以及 &a href=&https://link.zhihu.com/?target=https%3A//www.ostechnix.com/install-yaourt-arch-linux/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&Yaourt&/a& 等 AUR 辅助工具来安装它。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&pacaur -S pick
&/code&&/pre&&/div&&p&或者,&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&packer -S pick
&/code&&/pre&&/div&&p&或者,&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&yaourt -S pick
&/code&&/pre&&/div&&p&Debian,Ubuntu,Linux Mint 用户则可以通过运行下面命令来安装 Pick。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&sudo apt-get install pick
&/code&&/pre&&/div&&p&其他的发行版则可以从&a href=&https://link.zhihu.com/?target=https%3A//github.com/calleerlandsson/pick/releases/& class=& wrap external& target=&_blank& rel=&nofollow noreferrer&&这里&/a&下载最新的安装包,然后按照下面的步骤来安装。在写本指南时,其最新版为 1.9.0。&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&wget https://github.com/calleerlandsson/pick/releases/download/v1.9.0/pick-1.9.0.tar.gz
tar -zxvf pick-1.9.0.tar.gz
cd pick-1.9.0/
&/code&&/pre&&/div&&p&使用下面命令进行配置:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&./configure
&/code&&/pre&&/div&&p&最后,构建并安装 Pick:&/p&&div class=&highlight&&&pre&&code class=&language-text&&&span&&/span&m

我要回帖

更多关于 linux常用命令 的文章

 

随机推荐