安装后,一开始有点儿无力吐槽的感觉,变化这么大?
一、Runlevel
首先一条,原来一直用的CentOS-6.5-x86_64-minimal.iso光盘镜像(400M左右无图形系统小巧便捷),而7目前最小的镜像是CentOS-7.0-1406-x86_64-livecd.iso(700M左右),默认安装后是启动图形界面,按原来的习惯要改成启动命令行,结果发现:
[[email protected] ~]# 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
# graphical.target: analogous to runlevel
#
# To set a default target, run:
#
# ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/default.target
#
好吧,systemd一统天下了(它管的东西很多很多,学Centos7首先要搞定systemd)。
[[email protected] ~]# 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都变成什么样了?
[[email protected] ~]# ls -Xl /lib/systemd/system
[[email protected] ~]# ls -Xl /lib/systemd/system/runlevel*.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. root root 7月 : /lib/systemd/system/runlevel6.target -> reboot.target
修改默认启动runlevel为 multi-user (貌似runlevel2 3 4 没区别了)
[[email protected] ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
[[email protected] ~]# 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 还好用不。
[[email protected] ~]# init
Connection to 192.168.150.180 closed by remote host.
Connection to 192.168.150.180 closed.
成,好用。:)
因为我从桌面版Linux 连接Centos7系统提示变成了中文,所以需要把Centos7 的root用户语言改一下,回到原汁原味。
[[email protected] ~]# cp .bashrc .bashrc-back
[[email protected] ~]# echo 'export LANG="en_Us.UTF-8"' >> /root/.bashrc
二、Services
[[email protected] ~]# 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 :off :off :on :on :on :on :off
iprinit :off :off :on :on :on :on :off
iprupdate :off :off :on :on :on :on :off
livesys :off :off :off :on :on :on :off
livesys-late :off :off :off :on :on :on :off
netconsole :off :off :off :off :off :off :off
network :off :off :off :off :off :off :off
rhnsd :off :off :on :on :on :on :off
vboxadd :off :off :on :on :on :on :off
vboxadd-service :off :off :on :on :on :on :off
vboxadd-x11 :off :off :off :on :off :on :off
SysV已经快退居二线了,想配置服务得用systemctl,先看看默认启动的服务吧。(如果不用grep过滤一下,输出结果有260多行)
[[email protected] ~]# 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
默认居然没有启动sshd,晕!看看监听端口:
[[email protected] ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 127.0.0.1: 0.0.0.0:* LISTEN /master
果然没有22,试试老办法:
[[email protected] ~]# 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'
能用,但是指令被转发到 systemctl enable sshd.service ,以后控制服务就用这个指令了。试试:
禁用sshd:
[[email protected] ~]# systemctl disable sshd.service
rm '/etc/systemd/system/multi-user.target.wants/sshd.service'
启用sshd:
[[email protected] ~]# systemctl enable sshd.service
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
看看:
[[email protected] ~]# systemctl list-unit-files|grep sshd.service
anaconda-sshd.service static
sshd.service enabled
[[email protected] ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 127.0.0.1: 0.0.0.0:* LISTEN /master
tcp 0.0.0.0: 0.0.0.0:* LISTEN /sshd
tcp6 ::: :::* LISTEN /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 之类的指令启动服务器了。
先试试旧方法启动服务:
[[email protected] ~]# service sshd start
Redirecting to /bin/systemctl start sshd.service
用新方法折腾一下:
[[email protected] ~]# systemctl start sshd.service
[[email protected] ~]# systemctl stop sshd.service
[[email protected] ~]# systemctl restart sshd.service
[[email protected] ~]#
如果没有错误,就不会输出任何信息,这个,,,,得习惯一下。