Centos7新功能

Centos7 单用户模式
 
centos7里不再有0-6启动级别,而是4个target
 
graphical.target  多人模式,支持图形和命令行两种登录,对应之前的3,5级别
 
multi-user.target  多人模式,只支持命令行登录,对应之前的3级别
 
rescue.target   单人模式,对应之前的1级别
 
emergency.target 单人模式,不过系统进入后根目录是只读的
 
 
centos7采用的是grub2,和之前的方式有所不同
 
在对应的内核条目上,按下"e",会进入edit模式,搜寻ro那一行,以linux16开头的,按“end”键到最后,输入rd.break,再按ctrl+x进入
 
进去后重新挂载 /sysroot/,增加写权限
 
mount -o remount,rw /sysroot/
 
切换到原始系统下
 
chroot /sysroot/
 
passwd
修改密码输入新密码
 
touch /.autorelabel    //这句是为了selinux生效
 
退出单用户的方法是
 
先ctrl+d 退出,然后reboot
 
 
 
1.3 centos7救援模式
 
设置光驱启动
选择Troubleshooting
选择Rescure a centos system
选择continue
chroot /mnt/sysimage
passwd
 
1.4 设置IP
 
网卡名字不再是eth0、eth1
dhclient先自动获取ip
没有 ifconfig命令,要使用 ip add 查看ip
要想继续使用 ifconfig,需要安装 net-tools
yum install -y net-tools
编辑配置文件
vi  /etc/sysconfig/network-scripts/ifcfg-eno16777736
里面配置和centos6一样
 
 
1.5  设置主机名 && 设置命令自动补全
 
hostname 查看主机名
hostnamectl set-hostname  test1
hostnamectl status //查看主机名状态
cat /etc/hostname //查看配置文件
centos7支持命令参数补全
安装 bash-completion
yum install -y bash-completion
source /etc/profile
 
1.6 centos7服务相关
 
centos7 不再有chkconfig工具了,而是使用systemd
使某服务自启动 systemctl enable httpd.service
不自启动 systemctl disable httpd.service
查看服务状态 systemctl status httpd.service
查看所有服务 systemctl list-units --type=service
启动服务  systemctl start httpd.service
停止服务 systemctl stop httpd.service
重启服务 systemctl restart httpd.service
启动脚本路径 /usr/lib/systemd/system/
检查一个服务是否为开机启动  systemctl is-enabled httpd
 
 
1.7 centos7 systemd-unit
 
systemd管理服务的机制的特点:
支持服务并列启动,不用顺序启动,从而开机时间缩短
支持自动检测服务依赖的服务
Systemd 可以管理所有系统资源。不同的资源统称为 Unit(单位)。
Unit 一共分成12种类型
Service unit:系统服务   Target unit:多个 Unit 构成的一个组
Device Unit:硬件设备  Mount Unit:文件系统的挂载点
Automount Unit:自动挂载点  Path Unit:文件或路径
Scope Unit:不是由 Systemd 启动的外部进程
Slice Unit:进程组  Snapshot Unit:Systemd 快照,可以切回某个快照
Socket Unit:进程间通信的 socket  Swap Unit:swap 文件
Timer Unit:定时器
 
列出正在运行的 Unit   systemctl list-units
列出所有Unit,包括没有找到配置文件的或者启动失败的
systemctl list-units --all
列出所有没有运行的 Unit   systemctl list-units --all --state=inactive
列出所有加载失败的 Unit   systemctl list-units --failed
列出所有正在运行的、类型为 service 的 Unit
systemctl list-units --type=service
显示某个 Unit 是否正在运行  systemctl is-active application.service
显示某个 Unit 是否处于启动失败状态
systemctl is-failed application.service
显示某个 Unit 服务是否建立了启动链接
systemctl is-enabled application.service
 
 
1.8 centos7 systemd-target
 
target类似于centos6里面的启动级别,但target支持多个target同时启动。target其实是多个unit的组合,系统启动说白了就是启动多个unit,为了管理方便,就使用target来管理这些unit。
查看当前系统的所有 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 isolate 命令改变这种行为,关闭前一个 Target 里面所有不属于后一个 Target 的进程
systemctl isolate multi-user.target
 
1.9 centos7 target关联unit
 
主配置文件 /etc/systemd/system.conf
开机会先加载/etc/systemd/system/default.target
所有的service和target在 /usr/lib/systemd/system/
ls -l /etc/systemd/system/defaut.target 是一个软连接
软连接到了/usr/lib/systemd/system/multi-user.target
它会加载/usr/lib/systemd/system/multi-user.target.wants下面的service
查看一个service属于哪个target,需要cat 具体的service文件
cat /usr/lib/systemd/system/sshd.service
看里面[install]部分
 
 
2.0 centos7 继续使用centos6的iptables管理机制
 
centos7不再使用iptables,而是使用firewalld
若不想使用firewalld,继续使用iptables,可以停掉firewalld,并且安装iptables-services包
systemctl stop firewalld
systemctl disable firewalld
yum install -y iptables-services
systemctl enable iptables
systemctl start iptables
 
 
firewalld的使用
 
