CentOS设置程序开机自启动的方法 Linux

在CentOS系统下,主要有两种方法设置自己安装的程序开机启动。

1、把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd。

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/apache/bin/apachectl start

2、把写好的启动脚本添加到目录/etc/rc.d/init.d/,然后使用命令chkconfig设置开机启动。

例如:我们把httpd的脚本写好后放进/etc/rc.d/init.d/目录,使用

chkconfig --add httpd
chkconfig httpd on

命令即设置好了开机启动。



admin 发布于  2016-3-25 19:16 

Centos 查看系统启动时间和运行时间小计 Linux

1.uptime命令

uptime

输出:16:11:40 up 59 days, 4:21, 2 users, load average: 0.00, 0.01, 0.00

如下图所示:

01.jpg

2.查看/proc/uptime文件计算系统启动时间

cat /proc/uptime

输出: 5113396.94 575949.85 第一数字即是系统已运行的时间5113396.94 秒,运用系统工具date即可算出系统启动时间

02.jpg

代码:

date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"

输出: 2008-11-09 11:50:31


3.查看/proc/uptime文件计算系统运行时间

代码:

cat /proc/uptime| awk -F. '{run_days=$1 / 86400;run_hour=($1 % 86400)/3600;run_minute=($1 % 3600)/60;run_second=$1 % 60;printf("系统已运行:%d天%d时%d分%d秒",run_days,run_hour,run_minute,run_second)}'

输出:系统已运行:59天4时13分9秒

03.jpg

由于需要测试刚学的shell编程咋样需要用到,就copy过来备份了,原文地址:http://www.centoscn.com/CentOS/help/2013/0731/834.html


admin 发布于  2015-12-13 15:19