(亲测,可用)
nginx安装********************************
wget http://nginx.org/download/nginx-1.9.8.tar.gz
tar -xvf nginx-1.9.8.tar.gz
进入解压目录,安装到指定目录
./configure --prefix=/usr/local/nginx-1.9.8
如果报错 yum -y install pcre-devel openssl openssl-devel
make
make install
启动nginx,访问测试80端口
cd /usr/local/nginx-1.9.8/sbin
./nginx
配置反向代理(负载均衡)
cd /usr/local/nginx-1.9.8/conf
vi nginx.conf
在server标签上边添加upstream如下(myNginxserver这个是自己随意命名的,下边要用到。)
upstream mynginxserver {
#weight参数表示权重
server 127.0.0.1:8083 weight=1;
server 127.0.0.1:8084 weight=1;
}
#修改server
location / {
#root html;
#index index.html index.htm
proxy_pass http://mynginxserver
}
负载均衡请求分发策略默认安时间顺序,上面配置为根据权重分发,另外还有ip_hash策略+两个安装外部模块的策略
验证nginx配置文件是否正确
./nginx -t
热启动
./nginx -s reload
查找Nginx进程
ps -ef|grep nginx
杀死进程
kill -HUP 进程号
Tomcat下载
上传服务器命令
scp -r /Users/youben/Desktop/shareSoft root@192.168.2.130:/home/youben/resource
解压,重命名
tar -xvf apache-tomcat-7.0.93.tar.gz 或
unzip apache-tomcat-7.0.67.zip
mv apache-tomcat-7.0.67 tomcat_8083
配置session共享(这里介绍在tomcat中进行session复制)
安装redis(参考:虚拟机下各种服务配置)
拷贝tomcat 需要的jar 包到到${TOMCAT_HOME}/lib下(以下其中核心jar视tomcat版本而定,链接是支持tomcat7)
jar包下载链接:https://pan.baidu.com/s/1LbY-SHepGmt9LWUykzQt3A 密码:hq5p
tomcat-redis-session-manager-VERSION.jar
jedis-2.5.2.jar
commons-pool2-2.2.jar
编辑${TOMCAT_HOME}/conf/context.xml,在context中加入
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="192.168.2.130"
port="6379"
database="0"
maxInactiveInterval="60" />
重启两个tomcat,访问Nginx所在80端口即可(亲测可用,针对tomcat集群不多的情形)