services使用了systemd来代替sysvinit管理。

systemd是Linux下的一种init软件,由Lennart Poettering带头开发,并在LGPL 2.1及其后续版本许可证下开源发布。

其开发目标是提供更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果,

最终代替现在常用的System V与BSD风格init程序。

2.1、与多数发行版使用的System V风格init相比,systemd采用了以下新技术:

采用Socket激活式与总线激活式服务,以提高相互依赖的各服务的并行运行性能。

用cgroups代替PID来追踪进程,以此即使是两次fork之后生成的守护进程也不会脱离systemd的控制。

从设计构思上说,由于systemd使用了cgroup与fanotify等组件以实现其特性,所以只适用于Linux。

2.2、systemd的服务管理程序:

systemctl是主要的工具,它融合之前service和chkconfig的功能于一体。可以使用它永久性或只在当前会话中启用/禁用服务。

为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。

启动一个服务:systemctl start postfix.service

关闭一个服务:systemctl stop postfix.service

重启一个服务:systemctl restart postfix.service

#提示:systemctl关闭、开启、重启服务是没有提示的,需要使用systemctl 服务状态命令查看;

显示一个服务的状态:systemctl status postfix.service

#命令最后加“-l”表示查看详细的信息;

在开机时启用一个服务:systemctl enable postfix.service

在开机时禁用一个服务:systemctl disable postfix.service

查看服务是否开机启动:systemctl is-enabled postfix.service

查看已启动的服务列表:systemctl list-unit-files #static是系统自带服务不需要我们进行管理的;

#Centos6和Centos7命令使用方法对照表:

2.3、防火墙的区别:

centos 7 默认采用firewalld动态防火墙,我还是更习惯使用iptables。

yum install iptables-services

# 安装iptables服务

systemctl stop firewalld.service

# 停止firewalld服务

systemctl disable firewalld.service

# 关闭firewalld服务开机自启

yum erase firewalld

# 卸载firewalld服务

systemctl enable iptables.service

# 开启iptables服务开机自启

systemctl list-unit-files | grep iptables.service

# 查看 iptables 开机自启动状态

systemctl start iptables.service

# 开启iptables服务

systemctl status iptables.service

# 查看iptables服务状态

2.4、端口查看命令:

[root@localhost ~]# ss -tunlp | column -t

Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

udp UNCONN 0 0 127.0.0.1:323 *:* users:(("chronyd",pid=932,fd=1))

udp UNCONN 0 0 ::1:323 :::* users:(("chronyd",pid=932,fd=2))

tcp LISTEN 0 128 *:22 *:* users:(("sshd",pid=1421,fd=3))

2.5、安装缺少的包组:

1、centos7主推使用ip,ss命令;

2、放弃的命令有:

ifconfig:yum install -y net-tools

#该工具包组件有ntsysv(系统服务)、system-config-networktui(网络服务)、iptables(防火墙配置)等;

setup:yum install -y setuptools

#安装完成之后,里面什么都没有,这只是一个图形工具,我们需要的防火墙,系统服务需要再另行安装;

#nmtui:图形化界面代替centos6的'setup'命令;

3、安装缺少的包:

yum install lrzsz dos2unix bash-completion nmap telnet tree wget vim net-tools ntpdate zabbix-agent bash-completion -y

2.6、更改yum源:

http://mirrors.aliyun.com/repo/ #该地址有阿里云所有的repo源配置文件;

1、yum源:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

#备份yum源;

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

#替换yum源;

2、eple源:

yum install -y epel-release

#安装epel源;

mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak

#备份epel源;

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

#替换eple源;

3、生成本地源缓存:

yum clean all

yum makecache

Centos7系统参数命令可以使用tab键进行补全;

4、查看系统可用的源:

yum repolist enabled

2.7、改主机名:

1、centos6:

hostname <hostname>

vim /etc/sysconfig/network

2、centos7:

(1)方法一:

