CentOS7新特性

一、CentOS7的4中模式

CentOS7里不在有0-6启动级别,而是4个target

1、graphical.target:多人模式,支持图形和命令行两种登录,对应之前的3,5级别

2、multi-user.target:多人模式,只支持命令行登录,对应之前3级别

3、rescue.target:单人模式,对应之前的1级别

4、emergency.target:单人模式,不过系统进入根后目录是只读的

二、CentOS7的单用户模式

CentOS7采用的是grub2,和之前的方式有所不同

1、在对应的内核条目上,按e键,会进入edit模式,搜寻以linux16开头的,按end键到最后,输入rd.break,再按ctrl+x进入

2、进去后重新挂载/sysroot/,增加写权限

mount -o remount,rw /sysroot/

3、切换到原始系统下

chroot /sysroot/

现在就可以修改root用户的密码了

4、使selinux生效(可以省略)

touch /.autorelabel

如果没有此操作在重启后会对系统进行检测

5、退出单用户重启

先exit

然后reboot

三、CentOS7设置IP

查看IP的方法是ip addr

要想使用ifconfig命令需要安装net-tools包

和6差不多只不过文件的名字不太一样

四、CentOS7设置主机名

1、查看主机名hostname

设置主机名(直接写入到配置文件,使用hostname fansik则不会)

hostnamectl set-hostname fansik

2、配置文件/etc/hostname

3、查看主机名状态

hostnamectl status

五、CentOS7设置命令(参数)自动补全

安装bash-completion

yum -y install bash-completion

source /etc/profile

六、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

七、systemd unit

systemd管理服务机制的特点:支持自动检测服务依赖的服务,并行启动

systemd可以管理所有系统资源,不同的资源统称为unit(单位)

unit一共分成12种类型

1、service unit:系统服务

2、target unit:多个unit构成的一个组

3、device unit:硬件设备

4、mount unit:文件系统的挂载点

5、automount unit:自动挂载点

6、path unit:文件或路径

7、scope unit:不是由systemd启动的外部进程

8、slice unit:进程组

9、snapshot unit:快照,可以切回某个快照

10、socket unit:进程间通信的

11、socket swap unit:swap文件

12、timer unit:定时器

systemd 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

八、systemd target

target类似于CentOS6里面的启动级别,但target支持多个target同时启动,target是多个unit的组合,系统启动是就是启动了多个unit,为了管理方便target来管理这些unit

target连接的runlevel在改目录下可以查看到相应软连接

/usr/lib/systemd/system

查看当前系统的所有target

systemctl list-unit-files --type=target

查看一个target所包含了哪些unit

systemctl list-dependencies mulit-user.target

查看启动是的默认target

systemctl get-default

设置启动时的默认target

systemctl set-default multi-user.target

切换target时,默认不关闭前一个target启动的进程

systemctl isolate命令改变这种行为,关闭前一个target里面所有不属于最后一个target的进程

systemctl isolate multi-user.target

九、systemd unit target关联关系

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

开机会自动加载/etc/systemd/system/default.target

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

/etc/systemd/system/default.target是一个软链接文件,链接到了/lib/systemd/system/multi-user.target

它会加载/usr/lib/systemd/system/multi-user.target.wants下面的service

查看一个service属于哪个target,需要cat具体的service文件

cat sshd.service,里面[Install]的部分

posted @ 2016-11-07 17:25  fansik  阅读(446)  评论(0编辑  收藏  举报