下面我将详细介绍在CentOS 6.5系统下配置Tomcat7、Nginx和Redis的方法。
首先确保系统是最新的:
yum update -y
yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel -y
验证安装:
java -version
yum install tomcat7 tomcat7-webapps tomcat7-admin-webapps -y
编辑配置文件:
vi /etc/tomcat7/server.xml
可以修改连接器端口(默认8080)和其他参数。
service tomcat7 start
chkconfig tomcat7 on
验证Tomcat是否运行:
curl http://localhost:8080
首先添加EPEL仓库:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装Nginx:
yum install nginx -y
编辑Nginx配置文件:
vi /etc/nginx/nginx.conf
在http
块中添加以下内容:
upstream tomcat {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://tomcat;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
service nginx start
chkconfig nginx on
验证Nginx是否运行:
curl http://localhost
yum install redis -y
编辑配置文件:
vi /etc/redis.conf
可以修改以下参数:
daemonize yes
bind 127.0.0.1
requirepass yourpassword (可选,设置密码)
service redis start
chkconfig redis on
验证Redis是否运行:
redis-cli ping
# 如果设置了密码
redis-cli -a yourpassword ping
下载Tomcat Redis Session Manager:
wget https://github.com/jcoleman/tomcat-redis-session-manager/releases/download/v2.0.0/tomcat-redis-session-manager-2.0.0.jar
wget http://central.maven.org/maven2/redis/clients/jedis/2.9.0/jedis-2.9.0.jar
wget http://central.maven.org/maven2/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar
将下载的JAR文件放入/usr/share/tomcat7/lib/
目录。
编辑Tomcat的context.xml:
vi /etc/tomcat7/context.xml
在<Context>
标签内添加:
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="localhost"
port="6379"
database="0"
password="yourpassword" <!-- 如果Redis设置了密码 -->
maxInactiveInterval="60" />
重启Tomcat:
service tomcat7 restart
如果启用了防火墙,需要开放相应端口:
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
service iptables save
service iptables restart
http://your-server-ip
应该显示Tomcat页面bash
redis-cli
KEYS *
这样就完成了CentOS 6.5下Tomcat7、Nginx和Redis的配置。根据实际需求,您可能需要进一步调整配置参数。