centos 7的/etc/rc.local无法启动问题分析

本文介绍了CentOS 7的发布时间,并分享了从旧版本升级至CentOS 7的经验,包括对/etc/rc.local文件的注意事项及变更说明。

centos7发布到现在有4年多了,公司项目也被迫需要全部升级到centos7,毕竟互联网项目就是不断的在升级再升级,升到不能升为止!哈哈~~

看看下面的centos发布时间,是不是感觉跟你孩子的年龄一样,对了,忘了还有单身的朋友!

版本

平台

RHEL 版本

发布日期

RHEL 发布日期

2

i386

2.1

2004.05.14

2002.05.17

3.1

i386,x86_64,ia64,s390,s390x

3

2004.03.19

2003.10.23

3.4 - Server CD

i386,x86_64,ia64,s390,s390x

3.4

2005.01.23

-

3.7

i386,x86_64,ia64,s390,s390x

3.7

2006.04.11

-

3.8

i386,x86_64

3.8

2006.08.25

2006.07.20

3.9

i386,x86_64,ia64,s390,s390x

3.9

2007.07.26

2007.06.15

4.0

i386,x86_64,various

4

2005.03.09

2005.02.14

4.6

i386,x86_64,ia64,alpha,s390,s390x,ppc (beta),sparc (beta)

4.6

2007.12.16

2007.11.16

4.7

i386,x86_64,ia64,alpha,s390,s390x

4.7

2008.09.13

2008.07.24

4.7 - Server CD

i386,x86_64,ia64,alpha,s390,s390x

4.7

2008.10.17

-

4.8

i386,x86-64,ia64,alpha,s390,s390x

4.8

2009.08.21

2009.05.18

4.9

i386,x86-64,ia64,alpha,s390,s390x

4.9

2011.03.02

2011.02.16

5.0

i386,x86_64

5

2007.04.12

2007.03.14

5.1

i386,x86_64

5.1

2007.12.02

2007.11.07

5.1 - LiveCD

i386

5.1

2008.02.18

-

5.2

i386,x86_64

5.2

2008.06.24

2008.05.21

5.2 - LiveCD

i386

5.2

2008.07.17

-

5.3

i386,x86_64

5.3

2009.03.31

2009.01.20

5.3 - Live CD

i386

5.3

2009.05.27

-

5.4

i386,x86_64

5.4

2009.10.21

2009.09.02

5.5

i386,x86_64

5.5

2010.05.14

2010.03.31

5.5 - LiveCD

i386,x86-64

5.5

2010.05.14

-

5.6

i386,x86-64

5.6

2011.04.07

2011.01.13

5.7

i386,x86-64

5.7

2011.09.14

-

5.8

i386,x86-64

5.8

2012.03.07

 

5.9

i386,x86-64

5.9

2013.01.17

2013.01.07

5.10 [3] 

i386,x86-64

5.10

2013.10.19

2013.10.01

5.11

i386,x86-64

5.11

2014.09.30

2014.09.16

6.0

i386,x86-64

6

2011.07.04

2010-11-10

6.1

i386,x86-64

6.1

2011.12.10

2011-05-19

6.2

i386,x86-64

6.2

2011.12.20

2011-12-06

6.3

i386,x86-64

6.3

2012.07.10

2012.06.21

6.4

i386,x86-64

6.4

2013.03.08

2013.02.21

6.5 [4] 

i386,x86_64

6.5

2013.12.01

2013.11.21

6.6

i386,x86_64

6.6

2014.10.27

2014.10.28

7.0 [2] 

x86_64,armv7hl

7.0

2014.07.07

2014.06.11

7.1

x86_64

7.1

2015.03.31

2015.03.05

7.2

x86_64

7.2

2015.12.15

2015.12.15

7.3

x86_64

7.3

2016.12.12

2016.11.03

7.4

x86_64

7.4

2017.09.13

2017.08.01

    [root@mcuhome ~]# uname -a
    Linux mcuhome.us-west-1.compute.internal 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    首先看一下/etc/rc.local文件内容
    [root@mcuhome logs]# more /etc/rc.local 
    #!/bin/bash
    # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
    #
    # It is highly advisable to create own systemd services or udev rules
    # to run scripts during boot instead of using this file.
    #
    # In contrast to previous versions due to parallel execution during boot
    # this script will NOT be run after all other services.
    #
    # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
    # that this script will be executed during boot.
    touch /var/lock/subsys/local
    /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
    注意“Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure”
    
    [root@mcuhome ~]# ll /etc/rc.local 
    lrwxrwxrwx. 1 root root 13 5月   2 2017 /etc/rc.local -> rc.d/rc.local
    您在 /var/spool/mail/root 中有新邮件
    [root@mcuhome ~]# ll /etc/rc.d/rc.local 
    -rw-r--r--. 1 root root 811 3月   7 10:37 /etc/rc.d/rc.local
    [root@mcuhome logs]# chmod +x /etc/rc.d/rc.local
    [root@mcuhome logs]# ll /etc/rc.d/rc.local 
    -r-xr-xr-x 1 root root 531 5月  28 14:47 /etc/rc.d/rc.local

    看样子是版本的变迁,/etc/rc.local /etc/rc.d/rc.local正在弃用的路上。

    看了readme才是最好的document啊!

