新聞中心
安裝centos 7系統(tǒng)后,變化竟然這么大?

一、Runlevel
首先一條,原來一直用的CentOS-6.5-x86_64-minimal.iso光盤鏡像(400M左右無圖形系統(tǒng)小巧便捷),而7目前最小的鏡像是CentOS-7.0-1406-x86_64-livecd.iso(700M左右),默認(rèn)安裝后是啟動(dòng)圖形界面,按原來的習(xí)慣要改成啟動(dòng)命令行,結(jié)果發(fā)現(xiàn):
[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 /etc/systemd/system/default.target #
好吧,systemd一統(tǒng)天下了(它管的東西很多很多,學(xué)Centos7首先要搞定systemd)。
[root@localhost ~]# ls -Xl /etc/systemd/system/*.target lrwxrwxrwx. 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*.target lrwxrwxrwx. 1 root root 15 7月 5 00:45 /lib/systemd/system/runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 7月 5 00:45 /lib/systemd/system/runlevel1.target -> rescue.target lrwxrwxrwx. 1 root root 17 7月 5 00:45 /lib/systemd/system/runlevel2.target -> multi-user.target lrwxrwxrwx. 1 root root 17 7月 5 00:45 /lib/systemd/system/runlevel3.target -> multi-user.target lrwxrwxrwx. 1 root root 17 7月 5 00:45 /lib/systemd/system/runlevel4.target -> multi-user.target lrwxrwxrwx. 1 root root 16 7月 5 00:45 /lib/systemd/system/runlevel5.target -> graphical.target lrwxrwxrwx. 1 root root 13 7月 5 00:45 /lib/systemd/system/runlevel6.target -> reboot.target
修改默認(rèn)啟動(dòng)runlevel為 multi-user (貌似runlevel2 3 4 沒區(qū)別了)
[root@localhost ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target [root@localhost ~]# ll -X /etc/systemd/system/*.target lrwxrwxrwx. 1 root root 37 7月 10 09:42 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target
試試init 6 還好用不。
[root@localhost ~]# init 6 Connection to 192.168.150.180 closed by remote host. Connection to 192.168.150.180 closed.
成,好用。:)
因?yàn)槲覐淖烂姘鍸inux 連接Centos7系統(tǒng)提示變成了中文,所以需要把Centos7 的root用戶語言改一下,回到原汁原味。
[root@localhost ~]# cp .bashrc .bashrc-back [root@localhost ~]# echo 'export LANG="en_Us.UTF-8"' >> /root/.bashrc
二、Services
[root@localhost ~]# chkconfig
Note: 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:off
iprinit 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iprupdate 0:off 1:off 2:on 3:on 4:on 5:on 6:off
livesys 0:off 1:off 2:off 3:on 4:on 5:on 6:off
livesys-late 0:off 1:off 2:off 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rhnsd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vboxadd-x11 0:off 1:off 2:off 3:on 4:off 5:on 6:offSysV已經(jīng)快退居二線了,想配置服務(wù)得用systemctl,先看看默認(rèn)啟動(dòng)的服務(wù)吧。(如果不用grep過濾一下,輸出結(jié)果有260多行)
[root@localhost ~]# systemctl list-unit-files|grep enabled tmp.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
默認(rèn)居然沒有啟動(dòng)sshd,暈!看看監(jiān)聽端口:
[root@localhost ~]# netstat -lntp Active 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,試試?yán)限k法:
[root@localhost ~]# chkconfig sshd on Note: Forwarding request to 'systemctl enable sshd.service'. ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
能用,但是指令被轉(zhuǎn)發(fā)到 systemctl enable sshd.service ,以后控制服務(wù)就用這個(gè)指令了。試試:
禁用sshd:
[root@localhost ~]# systemctl disable sshd.service rm '/etc/systemd/system/multi-user.target.wants/sshd.service'
啟用sshd:
[root@localhost ~]# systemctl enable sshd.service ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
看看:
[root@localhost ~]# systemctl list-unit-files|grep sshd.service anaconda-sshd.service static sshd.service enabled [root@localhost ~]# netstat -lntp Active 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
其實(shí)啟用和禁用服務(wù)就是在當(dāng)前“runlevel”的配置文件目錄(/etc/systemd/system/multi-user.target.wants/)里,
建立/usr/lib/systemd/system 里面對(duì)應(yīng)服務(wù)配置文件的軟鏈接;禁用服務(wù)就是刪除此軟鏈接。
有興趣就自己看看 /usr/lib/systemd/system 里的文件,語法跟舊版/etc/init.d/ 里的服務(wù)腳本完全不同,也不能再用 /etc/init.d/sshd restart 之類的指令啟動(dòng)服務(wù)器了。
先試試舊方法啟動(dòng)服務(wù):
[root@localhost ~]# service sshd start Redirecting 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 ~]#
如果沒有錯(cuò)誤,就不會(huì)輸出任何信息,這個(gè),,,,得習(xí)慣一下。
三、網(wǎng)絡(luò)
setup工具還是保留了,但有區(qū)別,沒有了網(wǎng)絡(luò)配置,多了RHN(Centos到底是跟RedHat一家子了)
[root@localhost ~]# setup
好吧,我們看看網(wǎng)絡(luò)配置。
[root@localhost ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 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 ~]# ifconfig enp0s3: flags=4163mtu 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 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 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 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 ~]#
先改改主機(jī)名:
[root@localhost ~]# echo "hostname cenots7.localdomain" >>/etc/sysconfig/network [root@localhost ~]# reboot Connection to 192.168.150.180 closed by remote host. Connection to 192.168.150.180 closed. xw@Opt9010:~$ ssh root@192.168.150.180 root@192.168.150.180's password: Last login: Thu Jul 10 10:01:09 2014 [root@cenots7 ~]#
看看網(wǎng)卡配置文件:
[root@cenots7 ~]# cd /etc/sysconfig/network-scripts/ [root@cenots7 network-scripts]# cat ifcfg-Auto_Ethernet HWADDR=08:00:27:9A:A6:88 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME="Auto Ethernet" UUID=76304098-8f46-4185-8337-bb7f0d90423e ONBOOT=yes [root@cenots7 network-scripts]# cat ifcfg-enp0s3 HWADDR=08:00:27:9A:A6:88 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=enp0s3 UUID=66a635c2-9600-437b-8cfb-57e9569f68da ONBOOT=no
看看兩個(gè)文件有啥不同:
[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
兩個(gè)文件MAC地址一樣,ifcfg-Auto_Ethernet ONBOOT=yes,但是ifconfig結(jié)果顯示的是enp0s3,有點(diǎn)兒費(fèi)解了。
再看看我復(fù)制KVM虛擬機(jī)時(shí)經(jīng)常要改的網(wǎng)卡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呢?
網(wǎng)卡MAC只在網(wǎng)卡配置文件里有,一旦變了我只需要改網(wǎng)卡配置文件?
[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
改一下網(wǎng)卡MAC 0800279AA688 -> 0800278C3746
改MAC后網(wǎng)卡不認(rèn)了,測(cè)試結(jié)果是只需要改網(wǎng)卡配置文件的MAC,而且兩個(gè)配置文件都要改才行。我順便把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:88 TYPE=Ethernet BOOTPROTO=static IPADDR=192.168.150.180 NETMASK=255.255.255.0 GATEWAY=192.168.150.254 DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=no IPV6_AUTOCONF=no IPV6_DEFROUTE=no IPV6_PEERDNS=no IPV6_PEERROUTES=no IPV6_FAILURE_FATAL=no NAME="Auto Ethernet" UUID=76304098-8f46-4185-8337-bb7f0d90423e ONBOOT=yes [root@cenots7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3 HWADDR=08:00:27:8C:37:46 # HWADDR=08:00:27:9A:A6:88 TYPE=Ethernet BOOTPROTO=static IPADDR=192.168.150.180 NETMASK=255.255.255.0 GATEWAY=192.168.150.254 DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=no IPV6_AUTOCONF=no IPV6_DEFROUTE=no IPV6_PEERDNS=no IPV6_PEERROUTES=no IPV6_FAILURE_FATAL=no NAME=enp0s3 UUID=66a635c2-9600-437b-8cfb-57e9569f68da ONBOOT=no
好吧,這樣初步解決了基礎(chǔ)問題。
當(dāng)前文章:CentOS 7系統(tǒng)配置詳解
本文地址:http://www.dlmjj.cn/article/dpheshj.html


咨詢
建站咨詢
