安装psacct或acct程序包

监视Linux用户活动

我认为,对每个想密切监视其服务器/系统上用户活动的Linux/Unix系统管理员来说,psacct或acct是优秀的、必需的应用程序之一。

psacct或acct程序包提供了用于监视进程活动的几项功能。

  • ac命令输出用户登录/退出(连接时间,数小时)的统计信息。
  • lastcomm命令输出用户之前执行的命令的信息。
  • accton命令用于开启/关闭进程会计机制(process accounting)。
  • sa命令用于概述之前执行的命令的信息。
  • last和lastb这两个命令显示了最近登录用户的列表。

安装psacct或acct程序包

psacct或acct都是类似的程序包,两者之间没有太大的区别,但是psacct程序包只适用于基于rpm的发行版,比如RHEL、CentOS和Fedora;而acct程序包适用于Ubuntu、Debian和Linux Mint等发行版。

想在基于rpm的发行版下安装psacct程序包,请运行下列yum命令。

# yum install psacct

想在Ubuntu / Debian / Linux Mint下安装acct程序包,请使用apt-get命令。

$ sudo apt-get install acct

或者

# apt-get install acctStarting psacct or acct service

默认情况下,psacct服务处于禁用模式,你需要在RHEL/CentOS/Fedora系统下手动开启该服务。请使用下列命令,检查服务状态。

# /etc/init.d/psacct status
Process accounting is disabled.

你看到状态显示为处于禁用状态,不妨使用下列两个命令手动开启该服务。这两个命令将创建一个/var/account/pacct文件,并开启服务。

# chkconfig psacct on
# /etc/init.d/psacct start
Starting process accounting: [ OK ]

开启服务后,再次检查状态,你会看到状态已被启用,如下所示。

# /etc/init.d/psacct status
Process accounting is enabled.

在Ubuntu、Debian和Mint系统下,服务已自动启动,你不需要再次启动服务了。

显示用户连接时间的统计信息

没有指定参数的ac命令会基于来自当前wtmp文件的用户登录/退出,显示连接时间(小时)的总统计信息。

# ac
total     1814.03

显示每天的用户统计信息

使用ac -d这个命令将输出每天的总登录时间(小时)。

# ac -d
Sep 17  total        5.23
Sep 18  total       15.20
Sep 24  total        3.21
Sep 25  total        2.27
Sep 26  total        2.64
Sep 27  total        6.19
Oct  1  total        6.41
Oct  3  total        2.42
Oct  4  total        2.52
Oct  5  total        6.11
Oct  8  total       12.98
Oct  9  total       22.65
Oct 11  total       16.18

显示每个用户的时间总数

使用ac -p这个命令将显示每个用户的总登录时间(小时)。

# ac -p
root                              1645.18
tecmint                            168.96
total     1814.14

显示单个用户时间

想得到tecmint这个用户的总登录统计时间(小时),请使用下列命令。

# ac tecmint
total      168.96

显示用户每天的登录时间

下列命令将输出tecmint这个用户的每天总登录时间(小时)。

# ac -d tecmint
Oct 11  total        8.01
Oct 12  total       24.00
Oct 15  total       70.50
Oct 16  total       23.57
Oct 17  total       24.00
Oct 18  total       18.70
Nov 20  total        0.18

输出所有的帐户活动信息

sa这个命令用于输出诸用户执行的命令的概要情况。

# sa
2       9.86re       0.00cp     2466k   sshd*
8       1.05re       0.00cp     1064k   man
2      10.08re       0.00cp     2562k   sshd
12       0.00re       0.00cp     1298k   psacct
2       0.00re       0.00cp     1575k   troff
14       0.00re       0.00cp      503k   ac
10       0.00re       0.00cp     1264k   psacct*
10       0.00re       0.00cp      466k   consoletype
9       0.00re       0.00cp      509k   sa
8       0.02re       0.00cp      769k   udisks-helper-a
6       0.00re       0.00cp     1057k   touch
6       0.00re       0.00cp      592k   gzip
6       0.00re       0.00cp      465k   accton
4       1.05re       0.00cp     1264k   sh*
4       0.00re       0.00cp     1264k   nroff*
2       1.05re       0.00cp     1264k   sh
2       1.05re       0.00cp     1120k   less
2       0.00re       0.00cp     1346k   groff
2       0.00re       0.00cp     1383k   grotty
2       0.00re       0.00cp     1053k   mktemp
2       0.00re       0.00cp     1030k   iconv
2       0.00re       0.00cp     1023k   rm
2       0.00re       0.00cp     1020k   cat
2       0.00re       0.00cp     1018k   locale
2       0.00re       0.00cp      802k   gtbl

