1. 前言
服务器购置完成之后首先参照腾讯云服务器官方文档,进行系统的选择和安装,我在这里使用的系统是CentOS 6.5,尽量使用生产环境中常用的Linux系统。
2. 环境配置
2.1 配置163服务的yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum clean all
yum makecache
2.2 安装JDK
我在这里选用的JDK版本是1.7.0_80
使用FileZilla将JDK上传至腾讯云服务器
这里提一下关于FileZilla的登录方法
- 主机(H):此处填写你购买的腾讯云服务器的外网IP地址
- 用户名(U):此处填写root
- 密码(W):此处填写root的登录密码,就是你在安装系统时设置的密码
- 端口(P):此处统一填写22
点击快速连接就可以远程登录到腾讯云服务器并进行一些上传下载的操作
将jdk-7u80-linux-x64.tar.gz文件上传到/usr/temp
文件夹下,如果没有'temp'文件夹需要自己新建
将jdk-7u80-linux-x64.tar.gz解压到/usr/java/jdk
文件夹下,如果没有'java'文件夹需要自己新建
tar zxvf jdk-7u80-linux-x64.tar.gz -C /usr/java/jdk
设置环境变量
vi /etc/profile
按'i'键后进行编辑;按'esc'键退出编辑模式后再按':'键然后输入'wq'回车进行保存;
在末尾添加下面设置
# Set Java Environment
export JAVA_HOME=/usr/java/jdk/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
重新编译资源文件
cd /etc
source profile
查看JDK版本信息测试JDK是否安装成功
java -version
2.3 安装MySQL数据库
CentOS 6.5不支持MarriaDB
yum install mysql mysql-server mysql-devel //安装MySQL主程序
service mysqld start //启动MySQL服务
use mysql; //使用MySQL主表
update user set password=PASSWORD('NEW PASSWORD') where user='root'; //修改root密码
flush privileges; //刷新生效
quit;
mysql -u root -p //重新登陆(用新密码)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'NEW PASSWORD' WITH GRANT OPTION; //修改权限可以让达到远程登录的目的
请将NEW PASSWORD换成自己需要的密码
2.4 安装Tomcat服务器
在安装Tomcat服务器之前请自行到Tomcat官网下载apache-tomcat-8.5.9。然后使用FileZilla上传至腾讯云服务器备用。
将下载的apache-tomcat-8.5.9.tar.gz文件上传到了腾讯云服务器的/usr/temp
文件夹下
开始配置Tomcat服务器
- 解压apache-tomcat-8.5.9.tar.gz文件至
/usr/tomcat
文件夹下,如果没有tomcat文件夹需要自己手动创建。
tar zxvf apache-tomcat-8.5.9.tar.gz -C /usr/tomcat
- 设置JDK
cd /usr/tomcat/apache-tomcat-8.5.9/bin
vi setclasspath.sh
按'i'键后进行编辑;按'esc'键退出编辑模式后再按':'键然后输入'wq'回车进行保存;
在末尾添加以下设置:
# Set Java Environment
export JAVA_HOME=/usr/java/jdk/jdk1.7.0_80
export JRE_HOME=/usr/java/jdk/jdk1.7.0_80/jre
- 配置Tomcat服务器
使用FileZilla将/usr/tomcat/apache-tomcat.8.5.9/conf/
文件夹的server.xml文件下载至本地
具体配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="org.apache.catalina.security.SecurityListener" />
-->
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
—>
<!—修改为80端口,可以直接使用IP地址访问网站-->
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation. The default
SSLImplementation will depend on the presence of the APR/native
library and the useOpenSSL attribute of the
AprLifecycleListener.
Either JSSE or OpenSSL style configuration may be used regardless of
the SSLImplementation selected. JSSE style configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
This connector uses the APR/native implementation which always uses
OpenSSL for TLS.
Either JSSE or OpenSSL style configuration may be used. OpenSSL style
configuration is used below.
-->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
maxThreads="150" SSLEnabled="true" >
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
<SSLHostConfig>
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
certificateFile="conf/localhost-rsa-cert.pem"
certificateChainFile="conf/localhost-rsa-chain.pem"
type="RSA" />
</SSLHostConfig>
</Connector>
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<!--设置访问路径-->
<Context path="/admin" docBase="SemiWarmAdmin"/>
<Context path="/api" docBase="SemiWarmAPI"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
- 启动Tomcat服务器
先进入Tomcat服务器的bin目录
cd /usr/tomcat/apache-tomcat-8.5.9/bin
启动Tomcat服务器命令
./startup.sh
停止Tomcat服务器命令
./shutdown.sh
至此服务器环境配置结束,可以在浏览器中输入ip:8080
访问tomcat服务器,出现tomcat首页后就配置成功了。