首页 > 代码库 > Centos7系统配置上的变化(一)

Centos7系统配置上的变化(一)

安装后,一开始有点儿无力吐槽的感觉,变化这么大?

一、Runlevel
首先一条,原来一直用的CentOS-6.5-x86_64-minimal.iso光盘镜像(400M左右无图形系统小巧便捷),而7目前最小的镜像是CentOS-7.0-1406-x86_64-livecd.iso(700M左右),默认安装后是启动图形界面,按原来的习惯要改成启动命令行,结果发现:

[root@localhost ~]# 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 /etc/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 set a default target, run:## ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/default.target#

好吧,systemd一统天下了(它管的东西很多很多,学Centos7首先要搞定systemd)。

[root@localhost ~]# ls -Xl /etc/systemd/system/*.targetlrwxrwxrwx. 1 root root 36 7月 8 23:12 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.target

我们来看看从前的runlevel都变成什么样了?

[root@localhost ~]# ls -Xl /lib/systemd/system[root@localhost ~]# ls -Xl /lib/systemd/system/runlevel*.targetlrwxrwxrwx. 1 root root 15 7月 5 00:45 /lib/systemd/system/runlevel0.target -> poweroff.targetlrwxrwxrwx. 1 root root 13 7月 5 00:45 /lib/systemd/system/runlevel1.target -> rescue.targetlrwxrwxrwx. 1 root root 17 7月 5 00:45 /lib/systemd/system/runlevel2.target -> multi-user.targetlrwxrwxrwx. 1 root root 17 7月 5 00:45 /lib/systemd/system/runlevel3.target -> multi-user.targetlrwxrwxrwx. 1 root root 17 7月 5 00:45 /lib/systemd/system/runlevel4.target -> multi-user.targetlrwxrwxrwx. 1 root root 16 7月 5 00:45 /lib/systemd/system/runlevel5.target -> graphical.targetlrwxrwxrwx. 1 root root 13 7月 5 00:45 /lib/systemd/system/runlevel6.target -> reboot.target

修改默认启动runlevel为 multi-user (貌似runlevel2 3 4 没区别了)

[root@localhost ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target[root@localhost ~]# ll -X /etc/systemd/system/*.targetlrwxrwxrwx. 1 root root 37 7月 10 09:42 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target

试试init 6 还好用不。

[root@localhost ~]# init 6Connection to 192.168.150.180 closed by remote host.Connection to 192.168.150.180 closed.

成,好用。:)

因为我从桌面版Linux 连接Centos7系统提示变成了中文,所以需要把Centos7 的root用户语言改一下,回到原汁原味。

[root@localhost ~]# cp .bashrc .bashrc-back[root@localhost ~]# echo export LANG="en_Us.UTF-8" >> /root/.bashrc

 

二、Services

[root@localhost ~]# chkconfigNote: This output shows SysV services only and does not include native      systemd services. SysV configuration data might be overridden by native      systemd configuration.      If you want to list systemd services use systemctl list-unit-files.      To see services enabled on particular target use      systemctl list-dependencies [target].iprdump            0:off    1:off    2:on    3:on    4:on    5:on    6:offiprinit            0:off    1:off    2:on    3:on    4:on    5:on    6:offiprupdate          0:off    1:off    2:on    3:on    4:on    5:on    6:offlivesys            0:off    1:off    2:off    3:on    4:on    5:on    6:offlivesys-late       0:off    1:off    2:off    3:on    4:on    5:on    6:offnetconsole         0:off    1:off    2:off    3:off    4:off    5:off    6:offnetwork            0:off    1:off    2:off    3:off    4:off    5:off    6:offrhnsd              0:off    1:off    2:on    3:on    4:on    5:on    6:offvboxadd            0:off    1:off    2:on    3:on    4:on    5:on    6:offvboxadd-service    0:off    1:off    2:on    3:on    4:on    5:on    6:offvboxadd-x11        0:off    1:off    2:off    3:on    4:off    5:on    6:off

SysV已经快退居二线了,想配置服务得用systemctl,先看看默认启动的服务吧。(如果不用grep过滤一下,输出结果有260多行)