hostname <hostname>

vim /etc/hostname

(2)方法二:

hostname <hostname>

hostnamectl set-hostname <hostname>

#实质是修改/etc/hostname配置文件;

hostnamectl status

#查看主机名配置文件的信息;

(3)提示:修改过主机名后需要退出当前的窗口,重新登录后生效;

2.8、修改字符集:

1、centos6:

vim /etc/sysconfig/i18n

source /etc/sysconfig/i18n

2、centos7:

(1)方法一:

vim /etc/locale.conf

source /etc/locale.conf

(2)方法二:

localectl set-locale LANG=zh_CN.UTF-8

#实质是修改/etc/locale.conf配置文件;

source /etc/locale.conf

localectl status

#查看字符集配置文件的信息;

2.9、时间:

[root@lc ~]# timedatectl status

Local time: Mon 2019-03-18 19:44:19 CST

Universal time: Mon 2019-03-18 11:44:19 UTC

RTC time: Mon 2019-03-18 11:44:19

Time zone: Asia/Shanghai (CST, +0800)

NTP enabled: yes

NTP synchronized: yes

RTC in local TZ: no

DST active: n/a

[root@localhost ~]# crontab -e

*/5 * * * * /usr/sbin/ntpdate ntp.aliyun.com $>/dev/null

2.10、查看系统版本号:

cat /etc/redhat-release #7和6都可用

cat /etc/os-release #只有centos7有

2.12、开机自启动文件的区别:

# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure

# that this script will be executed during boot.

上面的两段话来自Centos7中的/etc/rc.local配置文件中,在centos7中如果使用

/etc/rc.local配置文件需要执行chmod +x /etc/rc.d/rc.local命令进行授权操作,而

在centos6中则不需要该操作;

2.13、查看系统启动时间:

该功能是linux系统独有的,可以通过改参数对linux启动进行优化;

systemd-analyze time

Startup finished in 2.375s (kernel) + 7.075s (initrd) + 25.933s (userspace) = 35.384s

#显示出系统开机的总用时情况;

systemd-analyze blame

#对系统软件开机时间从大到小进行排序;

systemd-analyze plot >/tmp/boottime.svg

#将系统开机时间以可视化的图形进行展示,更为直观;

2.14、关闭postfix邮件提醒:

echo "unset MAILCHECK">> /etc/profile

source /etc/profile

2.15、centos7的运行级别:

1、Centos7将废弃"/etc/inittab"配置文件;

[root@slave-node1 ~]# cat /etc/inittab

# inittab is no longer used when using systemd.

#

# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

#

# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target

#

# systemd uses 'targets' instead of runlevels. By default, there are two main targets:

#

# multi-user.target: analogous to runlevel 3

# graphical.target: analogous to runlevel 5

#

# To view current default target, run:

# systemctl get-default

#

# To set a default target, run:

# systemctl set-default TARGET.target

#

2、查看当前的运行的系统级别:

[root@slave-node1 ~]# systemctl get-default

multi-user.target

3、设置系统的启动级别为多用户模式=>3:

[root@slave-node1 ~]# systemctl set-default multi-user.target

#设置系统的启动级别为桌面模式=>5:

[root@slave-node1 ~]# systemctl set-default graphical.target

#Centos6的runlevel在Centos7中的样子:

[root@slave-node1 ~]# ll /usr/lib/systemd/system/runleve*.target

lrwxrwxrwx. 1 root root 15 3月 18 12:49 /usr/lib/systemd/system/runlevel0.target -> poweroff.target

lrwxrwxrwx. 1 root root 13 3月 18 12:49 /usr/lib/systemd/system/runlevel1.target -> rescue.target

lrwxrwxrwx. 1 root root 17 3月 18 12:49 /usr/lib/systemd/system/runlevel2.target -> multi-user.target

lrwxrwxrwx. 1 root root 17 3月 18 12:49 /usr/lib/systemd/system/runlevel3.target -> multi-user.target

