centos 安装 java7,tomcat7,mysql5.6,mongodb

前端之家收集整理的这篇文章主要介绍了centos 安装 java7,tomcat7,mysql5.6,mongodb前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
chkconfig --list tomcat7

Linux环境为centos6.5

删除centos自带的java5

su到root权限在进行以下操作

一、
新机器,先安装编译需要用到的软件

yum -y install make gcc-c++ cmake bison-devel ncurses-devel gcc autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel*

二、jdk rpm格式
2.1、

rpm -ivh jdk-7u71-linux-x64.rpm


安装目录:/usr/java/jdk1.7.0_71

需手动配置环境变量

export JAVA_HOME=/usr/java/jdk1.7.0_71
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar 

三、tomcat7

3.1 安装
解压:

tar -zxvf apache-tomcat-7.0.56.tar.gz

z : 表示 tar 包是被 gzip 压缩过的,所以解压时需要用 gunzip 解压
x : 从 tar 包中把文件提取出来
v : 显示详细信息
f xxx.tar.gz : 指定被处理的文件是 xxx.tar.gz

解压后,如果嫌文件夹名太长,重命名为tomcat7056:

mv apache-tomcat-7.0.56 tomcat7056

启动tomcat:进入tomcat的bin目录,

bash startup.sh 


停止:

bash shutdown.sh

3.2、设置开机自动启动tomcat7

建tomcat用户,建/home/tomcat文件
赋权限:
chown -R tomcat.tomcat /home/tomcat

在/etc/init.d下vim tomcat7

输入:(注意,***start***和***end***不要输入,JDK和TOMCAT配好)

*********************** start ****************************
#!/bin/bash
# Startup script for the tomcat
# chkconfig: 2345 95 15
# description: tomcat service script
# Source function library.
# . /etc/rc.d/init.d/functions
CATALINA_BASE=/usr/local/tomcat7056;
#export CATALINA_BASE
CATALINA_HOME=/usr/local/tomcat7056;
#export CATALINA_HOME
CATALINA_TMPDIR=/usr/local/tomcat7056/temp;
#export CATALINA_TMPDIR
JRE_HOME=/usr/java/jdk1.7.0_71;
#export JRE_HOME
CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar;
#export CLASSPATH
TOMCAT_HOME=/usr/local/tomcat7056;
#export TOMCAT_HOME
RETVAL=0
checkjava(){
if [ -z "$JAVA_HOME" ]; then
export JAVA_HOME=/usr/java/jdk1.7.0_71
fi
}
start(){
checkjava
checkrun
   if [ $RETVAL -eq 0 ]; then
echo "Starting tomcat"
#su - tomcat -c $TOMCAT_HOME/bin/startup.sh
su - tomcat -c $TOMCAT_HOME/bin/startup.sh
#touch /var/lock/subsys/tomcat
else
echo "tomcat allready running"
fi
}
stop(){
checkjava
checkrun
if [ $RETVAL -eq 1 ]; then
echo "Shutting down tomcat"
su - tomcat -c $TOMCAT_HOME/bin/shutdown.sh
#while [ $RETVAL -eq 1 ]; do
# sleep 5
# checkrun
#done
rm -f /var/lock/subsys/tomcat
else
echo "tomcat not running"
fi
checkrun
}
checkrun(){
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
RETVAL=1
return $RETVAL
else
RETVAL=0
return $RETVAL
fi
}
status(){
checkrun
if [ $RETVAL -eq 1 ]; then
echo -n "Tomcat ( pid "
ps ax --width=1000 | grep "org.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped"
fi
echo "---------------------------------------------"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
# su - tomcat -c "$TOMCAT_HOME/bin/catalina.sh version"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
*********************** end ****************************

然后使文件可执行

chmod +x tomcat7


将tomcat添加到启动服务中

chkconfig --add tomcat7

查看是否配置成功

使其自启动

chkconfig tomcat7 on

手动用service方式启动停止

service tomcat7 start
service tomcat7 stop

猜你在找的CentOS相关文章