nginx+tomcat+redis 负载均衡方案
负载均衡需要的软件和jar包
redis-2.4.14.tar.gz
tcl8.5.11-src.tar.gz
nginx-1.2.0.tar.gz
tomcat-redis-session-manager-1.0.jar
commons-pool-1.6-bin.tar.gz
jedis-2.1.0.jar
第一步 先配置tomcat支持redis缓存策略
1.把jar拷贝到 $TOMCAT_HOME/lib/ 下面
2.修改$TOMCAT_HOME/conf/context.xml
在最后加上
<Valve classname="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager classname="com.radiadesign.catalina.session.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60"
/>
第二步 安装redis应用环境
安装redis依赖库
tcl8.5.11-src.tar.gz
tar zxvf tcl8.5.11-src.tar.gz
cd tcl8.5.11/unix
./configure --prefix=/usr \
--enable-threads \
--mandir=/usr/share/man &&
make &&
sed -i \
-e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
-e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \
tclConfig.sh
make install &&
make install-private-headers &&
ln -v -sf tclsh8.5 /usr/bin/tclsh &&
chmod -v 755 /usr/lib/libtcl8.5.so
ln -v -sf tclsh8.5 /usr/bin/tclsh
ldconfig -p |grep 'tcl'
libtcl8.5.so (libc6,x86-64) => /usr/lib/libtcl8.5.so
libtcl8.4.so (libc6,x86-64) => /usr/lib64/libtcl8.4.so
libOpenIPMItcl.so.0 (libc6,x86-64) => /usr/lib64/libOpenIPMItcl.so.0
出现 libtcl8.5.so说明安装成功。
开始安装redis
tar zxvf redis-2.4.14.tar.gz
cd redis-2.4.14
make
make test
make install
echo 1 > /proc/sys/vm/overcommit_memory
sudo -s
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
mkdir -p /usr/local/redis/var
cp redis-server redis-cli redis-benchmark redis-stat /usr/local/redis/bin/
cp redis.conf /usr/local/redis/etc/
vim redis.conf
当前目录redis.conf是redis的配置文件
daemonize no 将no改为redis后台运行
运行/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
./redis-cli是测试客户端脚本(执行这个脚本就可以和redis交互了)
set a b
get a
安装完成
启动toncat 测试 session存储
第三步 安装 nginx
首先安装依赖类库
yum -y install pcre-devel //HTTP rewrite module
yum -y install openssl openssl-devel //HTTP cache module requireslibrary
yum install -y zlib-devel // gzib
安装nginx
./configure --prefix=/usr/local/nginx --without-http_rewrite_module
make make install
配置 vi /usr/local/nginx/conf/nginx.conf
//负载均衡主机列表 默认 权重为1
upstream backend
{
server 192.168.1.246:8080;
server 192.168.1.246:9080;
}
server 配置中添加
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
}
// 测试nginx 配置
sbin/nginx -t
重启nginx
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
over!
redis-2.4.14.tar.gz
tcl8.5.11-src.tar.gz
nginx-1.2.0.tar.gz
tomcat-redis-session-manager-1.0.jar
commons-pool-1.6-bin.tar.gz
jedis-2.1.0.jar
第一步 先配置tomcat支持redis缓存策略
1.把jar拷贝到 $TOMCAT_HOME/lib/ 下面
2.修改$TOMCAT_HOME/conf/context.xml
在最后加上
<Valve classname="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager classname="com.radiadesign.catalina.session.RedisSessionManager"
host="localhost"
port="6379"
database="0"
maxInactiveInterval="60"
/>
第二步 安装redis应用环境
安装redis依赖库
tcl8.5.11-src.tar.gz
tar zxvf tcl8.5.11-src.tar.gz
cd tcl8.5.11/unix
./configure --prefix=/usr \
--enable-threads \
--mandir=/usr/share/man &&
make &&
sed -i \
-e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
-e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \
tclConfig.sh
make install &&
make install-private-headers &&
ln -v -sf tclsh8.5 /usr/bin/tclsh &&
chmod -v 755 /usr/lib/libtcl8.5.so
ln -v -sf tclsh8.5 /usr/bin/tclsh
ldconfig -p |grep 'tcl'
libtcl8.5.so (libc6,x86-64) => /usr/lib/libtcl8.5.so
libtcl8.4.so (libc6,x86-64) => /usr/lib64/libtcl8.4.so
libOpenIPMItcl.so.0 (libc6,x86-64) => /usr/lib64/libOpenIPMItcl.so.0
出现 libtcl8.5.so说明安装成功。
开始安装redis
tar zxvf redis-2.4.14.tar.gz
cd redis-2.4.14
make
make test
make install
echo 1 > /proc/sys/vm/overcommit_memory
sudo -s
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
mkdir -p /usr/local/redis/var
cp redis-server redis-cli redis-benchmark redis-stat /usr/local/redis/bin/
cp redis.conf /usr/local/redis/etc/
vim redis.conf
当前目录redis.conf是redis的配置文件
daemonize no 将no改为redis后台运行
运行/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
./redis-cli是测试客户端脚本(执行这个脚本就可以和redis交互了)
set a b
get a
安装完成
启动toncat 测试 session存储
第三步 安装 nginx
首先安装依赖类库
yum -y install pcre-devel //HTTP rewrite module
yum -y install openssl openssl-devel //HTTP cache module requireslibrary
yum install -y zlib-devel // gzib
安装nginx
./configure --prefix=/usr/local/nginx --without-http_rewrite_module
make make install
配置 vi /usr/local/nginx/conf/nginx.conf
//负载均衡主机列表 默认 权重为1
upstream backend
{
server 192.168.1.246:8080;
server 192.168.1.246:9080;
}
server 配置中添加
{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
}
// 测试nginx 配置
sbin/nginx -t
重启nginx
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
over!
相关推荐
王道革 2020-11-25
wangdonghello 2020-11-03
Langeldep 2020-11-16
chenhualong0 2020-11-16
聚合室 2020-11-16
koushr 2020-11-12
MRFENGG 2020-11-11
guoyanga 2020-11-10
fackyou00 2020-11-10
Orangesss 2020-11-03
dongCSDN 2020-10-31
rainandtear 2020-10-30
Quietboy 2020-10-30
liuyulong 2020-10-29
fansili 2020-10-29
温攀峰 2020-10-23
jackbon 2020-10-19
kaixinfelix 2020-10-04