centos6上使用的静态防火墙,规则保存在/etc/sysconfig/iptalbes, 更新规则,需要重新加载或者重启iptables服务,相当于是把之前的规则全部清空,再把配置文件里面的规则加载。
而centos7使用了动态防火墙,即firewalld,这种防火墙方案不再像之前,更改了规则不需要重新加载配置。
无论是firewalld还是之前的iptables服务,底层都是使用iptables工具来配置规则的。
fiewalld有zone和service的概念
每一个zone里面的iptables规则不一样,默认有9个zone。
centos7的默认zone是public
使用命令  firewall-cmd --get-zones 获取所有的zone
使用命令  firewall-cmd --get-default-zone  获取默认的zone
 
2.1 centos7 firewalld的zone
 
drop(丢弃) 任何接收的网络数据包都被丢弃,没有任何回复。仅能有发送出去的网络连接。
block(限制)任何接收的网络连接都被 IPv4 的 icmp-host-prohibited 信息和 IPv6 的 icmp6-adm-prohibited 信息所拒绝。
public(公共)在公共区域内使用,不能相信网络内的其他计算机不会对您的计算机造成危害,只能接收经过选取的连接。
external(外部)特别是为路由器启用了伪装功能的外部网。您不能信任来自网络的其他计算,不能相信它们不会对您的计算机造成危害,只能接收经过选择的连接。
dmz(非军事区)用于您的非军事区内的电脑,此区域内可公开访问,可以有限地进入您的内部网络,仅仅接收经过选择的连接。
work(工作)用于工作区。您可以基本相信网络内的其他电脑不会危害您的电脑。仅仅接收经过选择的连接。
home(家庭)用于家庭网络。您可以基本信任网络内的其他计算机不会危害您的计算机。仅仅接收经过选择的连接。
internal(内部) 用于内部网络。您可以基本上信任网络内的其他计算机不会威胁您的计算机。仅仅接受经过选择的连接。
trusted(信任)可接受所有的网络连接。
指定其中一个区域为默认区域是可行的。当接口连接加入了 NetworkManager,它们就被分配为默认区域。安装时,firewalld 里的默认区域被设定为公共区>域。
 
2.2 centos7 firewalld的zone相关命令
 
设置默认的zone  firewalld-cmd --set-default-zone=work
查看指定网卡所在的zone
firewall-cmd --get-zone-of-interface=eno16777736
给指定的网卡设置zone  firewall-cmd --zone=public --add-interface=lo
针对网卡更改zone  firewall-cmd --zone=dmz --change-interface=lo
也可以针对网卡删除zone
firewall-cmd --zone=dmz  --remove-interface=lo
查看所有网卡所在的zone  firewall-cmd --get-active-zones
 
 
2.3 centos7 firewalld service操作
 
在 /usr/lib/firewalld/services/ 目录中,还保存了另外一类配置文件,每个文件对应一项具体的网络服务,如 ssh 服务等
与之对应的配置文件中记录了各项服务所使用的 tcp/udp 端口,在最新版本的 firewalld 中默认已经定义了 70+ 种服务供我们使用
zone就是调用了不同的service而实现了不同的效果
列出所有的service: firewall-cmd --get-services
列出当前zone下加载的service:  firewall-cmd --list-services
查看某个zone下面的service:firewall-cmd --zone=public --list-services
给一个zone下面添加一个service:
firewall-cmd --zone=public --add-service=http
这个改动不会保存到配置文件里,要想保存到配置文件中,需要加上--permanent
firewall-cmd --zone=public --add-service=http  –-permanent
既然可以增加,同样也可以删除
firewall-cmd --zone=public --remove-service=http --permanent
 
2.4 centos7 firewalld 增加规则
 
假设自定义的 ssh 端口号为 12222,使用下面的命令来添加新端口的防火墙规则
firewall-cmd --add-port=12222/tcp --permanent
如果需要使规则保存到 zone 配置文件,则需要加参数 --permanent
防火墙配置文件也可以手动修改,修改后记得重载,重新加载的命令是
firewall-cmd --reload  这种情况下重新加载防火墙并不会中断用户连接,也可以彻底加载,这时候会中断用户连接,也会丢弃状态信息
firewall-cmd --complete-reload
还可以添加一个端口范围
firewall-cmd --add-port=2000-4000/tcp
针对某个zone添加端口
firewall-cmd --permanent --zone=home --add-port=443/tcp
启用端口转发,例如把22端口转发到127.0.0.2
firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2
 
 
 
2.5 centos7 firewalld 更改配置文件
 
两个路径/etc/firewalld/和/usr/lib/firewalld
系统使用的是/etc/firewalld下面的配置文件
在/etc/firewalld/zones下面只有一个public.xml,如果给另外一个zone做一些改动,并永久保存,那么会自动生成对应的配置文件
比如,给work zone增加一个端口
firewall-cmd --permanent --zone=work --add-port=1000/tcp
此时就会生成一个work.xml配置文件
需求: 修改ftp的端口,默认ftp端口是21,需要改为1121
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/
vi /etc/firewalld/services/ftp.xml   //把21改为1121
vi /etc/firewalld/zones/work.xml  //work为默认zone,所以要编辑这个,增加一行 <service name="ftp"/>
firewall-cmd --reload  //重新加载
posted @ 2017-05-08 10:21  Oops!#  阅读(3592)  评论(0编辑  收藏  举报