linux基础--开机自启动
来源:互联网 发布:剑灵人男捏脸数据图 编辑:程序博客网 时间:2024/05/19 17:59
方法一
将自己写好的脚本或命令写入/etc/rc.local文件中。系统会根据该文件来启动所指定的脚本或命令。
下面为httpd服务做了一个启动脚本。
功能:在Linux系统启动时检查httpd服务是否启动成功,如果服务已启动,将日志写入log。如果没有启动,则立即启动httpd服务,并将日志写入log。
[web@info data]$ vi/data/http.sh
#/bin/bash
log_file=/data/http_state.log
echo "">$log_file;
http_status=`netstat-nat|grep 80|awk {print $4}`
port=`echo${http_status:3:3}`;
#echo$port;
if [ "${port}" =="80" ]; then
fi
将写好的脚本加入/etc/rc.local中
[web@infodata]$ echo"/data/http.sh" >>/etc/rc.local;tail -1 /etc/rc.local
/data/http.sh
[web@info data]$ cat /data/http_status.log
http server stop!
[web@info data]$ netstat -nat|grep 80
tcp 0 0:::80 :::* LISTEN
方法二
#chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,6指的是重启,其他为正常启动。80为启动的优先级,
05为关闭的优先级别
#chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,6指的是重启,其他为正常启动。80为启动的优先级,
05为关闭的优先级别
通过启动脚本来创建一个服务,使用chkconfig来指定启动服务的级别,并在ntsysv工具下加载让其自动运行。
[root@info ~]# cp /etc/rc.d/init.d/httpd/etc/init.d/aparche
[root@info ~]# chmod +x /etc/init.d/aparche
[root@info ~]# chkconfig --list aparche
aparche 服务支持chkconfig,但它在任何级别中都没有被引用(运行“chkconfig --add aparche”)
[root@info ~]# chkconfig --add aparche
[root@info ~]# chkconfig --list aparche
aparche 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@info ~]# chkconfig --level 2345 aparche on
[root@info ~]# service aparche start
启动 httpd:httpd: Could not determinethe servers fully qualified domain name, using 127.0.0.1 forServerName
[root@info ~]# ntsysv
lqqqqqqqqqqqqu 服务tqqqqqqqqqqqqk
方法三
在/home/用户/.bash_profile文件中 加入脚本或命令。在.bash_profile中加载的脚本或命令只能以单用户login时启动。并不是在Linux启动时启动。
[root@info ~]# cat /home/web/.bash_profile
# .bash_profile
# Get the aliases andfunctions
if [ -f ~/.bashrc ];then
fi
# User specific environment andstartup programs
PATH=$PATH:$HOME/bin
/usr/sbin/httpd -k start2>&/dev/null
0 0
- linux基础--开机自启动
- linux基础--debian开机自启动脚本
- Linux 开机自启动
- linux开机自启动
- linux开机自启动
- linux 开机自启动
- Linux 开机自启动
- android基础-开机自启动
- linux开机自启动linux
- linux开机自启动项
- linux sshd 开机自启动
- linux 开机自启动设置
- Linux开机自启动程序
- linux mysql 开机自启动
- Linux Svn开机自启动
- linux开机自启动脚本
- Linux Tomcat 开机自启动
- Linux开机自启动服务
- RF
- 剑指Offer15链表中倒数第k个结点
- iOS开-发回收键盘
- 迟到的博客
- hql关联和连接查询实例
- linux基础--开机自启动
- 设置QPushButton的背景图片(或者Window、WindowText等的背景图片/颜色)
- Perl语言学习笔记 14 字符串与排序
- How to Mock Singletons in 3 Simple Ways
- ACM 139. [USACO Feb08] 麻烦的聚餐(dp+递推)
- c语言中调用shell脚本
- POJ—3069—Saruman's Army—【贪心】
- Max Points on a Line
- Codeforces Round #262 (Div. 2)B. Little Dima and Equation