Linux 基础知识学习 PART-1
查看版本信息
查看Linux CentOS操作系统版本信息
uname 系统信息
uname 命令用于打印当前系统相关信息(内核版本号、硬件架构、主机名称和操作系统类型等)
选项 简要描述 -a 显示全部信息 -m 或 --machine 显示电脑类型 -r 或 --release 显示操作系统的发行编号 -s 或 --sysname 显示操作系统名称 -v 显示操作系统的版本 -p 或 --processor 输出处理器类型 或 “unknown” -i 或 --hardware-platform 输出硬件平台 或 “unknown” -o 或 --operating-system 输出操作系统名称 --
help显示帮助 --
version显示uname命令版本信息
uname -a
Linux pcsdev 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
cat /proc/version 版本信息
cat /proc/version
Linux version 3.10.0-693.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Aug 22 21:09:27 UTC 2017
cat /etc/centos-release 发布版本
cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
file /bin/ls
file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=3d705971a4c4544545cb78fd890d27bf792af6d4, stripped
cat /etc/issue
cat /etc/issue
\S
Kernel \r on an \m
安装的CentOS这个文件内容没有版本信息?
lsb_release -a
lsb_release -a
bash: lsb_release: command not found...
# 没有安装lsb_release, yum install redhat-lsb -y
mpstat -P ALL 查看CPU
mpstat -P ALL
Linux 3.10.0-693.el7.x86_64 (pcsdev) 04/30/19 _x86_64_ (2 CPU)
13:37:04 CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
13:37:04 all 0.04 0.00 0.03 0.06 0.00 0.00 0.02 0.00 0.00 99.84
13:37:04 0 0.04 0.00 0.04 0.06 0.00 0.00 0.02 0.00 0.00 99.84
13:37:04 1 0.04 0.00 0.03 0.06 0.00 0.00 0.02 0.00 0.00 99.84
sar -P ALL 查看CPU
sar -P ALL
Linux 3.10.0-693.el7.x86_64 (pcsdev) 04/30/19 _x86_64_ (2 CPU)
00:00:01 CPU %user %nice %system %iowait %steal %idle
00:10:01 all 0.04 0.00 0.04 0.00 0.03 99.89
00:10:01 0 0.03 0.00 0.05 0.01 0.03 99.88
00:10:01 1 0.05 0.00 0.04 0.00 0.02 99.89
00:10:01 CPU %user %nice %system %iowait %steal %idle
00:20:01 all 0.04 0.00 0.04 0.00 0.03 99.90
00:20:01 0 0.05 0.00 0.04 0.00 0.04 99.87
00:20:01 1 0.03 0.00 0.03 0.00 0.02 99.92
修改系统时间
date 系统时间
# root权限
# 查看系统时间
date
Wed Apr 24 19:36:47 CST 2019
# 修改系统时间(当系统重新启动的时候就会还原)
date -s '2019-04-24 17:00:00'
hwclock 硬件时间
# 查看硬件的时间(主机板上的时钟设备)
hwclock --show
Wed Apr 24 19:36:48 2019 -10.032729 seconds
# 设置硬件时间
hwclock --set --date '2019-04-24 17:00:00'
# 设置系统时间和硬件时间同步
hwclock --hctosys
# 保存时钟
clock -w
# 重启系统(init 6)使之生效,注意:若未生效 修改时区
# 更改时区
ln -sf /usr/share/zoneinfor/Asia/Shanghai /etc/localtime
clock / hwclock 显示与设定硬件时钟(query and set the hardware clock (RTC)),两个命令相同。RTC=Real Time Clock,也就是硬件时钟
选项 简要描述 -r 或 --show 读取并打印硬件时钟(read hardware clock and print result) -s 或 --hctosys 将硬件时钟同步到系统时钟(set the system time from the hardware clock) -w 或 --systohc 将系统时钟同步到硬件时钟(set the hardware clock to the current system time)
timedatectl 时区设置
# 附: 时区设置相关
timedatectl
Local time: Wed 2019-04-24 19:48:46 CST
Universal time: Wed 2019-04-24 11:48:46 UTC
RTC time: Wed 2019-04-24 11:47:47
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
# 列出所有时区
timedatectl list-timezones
# 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间
timedatectl set-local-rtc 1
# 设置系统时区为上海
timedatectl set-timezone Asia/Shanghai
常用监控命令
free 显示内存使用情况
free1 命令(free)用来显示Linux系统中空闲的、已用的物理内存及交换分区(swap)内存,及被内核使用的buffer。数据取自 /proc/meminfo文件。
# 每2秒采集一次信息 共显示3次
```shell
$ free -h -s 2 -c 3
total used free shared buff/cache available
Mem: 7.6G 793M 1.3G 88M 5.6G 6.5G
Swap: 13G 0B 13G
total used free shared buff/cache available
Mem: 7.6G 793M 1.3G 88M 5.6G 6.5G
Swap: 13G 0B 13G
total used free shared buff/cache available
Mem: 7.6G 794M 1.3G 88M 5.6G 6.5G
Swap: 13G 0B 13G
vmstat 虚拟内存统计
vmstat2 命令(Virtual Memory Statistics) 用来显示Linux系统虚拟内存状态。
可以展现指定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况、I/O等系统整体运行状态。
# 每2秒采集一次信息 共采集5次
$ vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 1315656 325984 5555384 0 0 0 0 1 0 0 0 100 0 0
0 0 0 1315608 325984 5555384 0 0 0 0 59 62 0 0 100 0 0
0 0 0 1315624 325984 5555384 0 0 0 0 46 49 0 0 100 0 0
0 0 0 1315608 325984 5555384 0 0 0 0 61 66 0 0 100 0 0
0 0 0 1315608 325984 5555384 0 0 0 0 51 53 0 0 100 0 0
top 实时监控系统运行进程情况
top3 命令(top) 用来实时监控Linux的系统状况,比如CPU、内存的使用,类似于Windows的任务管理器。
# 每2秒采集一次信息 共采集1次
$ top -d 2 -n 1
top - 11:29:19 up 110 days, 20:47, 1 user, load average: 0.00, 0.01, 0.05
Tasks: 163 total, 1 running, 162 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 8012508 total, 1302276 free, 817552 used, 5892680 buff/cache
KiB Swap: 14680060 total, 14680060 free, 0 used. 6769676 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 125488 4008 2504 S 0.0 0.1 35:32.98 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.35 kthreadd
...
todo
getconf
参考资料
- 如有 错误之处 还请多多指正