Centos 7 和 Centos 6 的区别

Centos 7

配置ip

默认没有安装 ifconfig ,yum search ifconfig 查看包是 net-tools,之后安装即可 yum install -y net-tools

或者使用 ip addr 命令来查看网卡

主机名相关
修改主机名
# hostnamectl set-hostname citizenwang
主机名配置文件
# vim /etc/hostname  
查看主机名状态
# hostnamectl status
命令补全包
相比于 centos 6 功能更全面
# yum install -y bash-completion 
# source /etc/profile 
系统服务相关
yum 安装

yum 的用法没有变化,但是做了优化,在 yum 安装的时候会自动选择距离最近的 yum 地址源。安装系统的时候如果使用了 minimal,一些命令比如 ifconfig、route、setup 等等都没有,可以安装以下的安装包。

# yum install -y lrzsz tree net-tools nmap vim bash-completion lsof dos2unix nc telnet ntp wget rng-tools psmisc
服务语法
启动、停止、状态等
# systemctl start/stop/restart/status/reload servicename 
自启动
# systemctl enable/disable service_name
杀死进程
# systemctl kill --signal=9 sshd
常见 service_name 及 服务列表
查看服务列表
# systemctl list-units --type=service
查看正在运行的服务
# systemctl list-units-files |grep enabled
查看特定服务是否开启
# systemctl list-units-files |grep servicename
启动脚本路径
# cd /usr/lib/systemd/system
  • network.service
  • nginx.service
  • network.service
  • sshd.service
  • rsyslog.service
  • crond.service
  • httpd.service
  • firewalld.service 防火墙
修改字符集
字符集配置文件
# cat /etc/locale.conf
修改字符集
# localectl set-locale LANG=zh_CN.UTF-8 
查看字符集状态
# localectl status
systemd
unit

systemd 支持多个服务同时启动,不用顺序启动,从而锁定开机时间;支持自动检测服务依赖的服务。

systemd 可以管理所有的系统资源,不同的资源统称为 unit。 unit 一共分为 12 种类型

/usr/lib/systemd/system 里面有各种类型的 unit,可以参考阅读
- Service Unit:系统服务 【常用
- Target Unit:多个 Unit 构成的组 【常用
- Device Unit:硬件设备
- Mount Unit:文件系统的挂载点
- Automount Unit:自动挂载点
- Path Unit:文件或路径
- Scope Unit:不是由 Systemd 启动的外部进程
- Slice Unit:进程组
- Snapshot Unit:systemd 快照,可以切回某个快照
- Socket Unit:进程间通信的 socket
- Swqp Unit:swap 文件
- Timer Unit:定时器

unit 相关命令
查看正在运行的 unit
# systemctl list-units 
查看所有的Unit,包括没有找到配置文件的或者启动失败的
# systeemctl list-units --all
查看所有加载失败的 unit
# systemctl list-units --fail
查看所有没有运行的 Unit
# systemctl list-units --all --static inactive
查看所有正在运行的、类型为 service 的 unit
# systemctl list-units --type service
查看某个 Unit 是否正在运行
# systemctl is-active servername.service
查看某个 Unit 是否处于启动失败状态
# systemctl is-failed servername.service
查看某个 Unit 服务是否开机启动
# systemctl is-enabled servername.service
target

类似于 centos 6 的运行级别,target 其实就是多个 unit 的组合,启动多个 unit,而 target 就是用来管理这些 unit。

系统一共有 5 个启动的target
# ls -l /usr/lib/systemd/system 
poweroff.target  
rescue.target
multi-user.target
graphical.target
reboot.target
target 常用命令
查看当前系统的所有 target
# systemctl list-unit-files --type target
查看一个 target 包含的所有 Unit
# systemctl list-dependencies multi-user.target
查看启动是的默认 target
# systemctl get-default
查看启动时的默认 target
# systemctl set-default multi-user.target
切换 target (默认不关闭前一个 target 启动的进程)
# systemctl rescue.target
# systemctl isolate multi-user.target
target 和 unit 的关联

主配置文件 /etc/systemd/system.conf

开机会先加载执行 /etc/systemd/system/default.target 这个 target ,ls -l /etc/systemd/system/defaut.target 查看文件是一个软连接,软连接到了/usr/lib/systemd/system/multi-user.target, 它会加载 /usr/lib/systemd/system/multi-user.target.wants 下面的 service。软连接也可以更改,用 systemctl set-default 修改

所有的 service 和 target 都在 /usr/lib/systemd/system/

查看一个 service 属于哪个 target,需要 cat 具体的 service 文件 cat /usr/lib/systemd/system/sshd.service 看里面 [install] 部分

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值