一、需求 公司linux服务器较多,想一键快速查看其系统信息,检查系统各项指标及参数,故使用系统快速检查脚本,输出系统信息到脚本运行的logs目录下。此脚本针对centos6以及7版本能查看服务器的 CPU信息、系统当前内存状况、系统网络信息、系统磁盘信息、系统信息、当前运行的服务监听端口等、系统登录用户、定时任务、Top10进程占用资源情况等
二、脚本1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 #!/bin/bash # auth:kaliarch # func:sys info check # version:v1.0 # sys:centos6.x/7.x [ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1 sysversion=$(rpm -q centos-release|cut -d- -f3) line="-------------------------------------------------" [ -d logs ] || mkdir logs sys_check_file="logs/$(ip a show dev ens192|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')-`date +%Y%m%d`.txt" # 获取系统cpu信息 function get_cpu_info() { Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l) Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l) CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}') CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq) CPU_Arch=$(uname -m) cat <<EOF | column -t CPU信息: 物理CPU个数: $Physical_CPUs 逻辑CPU个数: $Virt_CPUs 每CPU核心数: $CPU_Kernels CPU型号: $CPU_Type CPU架构: $CPU_Arch EOF } # 获取系统内存信息 function get_mem_info() { check_mem=$(free -m) MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB let MemUsed=MemTotal-MemFree MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}") report_MemTotal="$((MemTotal/1024))""MB" #内存总容量(MB) report_MemFree="$((MemFree/1024))""MB" #内存剩余(MB) report_MemUsedPercent="$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")""%" #内存使用率% cat <<EOF 内存信息: ${check_mem} EOF } # 获取系统网络信息 function get_net_info() { pri_ipadd=$(ip a show dev ens192|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}') pub_ipadd=$(curl ifconfig.me -s) gateway=$(ip route | grep default | awk '{print $3}') mac_info=$(ip link| egrep -v "lo"|grep link|awk '{print $2}') dns_config=$(egrep -v "^$|^#" /etc/resolv.conf) route_info=$(route -n) cat <<EOF | column -t IP信息: 系统公网地址: ${pub_ipadd} 系统私网地址: ${pri_ipadd} 网关地址: ${gateway} MAC地址: ${mac_info} 路由信息: ${route_info} DNS 信息: ${dns_config} EOF } # 获取系统磁盘信息 function get_disk_info() { disk_info=$(fdisk -l|grep "Disk /dev"|cut -d, -f1) disk_use=$(df -hTP|awk '$2!="tmpfs"{print}') disk_inode=$(df -hiP|awk '$1!="tmpfs"{print}') cat <<EOF 磁盘信息: ${disk_info} 磁盘使用: ${disk_use} inode信息: ${disk_inode} EOF } # 获取系统信息 function get_systatus_info() { sys_os=$(uname -o) sys_release=$(cat /etc/redhat-release) sys_kernel=$(uname -r) sys_hostname=$(hostname) sys_selinux=$(getenforce) sys_lang=$(echo $LANG) sys_lastreboot=$(who -b | awk '{print $3,$4}') sys_runtime=$(uptime |awk '{print $3,$4}'|cut -d, -f1) sys_time=$(date) sys_load=$(uptime |cut -d: -f5) cat <<EOF | column -t 系统信息: 系统: ${sys_os} 发行版本: ${sys_release} 系统内核: ${sys_kernel} 主机名: ${sys_hostname} selinux状态: ${sys_selinux} 系统语言: ${sys_lang} 系统当前时间: ${sys_time} 系统最后重启时间: ${sys_lastreboot} 系统运行时间: ${sys_runtime} 系统负载: ${sys_load} EOF } # 获取服务信息 function get_service_info() { port_listen=$(netstat -lntup|grep -v "Active Internet") kernel_config=$(sysctl -p 2>/dev/null) if [ ${sysversion} -gt 6 ];then service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled") run_service=$(systemctl list-units --type=service --state=running |grep ".service") else service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t) run_service=$(/sbin/service --status-all|grep -E "running") fi cat <<EOF 服务启动配置: ${service_config} ${line} 运行的服务: ${run_service} ${line} 监听端口: ${port_listen} ${line} 内核参考配置: ${kernel_config} EOF } function get_sys_user() { login_user=$(awk -F: '{if ($NF=="/bin/bash") print $0}' /etc/passwd) ssh_config=$(egrep -v "^#|^$" /etc/ssh/sshd_config) sudo_config=$(egrep -v "^#|^$" /etc/sudoers |grep -v "^Defaults") host_config=$(egrep -v "^#|^$" /etc/hosts) crond_config=$(for cronuser in /var/spool/cron/* ;do ls ${cronuser} 2>/dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done) cat <<EOF 系统登录用户: ${login_user} ${line} ssh 配置信息: ${ssh_config} ${line} sudo 配置用户: ${sudo_config} ${line} 定时任务配置: ${crond_config} ${line} hosts 信息: ${host_config} EOF } function process_top_info() { top_title=$(top -b n1|head -7|tail -1) cpu_top10=$(top b -n1 | head -17 | tail -10) mem_top10=$(top -b n1|head -17|tail -10|sort -k10 -r) cat <<EOF CPU占用top10: ${top_title} ${cpu_top10} 内存占用top10: ${top_title} ${mem_top10} EOF } function sys_check() { get_cpu_info echo ${line} get_mem_info echo ${line} get_net_info echo ${line} get_disk_info echo ${line} get_systatus_info echo ${line} get_service_info echo ${line} get_sys_user echo ${line} process_top_info } sys_check > ${sys_check_file}
1 2 3 chmod a+x sys_info.sh ./sys_info.sh
执行情况
执行的日志结果1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 [root@localhost logs]# cat 192.168.4.188-20190802.txt CPU信息: 物理CPU个数: 2 逻辑CPU个数: 2 每CPU核心数: 1 CPU型号: Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz CPU架构: x86_64 ------------------------------------------------- 内存信息: total used free shared buff/cache available Mem: 2847 593 239 137 2014 1880 Swap: 10239 0 10239 ------------------------------------------------- IP信息: 系统公网地址: 系统私网地址: 192.168.4.188 网关地址: 192.168.0.1 MAC地址: 00:50:56:b0:b2:45 52:54:00:75:22:45 52:54:00:75:22:45 路由信息: Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 ens192 192.168.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens192 192.168.4.0 0.0.0.0 255.255.255.0 U 100 0 0 ens192 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 DNS 信息: nameserver 8.8.8.8 ------------------------------------------------- 磁盘信息: Disk /dev/sda: 107.4 GB 磁盘使用: Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 xfs 90G 7.3G 83G 9% / devtmpfs devtmpfs 1.4G 0 1.4G 0% /dev inode信息: Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 45M 126K 45M 1% / devtmpfs 353K 339 353K 1% /dev ------------------------------------------------- 系统信息: 系统: GNU/Linux 发行版本: CentOS Linux release 7.4.1708 (Core) 系统内核: 3.10.0-693.el7.x86_64 主机名: localhost.localdomain selinux状态: Disabled 系统语言: en_US.UTF-8 系统当前时间: Fri Aug 2 10:37:22 CST 2019 系统最后重启时间: 2019-06-07 06:01 系统运行时间: 56 days 系统负载: 2.45, 2.33, 2.35 ------------------------------------------------- 服务启动配置: abrt-ccpp.service enabled abrt-oops.service enabled abrt-vmcore.service enabled abrt-xorg.service enabled abrtd.service enabled accounts-daemon.service enabled atd.service enabled auditd.service enabled autovt@.service enabled avahi-daemon.service enabled bluetooth.service enabled chronyd.service enabled crond.service enabled cups.service enabled dbus-org.bluez.service enabled dbus-org.freedesktop.Avahi.service enabled dbus-org.freedesktop.ModemManager1.service enabled dbus-org.freedesktop.NetworkManager.service enabled dbus-org.freedesktop.nm-dispatcher.service enabled display-manager.service enabled dmraid-activation.service enabled gdm.service enabled getty@.service enabled grafana-server.service enabled irqbalance.service enabled iscsi.service enabled kdump.service enabled ksm.service enabled ksmtuned.service enabled libstoragemgmt.service enabled libvirtd.service enabled lvm2-monitor.service enabled mcelog.service enabled mdmonitor.service enabled microcode.service enabled ModemManager.service enabled multipathd.service enabled mysqld.service enabled NetworkManager-dispatcher.service enabled NetworkManager.service enabled postfix.service enabled qemu-guest-agent.service enabled rngd.service enabled rsyslog.service enabled rtkit-daemon.service enabled smartd.service enabled snmpd.service enabled spice-vdagentd.service enabled sshd.service enabled sysstat.service enabled systemd-readahead-collect.service enabled systemd-readahead-drop.service enabled systemd-readahead-replay.service enabled tuned.service enabled vgauthd.service enabled vmtoolsd.service enabled zabbix-agent.service enabled ------------------------------------------------- 运行的服务: abrt-oops.service loaded active running ABRT kernel log watcher abrt-xorg.service loaded active running ABRT Xorg log watcher abrtd.service loaded active running ABRT Automated Bug Reporting Tool accounts-daemon.service loaded active running Accounts Service alsa-state.service loaded active running Manage Sound Card State (restore and store) atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack chronyd.service loaded active running NTP client/server colord.service loaded active running Manage, Install and Generate Color Profiles crond.service loaded active running Command Scheduler cups.service loaded active running CUPS Printing Service dbus.service loaded active running D-Bus System Message Bus gdm.service loaded active running GNOME Display Manager grafana-server.service loaded active running Grafana instance gssproxy.service loaded active running GSSAPI Proxy Daemon irqbalance.service loaded active running irqbalance daemon ksmtuned.service loaded active running Kernel Samepage Merging (KSM) Tuning Daemon libstoragemgmt.service loaded active running libstoragemgmt plug-in server daemon libvirtd.service loaded active running Virtualization daemon lvm2-lvmetad.service loaded active running LVM2 metadata daemon mcelog.service loaded active running Machine Check Exception Logging Daemon ModemManager.service loaded active running Modem Manager mysqld.service loaded active running MySQL Server NetworkManager.service loaded active running Network Manager packagekit.service loaded active running PackageKit Daemon polkit.service loaded active running Authorization Manager postfix.service loaded active running Postfix Mail Transport Agent rngd.service loaded active running Hardware RNG Entropy Gatherer Daemon rsyslog.service loaded active running System Logging Service rtkit-daemon.service loaded active running RealtimeKit Scheduling Policy Service smartd.service loaded active running Self Monitoring and Reporting Technology (SMART) Daemon snmpd.service loaded active running Simple Network Management Protocol (SNMP) Daemon. sshd.service loaded active running OpenSSH server daemon systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running Login Service systemd-udevd.service loaded active running udev Kernel Device Manager tuned.service loaded active running Dynamic System Tuning Daemon upower.service loaded active running Daemon for power management vgauthd.service loaded active running VGAuth Service for open-vm-tools vmtoolsd.service loaded active running Service for virtual machines hosted on VMware wpa_supplicant.service loaded active running WPA Supplicant daemon zabbix-agent.service loaded active running Zabbix Agent ------------------------------------------------- 监听端口: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12607/nginx: master tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1348/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 944/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 943/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1199/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 999/zabbix_agentd tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 942/snmpd tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 12607/nginx: master tcp6 0 0 :::22 :::* LISTEN 944/sshd tcp6 0 0 ::1:631 :::* LISTEN 943/cupsd tcp6 0 0 :::3000 :::* LISTEN 952/grafana-server tcp6 0 0 ::1:25 :::* LISTEN 1199/master tcp6 0 0 :::10050 :::* LISTEN 999/zabbix_agentd tcp6 0 0 :::3306 :::* LISTEN 1430/mysqld udp 0 0 0.0.0.0:48103 0.0.0.0:* 671/avahi-daemon: r udp 0 0 0.0.0.0:5353 0.0.0.0:* 671/avahi-daemon: r udp 0 0 192.168.122.1:53 0.0.0.0:* 1348/dnsmasq udp 0 0 0.0.0.0:67 0.0.0.0:* 1348/dnsmasq udp 0 0 0.0.0.0:161 0.0.0.0:* 942/snmpd udp 0 0 127.0.0.1:323 0.0.0.0:* 649/chronyd udp6 0 0 ::1:323 :::* 649/chronyd ------------------------------------------------- 内核参考配置: ------------------------------------------------- 系统登录用户: root:x:0:0:root:/root:/bin/bash yang:x:1000:1000:yang:/home/yang:/bin/bash mysql:x:989:1001::/home/mysql:/bin/bash ------------------------------------------------- ssh 配置信息: HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key SyslogFacility AUTHPRIV AuthorizedKeysFile .ssh/authorized_keys PasswordAuthentication yes ChallengeResponseAuthentication no GSSAPIAuthentication yes GSSAPICleanupCredentials no UsePAM yes X11Forwarding yes AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS Subsystem sftp /usr/libexec/openssh/sftp-server ------------------------------------------------- sudo 配置用户: root ALL=(ALL) ALL %wheel ALL=(ALL) ALL ------------------------------------------------- 定时任务配置: root * * * * * /var/tmp/ /.p/update >/dev/null 2>&1 * * * * * /var/opt/.crond/./crond ------------------------------------------------- hosts 信息: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ------------------------------------------------- CPU占用top10: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30541 root 20 0 55744 8448 0 S 172.2 0.3 14518:01 crond 1 root 20 0 125540 4076 2508 S 0.0 0.1 7:18.30 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.85 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:10.40 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root rt 0 0 0 0 S 0.0 0.0 0:01.45 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 R 0.0 0.0 3:08.48 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 0:13.94 watchdog/0 11 root rt 0 0 0 0 S 0.0 0.0 0:09.76 watchdog/1 内存占用top10: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30541 root 20 0 55744 8448 0 S 200.0 0.3 14518:02 crond 1 root 20 0 125540 4076 2508 S 0.0 0.1 7:18.30 systemd 9 root 20 0 0 0 0 R 0.0 0.0 3:08.48 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 0:13.94 watchdog/0 3 root 20 0 0 0 0 S 0.0 0.0 0:10.40 ksoftirqd/0 11 root rt 0 0 0 0 S 0.0 0.0 0:09.76 watchdog/1 7 root rt 0 0 0 0 S 0.0 0.0 0:01.45 migration/0 2 root 20 0 0 0 0 S 0.0 0.0 0:00.85 kthreadd 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H [root@localhost logs]# [root@localhost logs]# lll bash: lll: command not found... You have mail in /var/spool/mail/root [root@localhost logs]# ll total 32 -rw-r--r-- 1 root root 14147 Aug 2 10:37 192.168.4.188-20190802.txt -rw-r--r-- 1 root root 14147 Aug 2 10:35 -20190802.txt [root@localhost logs]# cat 192.168.4.188-20190802.txt CPU信息: 物理CPU个数: 2 逻辑CPU个数: 2 每CPU核心数: 1 CPU型号: Intel(R) Xeon(R) CPU E5-2683 v4 @ 2.10GHz CPU架构: x86_64 ------------------------------------------------- 内存信息: total used free shared buff/cache available Mem: 2847 593 239 137 2014 1880 Swap: 10239 0 10239 ------------------------------------------------- IP信息: 系统公网地址: 系统私网地址: 192.168.4.188 网关地址: 192.168.0.1 MAC地址: 00:50:56:b0:b2:45 52:54:00:75:22:45 52:54:00:75:22:45 路由信息: Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 ens192 192.168.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens192 192.168.4.0 0.0.0.0 255.255.255.0 U 100 0 0 ens192 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 DNS 信息: nameserver 8.8.8.8 ------------------------------------------------- 磁盘信息: Disk /dev/sda: 107.4 GB 磁盘使用: Filesystem Type Size Used Avail Use% Mounted on /dev/sda2 xfs 90G 7.3G 83G 9% / devtmpfs devtmpfs 1.4G 0 1.4G 0% /dev inode信息: Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 45M 126K 45M 1% / devtmpfs 353K 339 353K 1% /dev ------------------------------------------------- 系统信息: 系统: GNU/Linux 发行版本: CentOS Linux release 7.4.1708 (Core) 系统内核: 3.10.0-693.el7.x86_64 主机名: localhost.localdomain selinux状态: Disabled 系统语言: en_US.UTF-8 系统当前时间: Fri Aug 2 10:37:22 CST 2019 系统最后重启时间: 2019-06-07 06:01 系统运行时间: 56 days 系统负载: 2.45, 2.33, 2.35 ------------------------------------------------- 服务启动配置: abrt-ccpp.service enabled abrt-oops.service enabled abrt-vmcore.service enabled abrt-xorg.service enabled abrtd.service enabled accounts-daemon.service enabled atd.service enabled auditd.service enabled autovt@.service enabled avahi-daemon.service enabled bluetooth.service enabled chronyd.service enabled crond.service enabled cups.service enabled dbus-org.bluez.service enabled dbus-org.freedesktop.Avahi.service enabled dbus-org.freedesktop.ModemManager1.service enabled dbus-org.freedesktop.NetworkManager.service enabled dbus-org.freedesktop.nm-dispatcher.service enabled display-manager.service enabled dmraid-activation.service enabled gdm.service enabled getty@.service enabled grafana-server.service enabled irqbalance.service enabled iscsi.service enabled kdump.service enabled ksm.service enabled ksmtuned.service enabled libstoragemgmt.service enabled libvirtd.service enabled lvm2-monitor.service enabled mcelog.service enabled mdmonitor.service enabled microcode.service enabled ModemManager.service enabled multipathd.service enabled mysqld.service enabled NetworkManager-dispatcher.service enabled NetworkManager.service enabled postfix.service enabled qemu-guest-agent.service enabled rngd.service enabled rsyslog.service enabled rtkit-daemon.service enabled smartd.service enabled snmpd.service enabled spice-vdagentd.service enabled sshd.service enabled sysstat.service enabled systemd-readahead-collect.service enabled systemd-readahead-drop.service enabled systemd-readahead-replay.service enabled tuned.service enabled vgauthd.service enabled vmtoolsd.service enabled zabbix-agent.service enabled ------------------------------------------------- 运行的服务: abrt-oops.service loaded active running ABRT kernel log watcher abrt-xorg.service loaded active running ABRT Xorg log watcher abrtd.service loaded active running ABRT Automated Bug Reporting Tool accounts-daemon.service loaded active running Accounts Service alsa-state.service loaded active running Manage Sound Card State (restore and store) atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack chronyd.service loaded active running NTP client/server colord.service loaded active running Manage, Install and Generate Color Profiles crond.service loaded active running Command Scheduler cups.service loaded active running CUPS Printing Service dbus.service loaded active running D-Bus System Message Bus gdm.service loaded active running GNOME Display Manager grafana-server.service loaded active running Grafana instance gssproxy.service loaded active running GSSAPI Proxy Daemon irqbalance.service loaded active running irqbalance daemon ksmtuned.service loaded active running Kernel Samepage Merging (KSM) Tuning Daemon libstoragemgmt.service loaded active running libstoragemgmt plug-in server daemon libvirtd.service loaded active running Virtualization daemon lvm2-lvmetad.service loaded active running LVM2 metadata daemon mcelog.service loaded active running Machine Check Exception Logging Daemon ModemManager.service loaded active running Modem Manager mysqld.service loaded active running MySQL Server NetworkManager.service loaded active running Network Manager packagekit.service loaded active running PackageKit Daemon polkit.service loaded active running Authorization Manager postfix.service loaded active running Postfix Mail Transport Agent rngd.service loaded active running Hardware RNG Entropy Gatherer Daemon rsyslog.service loaded active running System Logging Service rtkit-daemon.service loaded active running RealtimeKit Scheduling Policy Service smartd.service loaded active running Self Monitoring and Reporting Technology (SMART) Daemon snmpd.service loaded active running Simple Network Management Protocol (SNMP) Daemon. sshd.service loaded active running OpenSSH server daemon systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running Login Service systemd-udevd.service loaded active running udev Kernel Device Manager tuned.service loaded active running Dynamic System Tuning Daemon upower.service loaded active running Daemon for power management vgauthd.service loaded active running VGAuth Service for open-vm-tools vmtoolsd.service loaded active running Service for virtual machines hosted on VMware wpa_supplicant.service loaded active running WPA Supplicant daemon zabbix-agent.service loaded active running Zabbix Agent ------------------------------------------------- 监听端口: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12607/nginx: master tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1348/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 944/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 943/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1199/master tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 999/zabbix_agentd tcp 0 0 127.0.0.1:199 0.0.0.0:* LISTEN 942/snmpd tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::80 :::* LISTEN 12607/nginx: master tcp6 0 0 :::22 :::* LISTEN 944/sshd tcp6 0 0 ::1:631 :::* LISTEN 943/cupsd tcp6 0 0 :::3000 :::* LISTEN 952/grafana-server tcp6 0 0 ::1:25 :::* LISTEN 1199/master tcp6 0 0 :::10050 :::* LISTEN 999/zabbix_agentd tcp6 0 0 :::3306 :::* LISTEN 1430/mysqld udp 0 0 0.0.0.0:48103 0.0.0.0:* 671/avahi-daemon: r udp 0 0 0.0.0.0:5353 0.0.0.0:* 671/avahi-daemon: r udp 0 0 192.168.122.1:53 0.0.0.0:* 1348/dnsmasq udp 0 0 0.0.0.0:67 0.0.0.0:* 1348/dnsmasq udp 0 0 0.0.0.0:161 0.0.0.0:* 942/snmpd udp 0 0 127.0.0.1:323 0.0.0.0:* 649/chronyd udp6 0 0 ::1:323 :::* 649/chronyd ------------------------------------------------- 内核参考配置: ------------------------------------------------- 系统登录用户: root:x:0:0:root:/root:/bin/bash yang:x:1000:1000:yang:/home/yang:/bin/bash mysql:x:989:1001::/home/mysql:/bin/bash ------------------------------------------------- ssh 配置信息: HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key SyslogFacility AUTHPRIV AuthorizedKeysFile .ssh/authorized_keys PasswordAuthentication yes ChallengeResponseAuthentication no GSSAPIAuthentication yes GSSAPICleanupCredentials no UsePAM yes X11Forwarding yes AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE AcceptEnv XMODIFIERS Subsystem sftp /usr/libexec/openssh/sftp-server ------------------------------------------------- sudo 配置用户: root ALL=(ALL) ALL %wheel ALL=(ALL) ALL ------------------------------------------------- 定时任务配置: root * * * * * /var/tmp/ /.p/update >/dev/null 2>&1 * * * * * /var/opt/.crond/./crond ------------------------------------------------- hosts 信息: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ------------------------------------------------- CPU占用top10: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30541 root 20 0 55744 8448 0 S 172.2 0.3 14518:01 crond 1 root 20 0 125540 4076 2508 S 0.0 0.1 7:18.30 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.85 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:10.40 ksoftirqd/0 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 7 root rt 0 0 0 0 S 0.0 0.0 0:01.45 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 R 0.0 0.0 3:08.48 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 0:13.94 watchdog/0 11 root rt 0 0 0 0 S 0.0 0.0 0:09.76 watchdog/1 内存占用top10: PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 30541 root 20 0 55744 8448 0 S 200.0 0.3 14518:02 crond 1 root 20 0 125540 4076 2508 S 0.0 0.1 7:18.30 systemd 9 root 20 0 0 0 0 R 0.0 0.0 3:08.48 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 0:13.94 watchdog/0 3 root 20 0 0 0 0 S 0.0 0.0 0:10.40 ksoftirqd/0 11 root rt 0 0 0 0 S 0.0 0.0 0:09.76 watchdog/1 7 root rt 0 0 0 0 S 0.0 0.0 0:01.45 migration/0 2 root 20 0 0 0 0 S 0.0 0.0 0:00.85 kthreadd 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
将日志发送至搭建的FTP服务器上面1 2 3 4 5 6 7 8 9 10 11 12 ############################start############################### LOFFILE="/opt/server_check_log/ftp.log" ftp -n >>$LOFFILE <<EOF open 此处为ftp服务器的ip user ftp服务器的用户名称 ftp服务器的密码 binary cd /opt/server_check_log put test.txt bye EOF ########################脚本结束###########################
将指定目录下的所有的文件整理为一个文件,方便阅读1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ##############################################start######################################### #!bin/bash #print the directory and file for file in /opt/server_check_log/log/* do if test -f $file then #echo "$file is file" cat $file >> /opt/server_check_log/getAll.txt fi done ###########################################end#############################################
删除冗余的日志1 2 3 4 5 6 7 #!/bin/sh date=`date +%c` filename=`hostname`_check_`date -d '-1 day' +%Y%m%d`.txt tempfile="/tmp/$filename" rm -rf $tempfile
脚本计划任务定期执行1 2 3 00 02 * * * /tmp/server_daily_check.sh restart 00 14 * * * /tmp/delete_server_daily_check.sh restart