2、centos6和centos7的区别
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的区别的更多相关文章
- centos6和centos7的区别和常用的简单配置优化
- 本节主要介绍centos6和centos7的区别和常用的简单配置优化:- 第一部分: - 1.对比文件系统 - 2.对比防火墙,内核版本,默认数据库 - 3.对比时间同步,修改时区,修改语言 - ...
- Centos6与Centos7的区别
前言 centos7与6之间最大的差别就是初始化技术的不同,7采用的初始化技术是Systemd,并行的运行方式,除了这一点之外,服务启动.开机启动文件.网络命令方面等等,都说6有所不同.让我们先来了解 ...
- CentOS6跟CentOS7的区别
1.CentOS6在/etc/profile配置环境变量是JAVAHOME,CentOS7是{JAVA_HOME} 2.
- Linux运维:CentOS6和7的区别
Liunx笔记:CentOS6和CentOS7的区别 路飞学城运维人员 在线流程图软件 Ago linux运维群: 93324526 笔者QQ:578843228 常用安装包下载 yum instal ...
- centos6 和centos7 安装git 的区别
centos6 和centos7 安装git 的区别 centos6安装git yum install curl-devel expat-devel gettext-devel openssl-dev ...
- centos6与centos7区别
CentOS 6 vs CentOS 7的不同 (1)桌面系统[CentOS6] GNOME 2.x[CentOS7] GNOME 3.x(GNOME Shell) (2)文件系统[CentOS6 ...
- CentOS6与CentOS7的网络区别
回顾:物理层 关注的是接口物理特性,传输介质数据链路层 MAC地址,数据帧,以太网,交换机网络层 IP地址,数据包,IP\ICMP\ARP协议,路由器传输层 TCP.UDP,端口号,数据段应用层 HT ...
- 配置 Docker 加速器:适用于 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1
天下容器, 唯快不破 Docker Hub 提供众多镜像,你可以从中自由下载数十万计的免费应用镜像, 这些镜像作为 docker 生态圈的基石,是我们使用和学习 docker 不可或缺的资源.为了解决 ...
- cobbler部署centos6与centos7系列
cobbler部署centos6与centos7系列 转载自:http://www.jianshu.com/p/a4bed77bf40d 版权声明:完全抄自 http://www.jianshu.co ...
随机推荐
- [bug] logback error FileNotFoundException
问题 在gitee上下载的项目,运行报错 原因 原程序中设置了日志保存路径,我的电脑没有,需要手动创建 参考 https://blog.csdn.net/danchaofan0534/article/ ...
- [转载]有些shell文件中为啥要用$(cd “$(dirname $0)“; pwd),pwd它不香吗
$(cd "$(dirname "$0")",pwd) 解析 xx.sh 文件内容如下: #!/bin/bash BIN_FOLDER=$(cd " ...
- vmware快捷键大全
初学linux的朋友往往需要使用VMware这个软件 与其打交道多了 越来越觉得快捷键的重要性 特将搜集到的快捷键记录以便查阅记忆 Ctrl-Alt-Enter 进入全屏模式 ctrl+alt+ins ...
- 【山外笔记-SVN命令】svn命令详解
本文打印版文件下载地址 [山外笔记-SVN命令]svn命令详解-打印版.pdf 一.命令简介 svn命令用于Subversion命令行客户端,执行svn相关的操作. 二.命令语法 1.svn语法: ( ...
- Centos6下通过 oprofile分析CPU性能
Centos6下通过 oprofile分析CPU性能 2014-01-18 10:55:15 bobpen 阅读数 2218更多 分类专栏: linux 版权声明:本文为博主原创文章,遵循CC 4 ...
- 实例:使用playbook实现httpd安装、配置、以及虚拟主机的配置
一.安装环境配置 1.在控制节点给受控主机配置本地仓库文件 [root@ansible ~]# vim /etc/yum.repos.d/dvd.repo [AppStream] name=appst ...
- Docker镜像的仓库及底层依赖的核心技术(3)
一.docker镜像的仓库 仓库分为公共仓库和私有仓库 DockerHub的官方仓库:https://hub.docker.com DockerPool社区仓库:https://dl.dockerpo ...
- Canvas跟随鼠标炫彩小球
跟随鼠标炫彩小球 canvas没有让我失望,真的很有意思 实现效果 超级炫酷 实现原理 创建小球 给小球添加随机颜色,随机半径 鼠标移动通过实例化,新增小球 通过调用给原型新增的方法,来实现小球的动画 ...
- HUAWEI防火墙通过L2TP隧道让外出员工访问公司内网的各种资源
组网图形 组网需求 企业网络如图所示,企业希望公司外的移动办公用户能够通过L2TP VPN隧道访问公司内网的各种资源. 操作步骤 配置LNS. 1.配置接口IP地址,并将接口加入安全区域. <L ...
- 听说 JVM 性能优化很难?今天我小试了一把!
文章首发于公众号「陈树义」及个人博客 shuyi.tech,欢迎关注访问. 对于 Java 开发的同学来说,JVM 性能优化可以说是比较难掌握的知识点.这不仅因为 JVM 性能优化需要掌握晦涩难懂的 ...