[root@localhost ~]# systemctl list-unit-files|grep enabledtmp.mount                                   enabled accounts-daemon.service                     enabled atd.service                                 enabled auditd.service                              enabled avahi-daemon.service                        enabled bluetooth.service                           enabled chronyd.service                             enabled crond.service                               enabled dbus-org.bluez.service                      enabled dbus-org.fedoraproject.FirewallD1.service   enabled dbus-org.freedesktop.Avahi.service          enabled dbus-org.freedesktop.NetworkManager.service enabled dbus-org.freedesktop.nm-dispatcher.service  enabled display-manager.service                     enabled dmraid-activation.service                   enabled firewalld.service                           enabled gdm.service                                 enabled getty@.service                              enabled irqbalance.service                          enabled iscsi.service                               enabled kdump.service                               enabled libstoragemgmt.service                      enabled lvm2-monitor.service                        enabled mdmonitor.service                           enabled microcode.service                           enabled multipathd.service                          enabled NetworkManager-dispatcher.service           enabled NetworkManager.service                      enabled packagekit-offline-update.service           enabled postfix.service                             enabled rngd.service                                enabled rsyslog.service                             enabled rtkit-daemon.service                        enabled smartd.service                              enabled spice-vdagentd.service                      enabled sysstat.service                             enabled systemd-readahead-collect.service           enabled systemd-readahead-drop.service              enabled systemd-readahead-replay.service            enabled tuned.service                               enabled avahi-daemon.socket                         enabled dm-event.socket                             enabled iscsid.socket                               enabled iscsiuio.socket                             enabled lvm2-lvmetad.socket                         enabled default.target                              enabled multi-user.target                           enabled remote-fs.target                            enabled 

默认居然没有启动sshd,晕!看看监听端口:

[root@localhost ~]# netstat -lntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2090/master

果然没有22,试试老办法:

[root@localhost ~]# chkconfig sshd onNote: Forwarding request to systemctl enable sshd.service.ln -s /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/sshd.service

能用,但是指令被转发到 systemctl enable sshd.service ,以后控制服务就用这个指令了。试试:

禁用sshd:

[root@localhost ~]# systemctl disable sshd.servicerm /etc/systemd/system/multi-user.target.wants/sshd.service

启用sshd:

[root@localhost ~]# systemctl enable sshd.serviceln -s /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/sshd.service

看看:

[root@localhost ~]# systemctl list-unit-files|grep sshd.serviceanaconda-sshd.service                       static  sshd.service                                enabled [root@localhost ~]# netstat -lntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2090/master         tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2758/sshd           tcp6       0      0 :::22                   :::*                    LISTEN      2758/sshd 

其实启用和禁用服务就是在当前“runlevel”的配置文件目录(/etc/systemd/system/multi-user.target.wants/)里,

建立/usr/lib/systemd/system 里面对应服务配置文件的软链接;禁用服务就是删除此软链接。
有兴趣就自己看看 /usr/lib/systemd/system 里的文件,语法跟旧版/etc/init.d/ 里的服务脚本完全不同,也不能再用 /etc/init.d/sshd restart 之类的指令启动服务器了。

先试试旧方法启动服务:

[root@localhost ~]# service sshd startRedirecting to /bin/systemctl start  sshd.service

用新方法折腾一下:

[root@localhost ~]# systemctl start sshd.service[root@localhost ~]# systemctl stop sshd.service[root@localhost ~]# systemctl restart sshd.service[root@localhost ~]# 

如果没有错误,就不会输出任何信息,这个,,,,得习惯一下。

 

三、网络
setup工具还是保留了,但有区别,没有了网络配置,多了RHN(Centos到底是跟RedHat一家子了)
[root@localhost ~]# setup


 


好吧,我们看看网络配置。

[root@localhost ~]# cat /etc/resolv.conf # Generated by NetworkManagernameserver 192.168.150.254[root@localhost ~]# cat /etc/sysconfig/network# Created by anaconda[root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg-*-rw-r--r--. 1 root root 298 Jul  9 00:13 /etc/sysconfig/network-scripts/ifcfg-Auto_Ethernet-rw-r--r--. 1 root root 288 Jul  8 23:12 /etc/sysconfig/network-scripts/ifcfg-enp0s3-rw-r--r--. 1 root root 254 Apr  2 23:30 /etc/sysconfig/network-scripts/ifcfg-lo[root@localhost ~]# ifconfigenp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        inet 192.168.150.180  netmask 255.255.255.0  broadcast 192.168.150.255        inet6 fe80::a00:27ff:fe9a:a688  prefixlen 64  scopeid 0x20<link>        ether 08:00:27:9a:a6:88  txqueuelen 1000  (Ethernet)        RX packets 39317  bytes 2487945 (2.3 MiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 2216  bytes 740115 (722.7 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536        inet 127.0.0.1  netmask 255.0.0.0        inet6 ::1  prefixlen 128  scopeid 0x10<host>        loop  txqueuelen 0  (Local Loopback)        RX packets 6  bytes 504 (504.0 B)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 6  bytes 504 (504.0 B)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0[root@localhost ~]# 

先改改主机名:

[root@localhost ~]# echo "hostname cenots7.localdomain" >>/etc/sysconfig/network[root@localhost ~]# rebootConnection to 192.168.150.180 closed by remote host.Connection to 192.168.150.180 closed.xw@Opt9010:~$ ssh root@192.168.150.180root@192.168.150.180s password: Last login: Thu Jul 10 10:01:09 2014[root@cenots7 ~]# 