lrwxrwxrwx. 1 root root 17 3月 18 12:49 /usr/lib/systemd/system/runlevel4.target -> multi-user.target

lrwxrwxrwx. 1 root root 16 3月 18 12:49 /usr/lib/systemd/system/runlevel5.target -> graphical.target

lrwxrwxrwx. 1 root root 13 3月 18 12:49 /usr/lib/systemd/system/runlevel6.target -> reboot.target

4、说明:

init0-init6还是可以使用的,在Centos7中只用三种运行级别,0(poweroff.target):关闭计算机,1(rescue.target):单用户模式,

2、3、4(multi-user.target):多用户模式,5(graphical.target):图形界面,6(reboot.target):重启服务器;如果使用systemctl rescue命令

进入了单用户模式需要使用init 3进入多用户模式;

2.16、Centos7 systemctl命令的实质:

1、systemctl:

该命令融合了Centos6中的service(/etc/init.d/)和chkconfig的功能于一体,兼容SysV和LSB的启动脚本,而且能够在进程启动的过程中

更有效的引导加载服务;

2、systemctl开机自启动服务脚本存放的位置:

/usr/lib/systemd/system/

#存放的是需要系统管理的开机自启动服务脚本,类似于Centos6中的/etc/init.d/目录;

/etc/systemd/system/

#系统管理服务开机自启动的目录,类似于Centos6中的/etc/rc.d/目录;

3、将服务加入开机自启和将服务去除开机自启动的实质:

[root@slave-node1 ~]# systemctl enable postfix.service #将postfix服务设为开机自启动;

Created symlink from /etc/systemd/system/multi-user.target.wants/postfix.service to /usr/lib/systemd/system/postfix.service.

#创建/usr/lib/systemd/system/postfix.service服务脚本软链接到/etc/systemd/system/multi-user.target.wants/postfix.service

[root@slave-node1 ~]# systemctl disable postfix.service #关闭postfix服务的开机自启动;

Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.

#删除/etc/systemd/system/multi-user.target.wants/postfix.service脚本的软链接;

说明:/etc/systemd/system/multi-user.target.wants/目录类似于centos6中的/etc/rc.d/rc3.d/目录,存放的是需要系统管理的开机自启动服务脚本的软链接;

2.17、Centos7开机自启动优化:

[root@slave-node1 ~]# systemctl list-unit-files | grep enabled

Centos7开机自启动全部是并行启动,是没有先后顺序的;

#关闭不需要的服务:

[root@slave-node1 ~]#

service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd

auditd chronyd microcode postfix firewalld)

