Linux下常用命令整理

Linux中查看有关CPU的信息

  • CPU总核数 = 物理CPU个数 * 每颗物理CPU的核数
  • 总逻辑CPU数 = 物理CPU个数 * 每颗物理CPU的核数 * 超线程数

查看CPU信息(型号)

cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c

物理CPU的个数

cat /proc/cpuinfo | grep "physical id" | sort | uniq

每个物理CPU的逻辑核数

cat /proc/cpuinfo | grep "cores" | uniq

系统整体cpu线程数

cat /proc/cpuinfo | grep "processor" | wc -l

查看整体CPU的信息

[root@node1 270]# lscpu 
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                24
On-line CPU(s) list:   0-23
Thread(s) per core:    1
Core(s) per socket:    12
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
Stepping:              1
CPU MHz:               1199.902
CPU max MHz:           2900,0000
CPU min MHz:           1200,0000
BogoMIPS:              4400.17
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              30720K
NUMA node0 CPU(s):     0-11
NUMA node1 CPU(s):     12-23

其中Thread(s) per core能够看出是否开启了超线程,为‘1’表示未开启,为‘2’则表示开启超线程

Centos7.5 关闭超线程的方法

vim /etc/grub2.cfg

修改:"linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/centos00-root ro crashkernel=auto rd.lvm.lv=centos00/root rd.lvm.lv=centos00/swap rhgb quiet LANG=en_DK.UTF-8"在‘rd.lvm.lv=centos00/swap’ 后面添加 nr_cpus=24,其中24为物理核心数


Centos7永久修改hostname的方法

hostnamectl set-hostname node1

Linux下时间和时间戳的转换

时间转换为时间戳

[ifactory2@node1 data]$ date
Sun Dec 16 11:15:04 CST 2018
[ifactory2@node1 data]$ date -d "Sun Dec 16 11:15:04 CST 2018" +%s
1544930104
[ifactory2@node1 data]$ date +%s
1544930152
[ifactory2@node1 data]$ 

时间戳转换为时间

[ifactory2@node1 data]$ date -d @1544930152
Sun Dec 16 11:15:52 CST 2018
[ifactory2@node1 data]$ date -d @1544930104
Sun Dec 16 11:15:04 CST 2018
[ifactory2@node1 data]$ 

检查TCP/UDP端口的连通性

telnet和nc是用来测试端口连通性的一般工具。

telnet可以测试tcp端口的连通性。

nc可以测试tcp和udp端口的连通性。

  • telnet
    语法:telnet <hostname/IP address>
telnet 192.168.4.91 22
  • nc
    语法:nc -z -v <hostname/IP address>
nc -z -v 192.168.4.91 22

其中,-z表示不发送数据,-v显示指令执行过程

nc -z -v -u 192.168.4.91 514 #rsyslog的udp端口

其中,-u表示udp

nc命令语法
nc [-hlnruz][-g<网关……>][-G<指向器数目>][-i<延迟秒杀>][-o<输出文件>][-p<通信端口>][-s<来源位置>][-v……][-w<超时秒数>][主机名称][]
nc命令参数解释
-n 直接指定ip地址,不通过域名解析
-v 显示指令执行过程
-u 使用udp协议
-z 使用0输入/输出模式,只在扫描通信端口时使用

Centos系统服务配置资源限制ulimit

  • 在/usr/lib/systemd/systemctl/xxx.server中添加以下内容:
[Service]
# Other directives omitted
# (file size)
LimitFSIZE=infinity
# (cpu time)
LimitCPU=infinity
# (virtual memory size)
LimitAS=infinity
# (locked-in-memory size)
LimitMEMLOCK=infinity
# (open files)
LimitNOFILE=64000
# (processes/threads)
LimitNPROC=64000
  • 重新进程服务才会生效
  • 查看某个进程的资源限制,使用以下命令
ps -aux | grep xxx
cat /proc/{pid}/limits

其中,{pid}为进程ID

修改系统的ulimit参数

  • 查看所有参数:ulimit -a
[root@t60 iFactory2]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 255553
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 255553
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
[root@t60 iFactory2]# 
  • 修改具体某一项:/etc/security/limits.conf
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
ifactory2	soft	memlock		unlimited
root	hard	memlock		unlimited

# End of file
  • 但是,有时修改这个参数之后,服务的limit并没有随之改变,是由于服务自身有有关于ulimit的限制,因此仍然需哟上面提到的有关系统服务配置资源的限制。

自定义yum和createrepo

http://www.linuxe.cn/post-300.html

后期整理补充

systemctl 报错

Apr 14 11:37:35 t91 systemd-journal[607949]: Runtime journal is using 136.0M (max allowed 4.0G, trying to leave 4.0G free of 62.6G avail…mit 4.0G)
是因为systemd-journal服务没有启动,需要重新启动。启动成功之后,再启动对应的其他服务

要轻松的显示一个路径的所有权限,你可以使用:

 namei -om /path/to/check
posted @ 2020-01-08 19:29  头文件1991  阅读(451)  评论(0编辑  收藏  举报