看看网卡配置文件:

[root@cenots7 ~]# cd /etc/sysconfig/network-scripts/[root@cenots7 network-scripts]# cat ifcfg-Auto_Ethernet HWADDR=08:00:27:9A:A6:88TYPE=EthernetBOOTPROTO=dhcpDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noNAME="Auto Ethernet"UUID=76304098-8f46-4185-8337-bb7f0d90423eONBOOT=yes[root@cenots7 network-scripts]# cat ifcfg-enp0s3 HWADDR=08:00:27:9A:A6:88TYPE=EthernetBOOTPROTO=dhcpDEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_PEERDNS=yesIPV6_PEERROUTES=yesIPV6_FAILURE_FATAL=noNAME=enp0s3UUID=66a635c2-9600-437b-8cfb-57e9569f68daONBOOT=no

看看两个文件有啥不同:

[root@cenots7 network-scripts]# diff ifcfg-Auto_Ethernet ifcfg-enp0s3 14,16c14,16< NAME="Auto Ethernet"< UUID=76304098-8f46-4185-8337-bb7f0d90423e< ONBOOT=yes---> NAME=enp0s3> UUID=66a635c2-9600-437b-8cfb-57e9569f68da> ONBOOT=no

两个文件MAC地址一样,ifcfg-Auto_Ethernet ONBOOT=yes,但是ifconfig结果显示的是enp0s3,有点儿费解了。

再看看我复制KVM虚拟机时经常要改的网卡MAC地址:

root@cenots7 network-scripts]# ll /etc/udev/rules.d/total 8-rw-r--r--. 1 root root 134 Jul  9 00:47 60-vboxadd.rules-rw-r--r--. 1 root root 352 Jul  4 00:38 98-kexec.rules[root@cenots7 network-scripts]# cat /etc/udev/rules.d/98-kexec.rules SUBSYSTEM=="cpu", ACTION=="online", PROGRAM="/bin/systemctl try-restart kdump.service"SUBSYSTEM=="cpu", ACTION=="offline", PROGRAM="/bin/systemctl try-restart kdump.service"SUBSYSTEM=="memory", ACTION=="add", PROGRAM="/bin/systemctl try-restart kdump.service"SUBSYSTEM=="memory", ACTION=="remove", PROGRAM="/bin/systemctl try-restart kdump.service"[root@cenots7 network-scripts]# cat /etc/udev/rules.d/60-vboxadd.rules KERNEL=="vboxguest", NAME="vboxguest", OWNER="vboxadd", MODE="0660"KERNEL=="vboxuser", NAME="vboxuser", OWNER="vboxadd", MODE="0666"

70-persistent-net.rules呢?

网卡MAC只在网卡配置文件里有,一旦变了我只需要改网卡配置文件?

[root@cenots7 network-scripts]# grep -r "08:00:27:9A:A6:88" /etc//etc/sysconfig/network-scripts/ifcfg-enp0s3:HWADDR=08:00:27:9A:A6:88/etc/sysconfig/network-scripts/ifcfg-Auto_Ethernet:HWADDR=08:00:27:9A:A6:88

改一下网卡MAC 0800279AA688 -> 0800278C3746

 

 

改MAC后网卡不认了,测试结果是只需要改网卡配置文件的MAC,而且两个配置文件都要改才行。我顺便把DHCP改成了固定IP。

[root@cenots7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-Auto_Ethernet HWADDR=08:00:27:8C:37:46# HWADDR=08:00:27:9A:A6:88TYPE=EthernetBOOTPROTO=staticIPADDR=192.168.150.180NETMASK=255.255.255.0GATEWAY=192.168.150.254DEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=noIPV6_AUTOCONF=noIPV6_DEFROUTE=noIPV6_PEERDNS=noIPV6_PEERROUTES=noIPV6_FAILURE_FATAL=noNAME="Auto Ethernet"UUID=76304098-8f46-4185-8337-bb7f0d90423eONBOOT=yes[root@cenots7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 HWADDR=08:00:27:8C:37:46# HWADDR=08:00:27:9A:A6:88TYPE=EthernetBOOTPROTO=staticIPADDR=192.168.150.180NETMASK=255.255.255.0GATEWAY=192.168.150.254DEFROUTE=yesPEERDNS=yesPEERROUTES=yesIPV4_FAILURE_FATAL=noIPV6INIT=noIPV6_AUTOCONF=noIPV6_DEFROUTE=noIPV6_PEERDNS=noIPV6_PEERROUTES=noIPV6_FAILURE_FATAL=noNAME=enp0s3UUID=66a635c2-9600-437b-8cfb-57e9569f68daONBOOT=no

 

好吧,这样初步解决了基础问题。回头见。。。。

 

 


参考systemd wiki:
http://zh.wikipedia.org/wiki/Systemd