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. [C] gcc

    概述 GNU C Compiler 流程 预处理,生成.i文件(中间文件,看不到) 编译,生成.s文件(中间文件,看不到) 汇编,生成.o文件 链接,生成可执行文件 参数 -E:预处理 -S:预处理, ...

  2. Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.

    1.按照提示 systemctl status ssh.service 查看报错原因 sshd -t 2.结果 /etc/ssh/sshd_config line 34: missing argume ...

  3. canal 环境搭建 canal 与kafka通信(三)

    canal 占用了生产者 .net core端 使用消费者获取canal 消息 安装 Confluent.Kafka  demo使用 1.3.0 public static void Consumer ...

  4. 攻防世界(四)php_rce

    攻防世界系列:php_rce 1.打开题目 看到这个还是很懵的,点开任意连接都是真实的场景. 2.ThinkPHP5,这里我们需要知道它存在 远程代码执行的漏洞. ?s=index/\think\ap ...

  5. logstash数据处理及格式化功能详解

    Grok正则提取日志 环境延续我上一篇ELK单机版的filebeat-->redis-->logstash-->elasticsearch-->kibana环境,详情请参考: ...

  6. 2.1PyCharm 的初始设置

    PyCharm 的初始设置(知道) 目标 恢复 PyCharm 的初始设置 第一次启动 PyCharm 新建一个 Python 项目 设置 PyCharm 的字体显示 PyCharm 的升级以及其他 ...

  7. 第9章 case条件语句的应用实践

    case语句企业级生产案例 范例9-7:实现通过传参的方式往/etc/openvpn_authfile.conf里添加用户,具体要求如下. 1)命令用法为: USAGE: sh adduser {-a ...

  8. 企业微信三种token

    http://www.upwqy.com/doc/28.html 基本配置介绍 区分三种类型access_token 服务商的token 说明:以corpid(服务商CorpID).provider_ ...

  9. F5 api接口开发实战(一)

    本人从18年下旬,开始从事F5负载均衡的自动化开发工作,主要使用python编程语言,开发的F5功能模块为LTM和GTM. F5开发简介 1.F5管理模式 F5的管理模式主要有4种(不包含snmp), ...

  10. DM8_Linux详细安装步骤

    (从虚拟机配置讲起,有基础的可以直接看二,谢谢) 一.虚拟机的安装和配置 软件:virtualbox 系统:centos7 工具:Xshell 官网下载centos7,使用virtualbox安装ce ...