history
Unix(FreeBSD) - 贝尔实验室
Minix - 安德鲁
Linux - Linus Benedict Torvalds - (Redhat -> Centos | Ubuntu )
使用率
basic
基础变更
- 文件系统 - xfs
- /etc/hostname - 修改主机名 | timedatectl set-timezone - 时区设置 | ip - ip信息查看| ss - 端口查看 | firewalld - 防火墙 | systemd - 服务管理 | chrony - 时间同步
- 默认支持docker - 内核支持:OverlayFS | Repo源支持
- 不再支持32位操作系统
- GNOME 3.x
- centos7 - systemd 不断完善,强大 (ubuntu等也在不断加强使用)
hostname
1 | vim /etc/hostname |
file | dir
- 树状结构有时候查问题的时候,注意6/7的文件目录结构的变更
1
2
3
4
5
6
7
8
9
10
11
12
13
14/bin = User BINaries
/sbin = Superuser BINaries
/etc = ETCetera - configuration files
/dev = DEVices files
/proc = PROCesses information - top命令
/lib = LIBrary - system libraries
/tmp = TeMPorary
/usr = Unix Shared Resources - user programs
/boot = Boot loader files
/var = VARiable
/opt = optional add-on apps
/mnt = mount directory
/media = removable devices
/src = service data - bin -> usr/bin (7链接到了usr/bin下)
- sbin -> usr/sbin
- lib | lib64 等同上
- centos7 里面多了run目录
1
cd /;ls ./
timezone
- 中国 - +8
- 时区不准确,会导致系统时间有问题,即使配置了时间同步
1
2
3
4
5
6
7date -R
cat /etc/local
cat /ect/localtime
time
timedatectl # ntp的协议进行时间同步的|RTC - 本地主板时间
timedatectl set-timezone Asia/Shanghai
timedatectl set-local-rtc 1 # 将硬件时间调整成和本地时间(local time zone)一致
网络接口
- 默认命名规则
- centos6,如果是Dell的,可能会有em0等出现
- centos7 - net.ifnames 命名全自动,可预知,但是命名比较难读 | biosdevname = 提供给Dell部分
- /etc/sysconfig/grub -> GRUB_CMDLE_LINUX
- ifconfig - 阿里云的有这个命令,这个命令在(centos7-minimal安装)里面就默认没有了
- ip还是很强大的,推荐使用
1
2
3
4ip a # a - addr
ip a add|del # 修改ip地址信息
ip link set dev eth1 down|up # 关闭|启用网络接口
# 策略路由配置
自动补全
- tab (一下|两下)
- 名字 | 参数 - 安装bash-completion,然后重新登入主机
系统内存
- 操作系统内存 - 应用程序 | buffers | cached | 未使用
- shared 是很小的,不同程序间的共享内存
- Buffers - 存储速度|优先级 - 不同的设备之间传输数据的缓存区域
- Cached - CPU读取数据文件缓存的存储缓存区域
- Buffers | Cache 部分可以回收,来提供给应用程序使用
- 操作系统内存耗尽,触发OOM机制(out of memory),导致系统自动重启
- swap原理要理解 - 操作系统内存不够,会用swap -其实解决不了根本问题- mongoDB等还会产生问题
- Used到60%-80% 要注意
1
2
3top # 1 | shift + M | shift + P
free # 内存
free -m # 单位 M,free是未被分配的内存,Used-应用程序使用的
端口状态查看
1 | # ss - centos7 - 执行快(比netstat)- /proc/net/ |
TCP
- listen | established | fin_wait1 | close_wait | fin_wait2 |last_ack | “time_wait” | closed
- syn_sent | syn_recv
- 三次握手|四次挥手
Systemd
basic
- Systemd - centos7 - 新采用的管理体系,对比sysVini(centos6)
- 服务管理|启动项管理|系统启动级别|定时任务|日志管理
- centos6 - service|chkconfig|init|cron|syslog
- centos7 - systemctl|systemctl|systemctl|timer|Systemd-journal
- 支持并行启动
1
2
3
4
5
6
7# 可以提高开机启动速度(case,找一台中间机器,比较下速度)
yun install vsftpd
# 对于不同的6,7的,进行reboot,从中间机器上,看下联通情况
systemctl enable vsftpd # 加入开机启动-7
chkconfig vsftpd on # 加入开机启动-6
watch 'echo exit|nc xxx.xxx.xxx.xxx 21' # 中间机器 - centos7 关机只关闭正在运行的服务
- 对于服务的挂历不需要init.d下的脚本
- Service | Syslog - 原有问题解决
systemctl
- 文件扩展名 - 管理单元
1
2
3
4systemctl -t help # 查看支持哪些单元的管理
df -h
systemctl list-unit | grep 'boot'
systemctl start|stop nginx # service - 如果无扩展名,systemctl默认会把扩展名当成.service
systemctl list-units | --failed | list-unit-files | deamon-reload
- 单元管理命令 - start|stop|restart|reload|status|is-enabled
- 基本命令 enable|disable|mask|unmask
- systemctl [options] command [name]
- systemctl -h
target
- SysVinit vs Systemd
- 系统启动运行级别 - 0~6
1
2
3
4
5
6
7
8# SysVinit
cat /etc/rc.d/rc3.d
runlevel
init|telinit 6 # 非永久
# Systemd
systemctl get-default
systemctl set-default|isolate xxx.target
reboot systemctl list-dependencies
# 看到关联关系systemctl --reverse list-dependencies xxx.service
service
1 | # SysVinit |
1 | rpm -ql nginx |
- 软件包安装的单元 - /usr/lib/systemd/system/
- 系统管理员安装的单元 - /etc/systemd/system/
自定义服务单元
1 |
|
1 | tail -f /tmp/xxx.res |
1 | systemctl daemon-reload # 每次改完配置文件,要reload |
Timers
- 替代cron,定时控制服务事件(.service文件)
- 定时任务 = service服务单元 + timer定时单元
- 单调定时器 - 从一个时间点过一段时间后激活定时任务| 实时定时器 - 类比crontab(OnCalendar=--* 00:00:00)
- [Unit][Timer][Install]
- https://fedoramagazine.org/systemd-timers-for-scheduling-tasks/
1
systemctl list-timers
Journal
- Systemd的日志管理
- /etc/systemd/journald.conf
- RAM - tmpfs /run (df -h)
- /run/log/journal/ - 重启之后不会存在
journalctl
- 操作系统日志级别 - 0~7
journalctl [options] [matches]
- notice|warning - 粗体 error-红色
journalctl -n
# -n最后20行, -f实时,-p级别,-u具体单元
Firewalld
- https://firewalld.org/
- iptables - centos6
- 底层调用的iptables
- 区域管理
- 默认区域 - public
- 活跃|非活跃 区域
- ls /usr/lib/firewalld/zones/
- systemctl start firewalld.service
fiewall-cmd --list-all
ip a
- 外部访问服务器,默认阻止,服务器访问外部默认允许
1
2
3
4
5# 一个网卡接口只能属于一个zone,一个zone可以有多个网卡接口
# 配置了网络接口的区域是活跃区域(或者源地址配置add-source)
systemctl status
ip a
firewall-cmd --get-active-zones1
2
3
4
5
6
7
8
9
10# 端口白名单配置
ss -lntp
telnet xxx.xxx.xx.x 21 # 本机测试端口连通性
firewall-cmd --zone=public --add-port=21/tcp
firewall-cmd --list-all
firewall-cmd --reload # 动态加载新规则,在规则修改后,要执行这个,来使规则生效
firewall-cmd --complete-reload
firewall-cmd --zone=public --add-port=21/tcp --permanent
# 服务白名单配置
firewall-cmd --zone=public --add-service=http - 区域规则结合,可以得出想要的最终配置
1
2# default 设置为drop
firewall-cmd --zone=trusted --add-source=xxx.xxx.xxx.xx/24
文件系统
基本
- 装载 - 分区 - 格式化 => 文件系统
- c6 - ext4,ext3,ext2 c7 - xfs c7-ecs-ext4
- xfs - 扩展性支持能力高于ext4
云盘
ECS存储空间
数据隔离
提升性能
/dev/vda ext4 /系统目录
/dev/vd* xfs /应用目录
fdisk /dev/vdb
mount