<think>好的,我现在需要帮助用户在CentOS系统中通过编辑/etc/rc.local文件来添加一行ulimit -SHn 65535。首先,我应该回忆一下/etc/rc.local的作用,这个文件通常用于在系统启动时执行用户自定义的命令。不过,在某些较新的系统版本中,这个文件可能默认没有执行权限,或者服务可能被禁用,所以需要确保该服务已经启用。 接下来,用户想要设置ulimit的数值,具体是同时设置软限制和硬限制为65535。ulimit用于控制shell及其启动进程的资源限制,-H表示硬限制,-S表示软限制,n代表打开文件描述符的数量。正确性方面,需要确认这个值是否合理,通常65535是一个较高的数值,但需要确保系统内核允许,可能需要检查/etc/security/limits.conf或者sysctl的fs.file-max参数。 然后,我需要考虑在CentOS中如何正确配置/etc/rc.local。首先检查该文件是否存在,如果不存在可能需要创建。然后,确保文件有可执行权限,否则即使添加了命令也不会执行。此外,CentOS 7之后可能使用systemd,所以需要确认rc-local服务是否启用,可能需要创建相应的服务文件。 步骤可能包括: 1. 创建或编辑/etc/rc.local文件,添加ulimit命令。 2. 赋予执行权限chmod +x /etc/rc.local。 3. 启用rc-local服务,确保它在启动时运行。 4. 检查配置是否正确,比如是否有语法错误,服务是否正常启动。 5. 验证ulimit是否在启动后生效,可以通过重启后检查ulimit -n的值。 需要注意的问题可能有: - 用户权限问题,确保命令以root执行。 - systemd服务配置是否正确,可能需要创建服务单元文件。 - 检查是否有其他服务或配置覆盖了ulimit设置,比如在/etc/security/limits.conf中设置。 - 系统重启后验证是否生效,避免配置错误导致不生效。 另外,可能还需要考虑替代方法,比如直接在/etc/security/limits.conf中设置nofile的值,或者在systemd的服务文件中设置LimitNOFILE,但用户明确要求使用/etc/rc.local,所以需要按照用户的方法进行指导。 最后,总结步骤,确保用户能够正确添加命令,处理权限和服务启用的问题,并验证配置是否生效。</think>以下是在CentOS系统中通过`/etc/rc.local`设置`ulimit -SHn 65535`的完整操作指南: --- ### 一、操作背景 通过修改`/etc/rc.local`实现开机自动设置文件描述符限制(`nofile`),适用于: 1. CentOS 6及早期版本(原生支持`rc.local`) 2. CentOS 7/8等新版系统(需手动启用`rc-local`服务) --- ### 二、操作步骤 #### 1. 编辑 `/etc/rc.local` 文件 ```bash sudo vim /etc/rc.local ``` 在文件末尾 `exit 0` **之前**添加: ```bash # 设置所有用户的文件描述符限制 ulimit -SHn 65535 ``` #### 2. 赋予执行权限CentOS 7+必须) ```bash sudo chmod +x /etc/rc.local ``` #### 3. CentOS 7+ 需启用`rc-local`服务 ```bash # 创建服务定义文件(若不存在) sudo tee /etc/systemd/system/rc-local.service <<EOF [Unit] Description=/etc/rc.local ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target EOF # 重新加载systemd并启用服务 sudo systemctl daemon-reload sudo systemctl enable rc-local sudo systemctl start rc-local ``` #### 4. 验证是否生效 ```bash # 重启系统后执行 ulimit -n # 预期输出(需root用户查看) 65535 ``` --- ### 三、替代方案(推荐) 若`rc.local`配置无效,可通过以下方式实现更稳定的限制设置: #### 1. 修改系统全局限制 ```bash sudo vim /etc/security/limits.conf ``` 添加以下内容: ```conf * soft nofile 65535 * hard nofile 65535 ``` #### 2. 修改systemd服务默认限制 ```bash sudo vim /etc/systemd/system.conf ``` 修改以下参数: ```conf DefaultLimitNOFILE=65535 ``` 执行: ```bash sudo systemctl daemon-reexec ``` --- ### 四、注意事项 1. **权限问题**:`/etc/rc.local`必须由`root`执行 2. **生效范围**:`rc.local`中的`ulimit`仅影响通过该脚本启动的进程 3. **内核限制**:需确保不超过系统最大限制: ```bash # 查看系统级限制 cat /proc/sys/fs/file-max # 临时修改最大值 sudo sysctl -w fs.file-max=65535 # 永久修改 echo "fs.file-max=65535" | sudo tee -a /etc/sysctl.conf ``` --- ### 五、故障排查 ```bash # 查看rc-local服务日志 journalctl -u rc-local # 检查实际生效值 cat /proc/$(pidof your_service)/limits | grep 'Max open files' ``` 建议优先使用`/etc/security/limits.conf`或`systemd`配置实现更可靠的文件描述符限制管理。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值