其中:

  • 9.86re是"真实时间",以挂钟分钟为单位。
  • 0.01cp是系统/用户时间(以处理器分钟为单位)之和。
  • 2466k是处理器时间平均核心使用,也就是1k单位。
  • sshd命令名称

输出单个的用户信息

想获得单个用户的信息,请使用-u这个选项。

# sa -u
root       0.00 cpu      465k mem accton
root       0.00 cpu     1057k mem touch
root       0.00 cpu     1298k mem psacct
root       0.00 cpu      466k mem consoletype
root       0.00 cpu     1264k mem psacct           *
root       0.00 cpu     1298k mem psacct
root       0.00 cpu      466k mem consoletype
root       0.00 cpu     1264k mem psacct           *
root       0.00 cpu     1298k mem psacct
root       0.00 cpu      466k mem consoletype
root       0.00 cpu     1264k mem psacct           *
root       0.00 cpu      465k mem accton
root       0.00 cpu     1057k mem touch

输出进程数量

这个命令输出进程总数和处理器分钟总数。如果你看到这些数字不断增大,那么就要查看系统,分析一下出现了什么状况。

# sa -m
sshd                                    2       9.86re       0.00cp     2466k
root                                  127      14.29re       0.00cp      909k

输出按百分比排序

sa -c这个命令显示了用户的最高百分比。

# sa -c
132  100.00%      24.16re  100.00%       0.01cp  100.00%      923k
2    1.52%       9.86re   40.83%       0.00cp   53.33%     2466k   sshd*
8    6.06%       1.05re    4.34%       0.00cp   20.00%     1064k   man
2    1.52%      10.08re   41.73%       0.00cp   13.33%     2562k   sshd
12    9.09%       0.00re    0.01%       0.00cp    6.67%     1298k   psacct
2    1.52%       0.00re    0.00%       0.00cp    6.67%     1575k   troff
18   13.64%       0.00re    0.00%       0.00cp    0.00%      509k   sa
14   10.61%       0.00re    0.00%       0.00cp    0.00%      503k   ac
10    7.58%       0.00re    0.00%       0.00cp    0.00%     1264k   psacct*
10    7.58%       0.00re    0.00%       0.00cp    0.00%      466k   consoletype
8    6.06%       0.02re    0.07%       0.00cp    0.00%      769k   udisks-helper-a
6    4.55%       0.00re    0.00%       0.00cp    0.00%     1057k   touch
6    4.55%       0.00re    0.00%       0.00cp    0.00%      592k   gzip
6    4.55%       0.00re    0.00%       0.00cp    0.00%      465k   accton
4    3.03%       1.05re    4.34%       0.00cp    0.00%     1264k   sh*
4    3.03%       0.00re    0.00%       0.00cp    0.00%     1264k   nroff*
2    1.52%       1.05re    4.34%       0.00cp    0.00%     1264k   sh
2    1.52%       1.05re    4.34%       0.00cp    0.00%     1120k   less
2    1.52%       0.00re    0.00%       0.00cp    0.00%     1346k   groff
2    1.52%       0.00re    0.00%       0.00cp    0.00%     1383k   grotty
2    1.52%       0.00re    0.00%       0.00cp    0.00%     1053k   mktempList

用户最近执行的命令

latcomm这个命令用于搜索和显示之前执行的用户命令信息。你还可以搜索单个用户名称的命令。比如说,我们看到了用户(tecmint)执行的命令:

# lastcomm tecmint
su                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
ls                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
ls                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
ls                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
bash               F    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
id                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
grep                    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
grep                    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
bash               F    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
dircolors                tecmint  pts/0      0.00 secs Wed Feb 13 15:56
bash               F    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
tput                    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
tty                     tecmint  pts/0      0.00 secs Wed Feb 13 15:56
bash               F    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
id                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
bash               F    tecmint  pts/0      0.00 secs Wed Feb 13 15:56
id                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56

