Tomcat

1、设置编码

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true" URIEncoding="UTF-8" /> 

IEncoding="utf-8" URIEncoding="utf-8"

2、CentOS中安装

检查java版本信息

java -version

java version “1.7.0_99”
OpenJDK Runtime Environment (rhel-2.6.5.0.el6_7-x86_64 u99-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

如果没有则安装:

yum -y install java-1.7.0-openjdk

下载并解压缩tomcat
cd /tmp
wget http://www.us.apache.org/dist/tomcat/tomcat-7/v7.0.68/bin/apache-tomcat-7.0.68.tar.gz

http://www-us.apache.org/dist/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gz
(yum -y install wget)
tar xzf apache-tomcat-7.0.68.tar.gz
mv apache-tomcat-7.0.68 /usr/local/tomcat7
启动tomcat
cd /usr/local/tomcat7
./bin/startup.sh
[输出样例]
Using CATALINA_BASE: /usr/local/tomcat7
Using CATALINA_HOME: /usr/local/tomcat7
Using CATALINA_TMPDIR: /usr/local/tomcat7/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.

访问http://ip:8080

重启tomcat服务
# ./bin/shutdown.sh
# ./bin/startup.sh

防火墙开放8080端口:一
增加8080端口到防火墙配置中,执行以下操作:
[root@localhost ~]/sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT #开启8080端口
[root@localhost ~]/etc/rc.d/init.d/iptables save #保存配置
[root@localhost ~]/etc/rc.d/init.d/iptables restart #重启防火墙

防火墙开放8080端口:二

增加8080端口到防火墙配置中,执行以下操作:
[root@admin ~]# vi + /etc/sysconfig/iptables
增加以下代码
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT

重启防火墙
[root@admin java]# service iptables restart

3、查看tomcat日志(类windows控制台): tomcat/logs
tail -f catalina.out

4、设置用户账户

<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>

你可能感兴趣的:(Tomcat)