最近几天在部署SSM+Vue项目在阿里云,磕磕碰碰终于把基本配置准备完毕!
做个总结以备以后查阅;
1.前期准备阿里云服务器ECS(我使用CentOS 8.0)
2.使用FileZilla连接阿里云服务器(如果直接连接不成功,可使用密钥对来连接,安装方式个人博客已记录)
3.在Linux中先安装JDK,vim /etc/profile
中配置好Java环境
export JAVA_HOME=/user/develop/jdk/jdk1.8.0_241
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
4.接着Linux中安装多个Tomcat(细节问题耽误我很多时间)
1.server80和server90各有一个Tomcat
2.在/etc/profile文件下进行修改配置,添加两组CATALINA环境变量如下:
命令:vim /etc/profile
export JAVA_HOME=/user/develop/jdk/jdk1.8.0_241
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export CATALINA_BASE=/user/develop/tomcat/server90/apache-tomcat-9.0.31
export CATALINA_HOME=$CATALINA_BASE
export TOMCAT_HOME=$CATALINA_BASE
export CATALINA_2_BASE=/user/develop/tomcat/server80/apache-tomcat-9.0.31
export CATALINA_2_HOME=$CATALINA_2_BASE
export TOMCAT_2_HOME=$CATALINA_2_BASE
注意:第二个CATALINA的名字不一致
3.配置完成后使配置即时生效:
命令: source /etc/profile
4.需要把第二个Tomcat的两个端口,都在tomcat 中 conf/server.xml
下修改:
见截图:
第一个位置:
修改SHUTDOWN远程停服务端口为8006(默认为8005端口)<Server port="8006" shutdown="SHUTDOWN">
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8006" 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" />
第二个位置:
修改连接默认8080端口为80
<!-- 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
-->
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
5.最后我们需要配置第二个tomcat的catalina.sh,找到下面这行代码
# OS specific support. $var _must_ be set to either true or false.
,在下面增加代码
# OS specific support. $var _must_ be set to either true or false.
export CATALINA_BASE=$CATALINA_2_BASE
export CATALINA_HOME=$CATALINA_2_HOME
cygwin=false
darwin=false
os400=false
hpux=false
这里引入的CATALINA_BASE
和CATALINA_HOME
值需要跟之前 /etc/profile中配置的Tomcat名字需要一一对应,不配置这个默认使用$CATALINA_HOME和$CATALINA_BASE
然后需要给第二个tomcat/bin/catalina.sh
文件赋可执行权限
命令:chmod 777 catalina.sh
不然会报如下错误:
The file is absent or does not have execute permission This file is needed to run this program
在阿里云中实例中添加安全组90和80端口
最后分别启动两个tomcat中bin/startup.sh运行命令
网页打开效果为:80和:90端口
二、增加管理角色
在tomcat的用户配置当中定义,操作的配置文件为tomcat-users.xml,对于下载安装的tomcat而言,配置文件在tomcat路径下的conf文件夹中。对于在线安装的tomcat而言配置文件在路径/etc/tomcat中。 对于tomcat-users.xml文件,我们只是需要在tomcat-users节点中添加role 和 user 节点。
修改之后的xml文件内容如下所示
<!-- <role rolename="admin"/> -->
<!-- <role rolename="admin-gui"/> -->
<!-- <role rolename="admin-script"/> -->
<!-- <role rolename="manager"/> -->
<!-- <role rolename="manager-gui"/> -->
<!-- <role rolename="manager-script"/> -->
<!-- <role rolename="manager-jmx"/> -->
<!-- <role rolename="manager-status"/> -->
<!-- <user name="admin" password="adminadmin" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" /> -->
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>
</tomcat-users>
还需要去
apache-tomcat-9.0.29\webapps\manager\META-INF
路径下设置context.xml
将Value className注释即可
<Context antiResourceLocking="false" privileged="true" >
<!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>