CentOS 7系统配置上的变化解析

二、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:off

 

SysV已经快退居二线了,想配置服务得用systemctl,先看看默认启动的服务吧。(如果不用grep过滤一下,输出结果有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

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

[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,试试老办法:

[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'

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

禁用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

 

其实启用和禁用服务就是在当前“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 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 ~]#

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`nohup` 是一个命令行工具,在 Linux 和 Unix 系统上运行程序而不受终端会话退出的影响。当你在后台启动一个程序并挂起它,`nohup` 将确保该进程继续运行,即使你关闭了终端窗口。运行 `nohup` 命令时,程序的所有标准输出、错误输出都将被重定向到名为 `nohup.out` 的文件中。 然而,当出现 `-bash: nohup:: command not found` 错误信息时,通常意味着当前环境下 `nohup` 命令不可用。这可能是由以下几个原因造成的: 1. **未安装 `nohup`**:确保你的系统已经安装了必要的包来支持 `nohup`。这通常包括 GNU 工具集,可以在某些发行版上通过包管理器(如 apt 或 yum)安装。 - 对于 Debian/Ubuntu 用户: ```bash sudo apt-get install util-linux ``` - 对于 Red Hat/CentOS 用户: ```bash sudo yum install sysv-rc-conf ``` 2. **环境变量问题**:有时环境变量可能导致 `nohup` 可见性的问题。尝试将 `nohup` 添加到你的 shell 初始化脚本(如 `.bashrc`, `.zshrc`),然后重启终端会话以应用更改。 3. **路径问题**:检查你的 PATH 环境变量是否包含了包含 `nohup` 所在目录的位置。如果不在 PATH 中,你可以手动指定完整路径来运行 `nohup`,例如: ```bash /usr/bin/nohup your_program > nohup_output.txt & ``` 为了帮助理解,下面是一个使用 `nohup` 运行后台程序的例子,并同时创建输出文件的情况: ```bash nohup your_program > nohup_output.txt & ``` 在这个例子中,`your_program` 是你要运行的程序名称,`nohup_output.txt` 是存储所有输出和错误的日志文件。使用 `&` 符号可以将命令放入后台执行。 --- 相关问题 --- 1. `nohup` 是否支持并发运行多个任务? 2. 使用 `nohup` 后如何停止正在运行的后台程序? 3. `nohup` 是否适用于所有的程序?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值