-
系统重要目录信息 /proc(进程文件/内核文件)
系统硬件信息: 资产管理 excel
CPU信息查看:
physical id : 0 — 服务器上有几颗CPU
processor : 0 — 服务器CPU核心数physical id : 0 physical : 0 – 2行 == 服务器有两颗CPU
physical id : 0
physical id : 1 physical : 1
physical id : 1[root@linux67 ~]# grep “physical id” /proc/cpuinfo | uniq
physical id : 0
physical id : 1
[root@linux67 ~]# grep “physical id” /proc/cpuinfo | uniq |wc -line
2
说明: | 管道符号: 将前一个命令执行输出结果通过管道交给后面的命令进行再次处理processor : 0 – 4行 == 整个服务器有4个核心
processor : 1
processor : 2
processor : 3统计服务器总的核心数:
[root@linux67 ~]# grep -c processor /proc/cpuinfo
4补充: wc命令介绍:
-c, --bytes print the byte counts
将字节统计信息输出(包含空格和换行符)
-m, --chars print the character counts
将字符统计信息输出
-l, --lines print the newline counts ******
统计文件中有多少行
-w, --words print the word counts使用命令查看:
[root@linux67 ~]# lscpu
CPU(s): 4
Socket(s): 2内存信息: cat /proc/meminfo
MemTotal: 2028116 kB — 服务器总的内存数量
MemFree: 1720948 kB — 空闲内存数量
MemAvailable: 1703560 kB — 可用的内存数量 ***
Buffers: 2092 kB — 划分内存一定空间用于缓冲使用 加快数据写入
Cached: 98352 kB — 划分内存一定空间用于缓存使用 加快数据读写使用命令查看:
[root@linux67 ~]# free
total used free shared buff/cache available
Mem: 2028116 140908 1720708 9700 166500 1703320
Swap: 1048572 0 1048572
[root@linux67 ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 137M 1.6G 9.5M 162M 1.6G
Swap: 1.0G 0B 1.0G硬盘信息: cat /proc/mounts
/dev/sr0 /mnt iso9660 ro,relatime 0 0
/dev/sda1 /boot xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0- 存储设备文件信息
- 磁盘挂载点信息
- 文件系统类型信息
- 挂载的参数信息
- 是否备份磁盘信息
- 是否检查磁盘
使用命令查看磁盘:
[root@linux67 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 98G 1.6G 97G 2% /
devtmpfs 980M 0 980M 0% /dev
/dev/sr0 4.3G 4.3G 0 100% /mnt
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 199M 0 199M 0% /run/user/0如何在系统中生成大文件:
使用循环方法:
for 变量 oldboy in {1…300} oldboy=1 oldboy=2 … oldboy=10
do
做什么事
done
for oldboy in {1…300};do cat /etc/services >>/tmp/oldboy.txt;done查看负载情况: cat /proc/loadavg
cat /proc/loadavg
0.09 0.10 0.07 1/133(?) 8019(?)
每1分钟 每5分钟 每15分钟负载值 <= 服务器总的核心数
查看命令信息:
w uptime top
w
10:36:31 up 1:36, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.0.0.1 09:37 7.00s 0.60s 0.00s w
01 02 03 04 05 06 0701: 登录系统用户信息
02: 登录系统方式 pts/x(远程登录) ttyx(本地登录)
03: 远程登录主机用户IP地址信息
04: 用户登录主机时间
05: 用户登录主机空闲时间
06: 用户操作系统占用CPU情况
07: 检查用户远程之后再做什么
w — 用户在执行w命令
-bash — 进行基础命令操作
vim — 编辑文件状态
sh xxx — 执行脚本阶段总结: 目录结构章节知识
- 操作系统挂载概念 mount / umount
- 操作系统重要目录 /var /proc /etc
- 操作系统重要文件
/etc
a 网卡配置文件
b DNS解析配置文件
c 本地解析配置文件
d 主机名称配置文件
e 开机运行命令文件
f 开机自动挂载文件
g 系统运行级别文件
h 环境变量或别名配置文件 4个
i 登录显示信息文件 登录前 登录后
/var 是储存各种变化的文件
messages 记录系统的几乎所有信息,主要包括启动信息,syslogd服务记录的信息等
secure 记录登录系统访问数据的文件,如sshpop3telnetftp等都会记录在此文件中
/proc
cpuinfo meminfo mounts loadavg
lscpu free -h df -h w uptime top
-
操作系统基础优化:
准备工作:
系统版本信息:
[root@linux67 tmp]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
系统内核信息:
[root@linux67 tmp]# uname -a
Linux linux67 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux-
系统用户优化部分
如何创建用户: useradd oldgirl
如何设置密码:
方法一: 利用root用户设置密码
[root@linux67 tmp]# passwd oldgirl
Changing password for user oldgirl.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.方法二: 不同用户自己设置密码
[oldgirl@linux67 ~]$ passwd
Changing password for user oldgirl.
Changing password for oldgirl.
(current) UNIX password:
New password:
Retype new password:需要密码复杂度:
数字字母组合(大小写) oldboy12345(ok) Oldboy12345(ok)
数字字母符号 oldboy12345!(ok) Oldboy12345!(ok)
说明: 重新设置的密码尽量不要和原有密码太相似方法三: 批量修改用户密码
单个用户免交互修改密码:
echo 123456|passwd --stdin oldboy
批量修改多个用户密码:
for user in oldboy oldgirl olddog oldbaby;do echo 123456|passwd --stdin $user;done
脚本:
[root@linux67 tmp]# vi set_pass.sh
#!/bin/bash
for user in oldboy oldgirl olddog oldbaby
do
echo 123456|passwd --stdin $user
done如何删除用户 userdel olddog
检查用户信息 id oldboy
切换用户信息 su - 用户名称
-
系统命令提示符号优化
a 优化提示符显示信息
PS1 — 用于设置系统命令提示符echo $PS1
[ \u @ \h \W ]$
[root@linux67 tmp]#
\u — 当前登录用户
@ — 分割符号
\h — 显示系统主机名称
\W — 显示当前路径信息
$ — 显示登录系统用户信息
# 管理员用户 root
$ 普通用户 oldboy临时设置:
PS1="[\u@\h \t \W]\$ "
PS1=’[\u@\h \t \W]$ ’永久设置:
vi /etc/profile
PS1=’[\u@\h \t \W]$ ’b 恢复提示符正常显示
永久设置:
vi /etc/profile
PS1=’[\u@\h \t \W]$ ’c 提示符颜色优化
-
系统yum源优化
yum源优化
yum下载软件原理: yum仓库 yum源文件
yum源文件下载说明:
重要目录: /etc/yum.repos.d/ — 保存yum源文件目录
Base yum源优化
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repoepel yum源优化 (企业扩展yum仓库) Extra Packages for Enterprise Linux
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
或者
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repoyum install -y vim wget tree telnet nc nmap net-tools bash-completion(补全参数软件)
-
系统安全优化说明(关闭)
安全服务: firewalld(防火墙)-centos7 iptables(防火墙)-centos6
安全服务: selinux (限制root用户行为) 系统权限概念 root管理员防火墙服务如何关闭:
临时关闭:
centos7 centos6
systemctl stop firewalld /etc/init.d/iptables stop
systemctl is-active firewalld /etc/init.d/iptables status
services stop iptables
永久关闭:
centos7 centos6
systemctl disable firewalld chkconfig iptables off
systemctl is-enabled firewalld chkconfig --list iptablesselinux安全服务如何关闭
临时关闭:
setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ] ??
setenforce Permissive | 0getenforce
Permissive
永久关闭:
vim /etc/selinux/config
SELINUX=disabled
enforcing - SELinux security policy is enforced.
selinux安全策略会被强制执行permissive - SELinux prints warnings instead of enforcing.
selinux输出警告信息代替强制执行disabled - No SELinux policy is loaded.
不加载Selinux策略sed -i ‘7s#enforcing#disabled#g’ /etc/selinux/config
-
系统字符集优化
王永民 – 五笔
UTF-8 GBKa 避免出现字符乱码
字符编码信息如何调整:
临时调整:
LANG=“en_US.GBK”永久调整:
LANG=“en_US.GBK”
方法一: 将配置信息放入到/etc/profile
LANG=“en_US.GBK”
方法二: 将配置信息放入到/etc/locale.conf
LANG=“zh_CN.gbk”
说明: 配置的字符编码必须是系统可以识别的
localectl list-locales即临时修改, 又永久修改
localectl set-locale LANG=“en_US.iso88591”b 可以中文显示信息
localectl set-locale LANG=“zh_CN.utf8” -
系统时间信息优化
-
修改时间信息和真正时间同步
时区不正确:
timedatectl set-timezone ZONE
调整时间信息:
a 手动调整时间信息
timedatectl set-time TIME
b 自动调整时间信息
yum install -y chrony
timedatectl set-ntp 1timedatectl 参数信息:
status Show current time settings
显示目前时间设置信息
set-time TIME Set system time
设置系统时间
timedatectl set-time “2019-10-10 10:57”
set-timezone ZONE Set system time zone
list-timezones Show known time zones
显示出已知系统时区信息
timedatectl set-timezone America/Los_Angeles
timedatectl set-timezone Asia/Shanghai
set-local-rtc BOOL Control whether RTC is in local time
set-local-rtc 0 rtc功能是关闭
set-local-rtc 1 rtc功能是开启
1 2 3 30 整数
1.11 1.12 1.13 浮点数
1(true) 0(false)布尔型
RTC: 设置硬件时间信息, 设置为1开启, 将系统信息自动同步给硬件set-ntp BOOL Control whether NTP is enabled
是否设置开启网络时间同步功能(NTP: 网络时间协议)
yum install -y chrony
-
-
远程连接优化
修改远程服务配置文件:
vim /etc/ssh/sshd_config – :set nu
79 GSSAPIAuthentication no – 远程认证方式
115 UseDNS no – 远程访问时根据IP地址进行反向解析过程
systemctl restart sshd
-
操作系统基础优化
最新推荐文章于 2021-12-03 09:23:05 发布