[root@iZ94j7ahvuvZ ~]# cd /etc/rc.d/ [root@iZ94j7ahvuvZ rc.d]# cat rc.local #!/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 #./doc/redis-3.0.4/src/redis-server /doc/redis-3.0.4/redis.conf export JAVA_HOME=/usr/local/java/jdk1.7.0 /usr/local/tomcat/apache-tomcat-7.0.62/bin/startup.sh start [root@iZ94j7ahvuvZ rc.d]#
解析rc.local文件
1.配置环境变量
export JAVA_HOME=/usr/local/java/jdk1.7.0 (JDK的安装目录,可以用$echo $JAVA_HOME获取) 以下是我的服务器寻找JAVA_HOME环境变量的方法 [root@iZ94j7ahvuvZ rc.d]# $echo $JAVA_HOME -bash: /usr/local/java/jdk1.7.0: is a directory
2.配置tomcat路径
/usr/local/tomcat/apache-tomcat-7.0.62/bin/startup.sh start
这句话是tomcat的web服务器的startup.sh位置路径 再加上start即可
3.保存文件
按esc然后输入:wq 此刻我们已经保存好rc.local输入的内容了
4.修改rc.local文件为可执行,如:chmod +x rc.local
5.让服务器重启
shutdown -r now
6.开机登录后执行
ps -ef|grep java
看重启后登录是否有java进程 如果有则ok
[root@iZ94j7ahvuvZ rc.d]# ps -ef|grep java
root 1102 1 0 16:19 ? 00:00:04 /usr/local/java/jdk1.7.0/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/apache-tomcat-7.0.62/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/apache-tomcat-7.0.62/endorsed -classpath /usr/local/tomcat/apache-tomcat-7.0.62/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-7.0.62/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat/apache-tomcat-7.0.62 -Dcatalina.home=/usr/local/tomcat/apache-tomcat-7.0.62 -Djava.io.tmpdir=/usr/local/tomcat/apache-tomcat-7.0.62/temp org.apache.catalina.startup.Bootstrap start start
root 1187 1005 0 16:28 pts/1 00:00:00 grep java