for ((i=0;i<${#service_array[*]};i++)); do

/usr/bin/systemctl disable ${service_array[$i]}

done

service_array=(abrt-ccpp abrt-oops abrt-vmcore abrt-xorg abrtd

chronyd microcode postfix firewalld)

for ((i=0;i<${#service_array[*]};i++)); do

/usr/bin/systemctl stop ${service_array[$i]}

done

2、centos6和centos7的区别的更多相关文章

  1. centos6和centos7的区别和常用的简单配置优化

    - 本节主要介绍centos6和centos7的区别和常用的简单配置优化:- 第一部分: - 1.对比文件系统 - 2.对比防火墙,内核版本,默认数据库 - 3.对比时间同步,修改时区,修改语言 - ...

  2. Centos6与Centos7的区别

    前言 centos7与6之间最大的差别就是初始化技术的不同,7采用的初始化技术是Systemd,并行的运行方式,除了这一点之外,服务启动.开机启动文件.网络命令方面等等,都说6有所不同.让我们先来了解 ...

  3. CentOS6跟CentOS7的区别

    1.CentOS6在/etc/profile配置环境变量是JAVAHOME,CentOS7是{JAVA_HOME} 2.

  4. Linux运维:CentOS6和7的区别

    Liunx笔记:CentOS6和CentOS7的区别 路飞学城运维人员 在线流程图软件 Ago linux运维群: 93324526 笔者QQ:578843228 常用安装包下载 yum instal ...

  5. centos6 和centos7 安装git 的区别

    centos6 和centos7 安装git 的区别 centos6安装git yum install curl-devel expat-devel gettext-devel openssl-dev ...

  6. centos6与centos7区别

    CentOS 6 vs CentOS 7的不同   (1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME Shell) (2)文件系统[CentOS6 ...

  7. CentOS6与CentOS7的网络区别

    回顾:物理层 关注的是接口物理特性,传输介质数据链路层 MAC地址,数据帧,以太网,交换机网络层 IP地址,数据包,IP\ICMP\ARP协议,路由器传输层 TCP.UDP,端口号,数据段应用层 HT ...

  8. 配置 Docker 加速器:适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1

    天下容器, 唯快不破 Docker Hub 提供众多镜像,你可以从中自由下载数十万计的免费应用镜像, 这些镜像作为 docker 生态圈的基石,是我们使用和学习 docker 不可或缺的资源.为了解决 ...

  9. cobbler部署centos6与centos7系列

    cobbler部署centos6与centos7系列 转载自:http://www.jianshu.com/p/a4bed77bf40d 版权声明:完全抄自 http://www.jianshu.co ...

随机推荐

  1. [刷题] 235 Lowest Common Ancestor of a Binary Search Tree

    要求 给定一棵二分搜索树和两个节点,寻找这两个节点的最近公共祖先 示例 2和8的最近公共祖先是6 2和4的最近公共祖先是2 思路 p q<node node<p q p<=node& ...

  2. 一文搞懂spring的常用注解

    spring传统做法是使用xml文件对bean进行注入和配置.通过使用spring提供的注解,可以极大的降低配置xml文件的繁琐.本文将介绍常用的注解. 一@Autowired Autowired意为 ...

  3. Linux Test Project(一)

    http://www.vimlinux.com/lipeng/2014/09/12/ltp/ Testing Linux, one syscall at a time. LTP是从SGI开始的,后由I ...

  4. https://www.jqhtml.com/30047.html strace + 命令: 这条命令十分强大,可以定位你程序到底是哪个地方出了问题

    https://www.jqhtml.com/30047.html 我的Linux手册 服务器 浏览数:72 2019-1-30 原文链接 基础安装 # CentOS sudo yum install ...

  5. Docker Swarm(二)常用命令

    # 管理配置文件 docker config     # 查看已创建配置文件     - docker config ls     # 将已有配置文件添加到docker配置文件中     - dock ...

  6. 007.Python循环语句while循环嵌套

    1 使用两个循环打印十行小星星 j = 0 while j<10: # 打印一行十个小星星 i = 0 while i<10: print("*",end=" ...

  7. Java 语言的主要特性

    Java语言是简单的 Java语言的语法与C语言和C++语言很接近,使得大多数程序员很容易学习和使用. Java丢弃了C++中很少使用的.很难理解的.令人迷惑的那些特性,如操作符重载.多继承.自动的强 ...

  8. JRebel插件使用详解(IDEA热部署)(Day_44)

    JRebel插件使用详解 简介 JRebel是一套JavaEE开发工具. Jrebel 可快速实现热部署,节省了大量重启时间,提高了个人开发效率. JRebel是一款JAVA虚拟机插件,它使得JAVA ...

  9. 在 Kubernetes 集群在线部署 KubeSphere

    https://github.com/kubesphere/ks-installer/blob/master/README_zh.md https://kubesphere.com.cn/docs/i ...

  10. Activiti中工作流的生命周期详细解析!一个BPMN流程示例带你认识项目中流程的生命周期

    BPMN 2.0介绍 业务流程模型注解(BusinessProcess Modeling Notation - BPMN)是业务流程模型的一种标准图形注解.这个标准是由对象管理组(Object Man ...