Centos7 开启启动nat123

Centos7 开启启动nat123

官方教程添加到启动项里面

  1. 参考: 官方教程地址
  2. sudo find / -name rc.local
    在这里插入图片描述
    2.sudo cd /etc/rc.lcal
    注意: 这里可能不是这个路径,由上面指令查找到为准
  3. sudo vi /etc/rc.lcal

  4. cd /soft/nat123
    mono nat123linux.sh service &
    复制到文件里面
    在这里插入图片描述
  5. sudo shutdown -r now
    重启服务器
  6. 服务器启动后 ps -ef | grep nat
    在这里插入图片描述
    出现 nat123linux.sh service 则启动成功,如果没有则需要修改centos配置

重启不生效解决方案

参考:博客地址

  1. 在centos7之前,都习惯将自己的程序启动命令添加到/etc/rc.local,可是到centos7上面发现不生效了。难道不兼容了?系统默认应该是装了systemd-sysvcompat来兼容sysv的服务的。

  2. rc-local.service

    在centos7上面默认是使用systemd的,所以rc.local这个文件应该也是通过systemd的service启动的,可以在/usr/lib/systemd/system/rc-local.service找到这个service文件,查看里面的内容:

    cat /usr/lib/systemd/system/rc-local.service

     # This file is part of systemd.## systemd is free software;
      you can redistribute it and/or modify it# under the
       terms of the GNU Lesser General Public License as published by# the 
      Free Software Foundation; either version 2.1 of the 
      License, or# (at your option) any later version.#
       This unit gets pulled automatically into multi-user.target by
       # systemd-rc- local-generator if /etc/rc.d/rc.local is executable.
      [Unit]Description=/etc/rc.d/rc.local 		
    

    CompatibilityConditionFileIsExecutable=/etc/rc.d/rc.localAfter
    =network.target[Service]Type=forkingExecStart=/etc/rc.d/rc.lcal startTimeoutSec=0RemainAfterExit=yes

  3. 分析原因

    service是通过ExecStart=/etc/rc.d/rc.local start来启动的,所以这个文件需要有执行权限。可是ls -l 查看到/etc/rc.local是一个软连接连接到当前目录的rc.d/rc.local,接着查看/etc/rc.d/rc.local,发现没有执行权限,那我们就给这个文件执行权限:

    chmod +x /etc/rc.d/rc.local

    开启 rc-local.service 服务:

    systemctl enable rc-local.service

    systemctl start rc-local.service

  4. Systemctl enable rc-loacl.service 不成功?

    systemctl enable rc-local.service

    The unit files have no [Install] section. They are not meant to be enabled

    using systemctl.

    Possible reasons for having this kind of units are:

    1. A unit may be statically enabled by being symlinked from another unit’s

    .wants/ or .requires/ directory.

    1. A unit’s purpose may be to act as a helper for some other unit which has

    a requirement dependency on it.

    1. A unit may be started when needed via activation (socket, path, timer,

    D-Bus, udev, scripted systemctl call, …).

    提示启动service里面没有install这节的内容。那就给它通过多用户的target启动就可以了。

    vim /usr/lib/system/system/rc-local.service

    [Install]

    WantedBy=multi-user.target

    然后再次enable启动服务:

    systemctl enable rc-local.service

    ln -s ‘/lib/systemd/system/rc-local.service’ ‘/etc/systemd/system/multi-user.target.wants/rc-local.service’

  5. systemd还是sysv?

    systemd用起来还是没有sysv顺手,但是个人感觉centos7还是比较推荐让我们自己去写service文件,而不是去添加到rc.local的文件,毕竟添加到这个文件里面,启动就变成了单线程了。如果是自己写service文件可以根据实际情况,跟一些服务并行启动,提升开机速度。个人观点,你觉得是如何呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值