搜索命令日志

在lastcomm这个命令的帮助下,你能够查看每个命令的单独使用情况。

# lastcomm ls
ls                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
ls                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56
ls                      tecmint  pts/0      0.00 secs Wed Feb 13 15:56

原文链接:http://os.51cto.com/art/201303/385002.htm
时间: 2024-07-29 23:45:59

安装psacct或acct程序包的相关文章

服务器不重启安装Asp.net Core 程序包

遇到服务器不能重启但是需要安装asp.net core 下载dotnet-hosting安装即可,地址:https://dotnet.microsoft.com/download/dotnet-core 安装后打开IIS中打开模块,如果其中有下图已经安装成功. 原文地址:https://www.cnblogs.com/wangjunguang/p/11165523.html

如何安装所有的R程序包

# get names of installed packages packs <- installed.packages() exc <- names(packs[,'Package']) # get available package names av <- names(available.packages()[,1]) # create loooong string ins <- av[!av %in% exc] install.packages(ins)

解决Chrome插件安装时出现的“程序包无效”问题亲测可用

原文地址:https://www.cnblogs.com/by-DSL/p/12560678.html

谢烟客---------Linux之程序包管理yum使用和编译安装

yum命令及仓库创建与配置 YUM 原理 安装.卸载.查询.升级.检查,本地缓存.重装.降级.历史.获取帮助 仓库 变量.事务.URL.开销.镜像.元数据存储方式及组成 createrepo作用.命令.lftp命令 编译安装  目的 原理 开发工具及开发环境 编译后的处理 获取程序包源代码的途径 YUM Redhat二次发行版 Yellow Dog Linux,上使用的yum(Yellowdog Update Modifier),由yellow dog 研发 yum命令的工作原理 1.接收用户命

Linux程序包管理及yum安装管理

Linux程序包管理: API:ApplicationProgramming Interface   应用编程接口 POSIX:Portable OS    遵循本协议的程序均可在不同系统间移植 程序编写完成后,执行所要经过的处理步骤: 程序源代码 --> 预处理 --> 编译 --> 汇编 --> 链接 静态编译: 共享编译:直接调用.so共享对象实现 ABI:ApplicationBinary Interface  应用二进制接口 Windows与Linux所支持的可执行二进制

博客9:程序包的管理,以及软件的安装和管理

1.对于二进制应用程序的认识  (1)组成部分:       二进制文件,库文件,配置文件,帮助文件(前两项是由源代码组成的)  (2)程序包管理器:       debian:deb,dpt       redhat:rpm,rpm  (3)源代码的命名方式       name-VERSION.tar.gz       其中VERSION:major.minor.release 2.查看二进制程序所依赖的库文件   # ldd /PATH/TO/BINARY_FILE  管理以及查看本机装载

linux程序包管理rpm,yum和编译安装以及冒泡排序练习

linux程序包管理: API:Application Programming Interface POSIX:Portable OS 程序源代码--> 预处理--> 编译--> 汇编--> 链接 静态编译: 共享编译:.so ABI:Application Binary Interface Windows与Linux不兼容 ELF(Executable and Linkable Format) PE(Portable Executable) 库级别的虚拟化: Linux: WIN

Linux程序包管理之yum仓库、源码编译安装

CentOS:yum,dnf URL:ftp://172.16.0.1/pub yum是C/S架构,是rpm的前端工具,依赖于rpm存在的: 1.本地要有yun程序: 2.本地要有配置文件(配置远程服务器yum仓库或本地服务器yum仓库): 3.要有存在的文件服务器(程序包仓库即yum仓库).(也可以在本地配置服务器yum仓库): yum支持的服务器有两种:一种是ftp服务器,第二种是http服务器: yum工作简述: yum是客户端,也认为是自我独立管理的组件,需要联系远程的仓库,从仓库中下载

rpm和yum的使用,程序包编译安装以及编译apache过程中出现的问题

一.rpm包管理 用法: rpm [选项...] 查询/验证软件包选项: -a, --all                        查询/验证所有软件包 -f, --file                       查询/验证文件属于的软件包 -g, --group                      查询/验证组中的软件包 -p, --package                    查询/验证一个软件包 --pkgid