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








猜你喜欢

转载自www.cnblogs.com/LiuChang-blog/p/12321055.html