现在很多项目都部署在Linux服务器上运行,现在我以虚拟机为服务器,说一下怎样部署一个项目并运行。
第一步:环境准备
1.1 安装JDK
关于JDK的安装我这里不做详细介绍,大家可以参考:http://blog.csdn.net/u012453843/article/details/52422736这篇博客进行安装
1.2 安装MysqL
关于MysqL的安装,大家可以参考:http://blog.csdn.net/u012453843/article/details/52943779这篇博客进行安装
1.3 安装tomcat
1.3.1 从官网下载tomcat安装包,也可以到:http://download.csdn.net/detail/u012453843/9665789这个地址下载
1.3.2 上传到服务器,这里我上传到我虚拟机的/root/zcms目录下了
1.3.3 解压apache-tomcat-6.0.47.tar.gz
[root@test zcms]# tar -zxvf apache-tomcat-6.0.47.tar.gz
1.3.4 解压后会有一个apache-tomcat-6.0.47文件,我们把它复制到/usr/local目录下并重命名为tomcat
[root@test zcms]# cp -r apache-tomcat-6.0.47 /usr/local/tomcat
1.3.5 设置Tomcat开机自启动,修改rc.local文件,命令行:vim/etc/rc.d/rc.local,在文件末尾加上下面三句话,当然,jdk的版本不同,你要写你jdk的版本。
exportJDK_HOME=/usr/java/jdk1.7.0_80
export JAVA_HOME=/usr/java/jdk1.7.0_80
/usr/local/tomcat/bin/startup.sh
1.3.6 为了方便的手动控制tomcat启动、关闭,我们就需要配置环境变量,让命令在任何目录下都可以执行,下面红色加粗的配置是我们需要配置的内容(JDK是我们第一步就配置好的)。
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
pathmunge /sbin after
fi
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null 2>&1
fi
fi
done
unset -f pathmunge
export JAVA_HOME=/usr/java/jdk1.7.0_80
export TOMCAT_HOME=/usr/local/tomcat
export PATH=$JAVA_HOME/bin:$TOMCAT_HOME/bin:$PATH
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_80
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_80
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
30436 Jps
30404 Bootstrap
[root@test webapps]# ls
docs examples host-manager manager ROOT
[root@test webapps]# rm -rf *
[root@test tomcat]# ls
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[root@test tomcat]# cd conf/
[root@test conf]# ls
Catalina catalina.policy catalina.properties context.xml logging.properties server.xml tomcat-users.xml web.xml
[root@test conf]# vim server.xml
<Connector port=" 80 " protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
bootstrap.jar commons-daemon.jar digest.bat shutdown.bat tomcat-juli.jar version.bat
catalina.bat commons-daemon-native.tar.gz digest.sh shutdown.sh tomcat-native.tar.gz version.sh
catalina.sh cpappend.bat setclasspath.bat startup.bat tool-wrapper.bat
catalina-tasks.xml daemon.sh setclasspath.sh startup.sh tool-wrapper.sh
[root@test bin]# vim catalina.sh
# implementation when JSSE is used. Default is:
# "-Djdk.tls.ephemeralDHKeySize=2048"
#
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process,when start (fork) is used
#
# LOGGING_CONFIG (Optional) Override Tomcat's logging config file
# Example (all one line)
# LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
#
# LOGGING_MANAGER (Optional) Override Tomcat's logging manager
# Example (all one line)
# LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
#
# USE_NOHUP (Optional) If set to the string true the start command will
# use nohup so that the Tomcat process will ignore any hangup
# signals. Default is "false" unless running on HP-UX in which
# case the default is "true"
# -----------------------------------------------------------------------------
JAVA_OPTS="-Xms256m -Xmx512m -Xss1024K -XX:PermSize=128m -XX:MaxPermSize=256m"
cygwin=false
[MysqLd]
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
user=MysqL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
lower_case_table_names=1
default-character-set=utf8
Stopping MysqLd: [ OK ]
Starting MysqLd: [ OK ]
[root@test ~]#
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_80
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
[root@test ~]#
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jdk1.7.0_80
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar
catalina.2016-10-27.log catalina.out host-manager.2016-10-27.log localhost.2016-10-27.log manager.2016-10-27.log
[root@test logs]# more catalina.out
ERROR: 16-10-27 04:58:50 at java.io.FileOutputStream.open(Native Method)
ERROR: 16-10-27 04:58:50 at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
ERROR: 16-10-27 04:58:50 at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[root@test tomcat]# cd logs/
[root@test logs]# tail -f catalina.out 完成:0% 完成:0% 完成:0% 完成:0% 完成:0% 完成:0% 完成:0% 完成:0% 完成:0% URL /platform/environmentalTest.zhtml cost 242ms. INFO: 16-10-27 05:28:03 ZCMS Compile application.zhtml cost 10 ms. URL /application.zhtml cost 260ms. INFO: 16-10-27 05:28:05 ZCMS Compile platform/systemInfo.zhtml cost 30 ms. INFO: 16-10-27 05:28:11 ZCMS Compile platform/environmentalTest.zhtml cost 1 ms.