Ubuntu Server 10.04, resin 3.1.10, nginx-0.7.65 架设负载均衡网站
软件硬件架构
internet -> fire wall -> f5 load balancer -> router -> web servers(ubuntu + nginx + resins) -> db servers(aix + oracle) -> storage
一、安装 Ubuntu
在vitrual box 3.2.4中安装,安装时可断网,这样比较快一点
网络选 bridged adapter
本机地址为192.168.3.31
ubuntu server 地址为3.222
网关3.1
dns 8.8.8.8
用putty做终端,连接
二、修改unbuntu server 网卡
sudo vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.3.222 #ubuntu ip 地址
netmask 255.255.255.0 #子网掩码
# network 192.168.3.0 #可不用配置
# broadcast 192.168.3.255 #可不用配置
gateway 192.168.3.1 #网关
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8 # DNS,多个用半角空格隔开
sudo /etc/init.d/networking restart #启动网卡,终端会断掉
sudo /etc/init.d/networking force-reload #强制加载,这个更好点,终端不会断掉
三、安装JDK
准备工作
sudo vi /etc/apt/sources.list
加入源
deb http://archive.canonical.com/ lucid partner
sudo apt-get update 一定要执行一下
APT: Advanced Packaging Tools
apt-get 其它用法
apt-cache search package 搜索包
apt-cache show package 获取包的相关信息,如说明、大小、版本等
sudo apt-get install package 安装包
sudo apt-get install package - - reinstall 重新安装包
sudo apt-get -f install 强制安装?#"-f = --fix-missing"当是修复安装吧...
sudo apt-get remove package 删除包
sudo apt-get remove package - - purge 删除包,包括删除配置文件等
sudo apt-get update 更新源
sudo apt-get upgrade 更新已安装的包
sudo apt-get dist-upgrade 升级系统
sudo apt-get dselect-upgrade 使用 dselect 升级
apt-cache depends package 了解使用依赖
apt-cache rdepends package 了解某个具体的依赖?#当是查看该包被哪些包依赖吧...
sudo apt-get build-dep package 安装相关的编译环境
apt-get source package 下载该包的源代码
sudo apt-get clean && sudo apt-get autoclean 清理下载文件的存档 && 只清理无用的包
sudo apt-get check 检查是否有损坏的依赖
sudo apt-get install sun-java6-jdk #下载,安装
java -version #检测是否安装成功
sudo vi /etc/profile #配置JAVA_HOME方法一
在最后加入
#jdk1.6 env
JAVA_HOME=/usr/java/jdk1.6.0_20
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/td.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
sudo vi /etc/environment #配置JAVA_HOME方法二(推荐)
# PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
# jdk1.6 env
JAVA_HOME=/usr/lib/jvm/java-6-sun
PATH=$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
CLASSPATH=.:$JAVA_HOME/lib/td.jar:$JAVA_HOME/lib/tools.jar
在putty界面按ctrl+d退出,再进入
echo $JAVA_HOME
四、安装nginx
sudo apt-get install nginx #下载,安装
sudo /etc/init.d/nginx reload|start|stop
sudo vi /etc/nginx/sites-available/default
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts
upstream resin {
# server 192.168.1.103:8080 weight=2;
server 192.168.3.222:8080 weight=2;
server 192.168.3.222:8081 weight=2;
server 192.168.3.31:8080 weight=3;
server 192.168.3.31:8081 weight=3;
}
server {
listen 80 default;
server_name localhost,192.168.3.222;
access_log /var/log/nginx/localhost.access.log;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_pass http://resin;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect false;
}
}
sudo /etc/init.d/nginx reload
访问http://192.168.3.222
五、安装resin
下载resin 3.1.10 free版
http://www.caucho.com/download/
下载后传到/home/root
sudo tar -zxvf resin-pro-3.1.10.tar.gz #解压
sudo mv resin-pro-3.1.10 /usr/local/resin #复制为resin
sudo chmod -R 777 /usr/local/resin #修改权限
cd /usr/local/resin/config
sudo cp resin.conf resin-8080.conf
sudo cp resin.conf resin-8081.conf
修改resin-8081.conf中的端口对应到8081,其他端口依次加1
修改两文件中的web-app节点
在两文件夹中放入测试文件
cd /usr/local/resin/bin
sudo cp httpd.sh httpd-8080.sh
sudo cp httpd.sh httpd-8081.sh
修改其中的最后一行,从
exec $JAVA_EXE -jar ${RESIN_HOME}/lib/resin.jar $*
修改为
exec $JAVA_EXE -jar ${RESIN_HOME}/lib/resin.jar -conf ${RESIN_HOME}/conf/resin-8080.conf $*
exec $JAVA_EXE -jar ${RESIN_HOME}/lib/resin.jar -conf ${RESIN_HOME}/conf/resin-8081.conf $*
加上-conf参数
sudo ./httpd-8080.sh start
sudo ./httpd-8081.sh start
运行成功
将resin 安装为服务
sudo vi /usr/local/resin/contrib/init.resin.in
JAVA_HOME, RESIN_HOME修改为
JAVA_HOME="/usr/lib/jvm/java-6-sun"
RESIN_HOME="/usr/local/resin"
复制为两个文件
sudo cp /usr/local/resin/contrib/init.resin.in /etc/init.d/resin8080
sudo cp /usr/local/resin/contrib/init.resin.in /etc/init.d/resin8081
再分别修改两个文件
sudo vi /etc/init.d/resin8080
sudo vi /etc/init.d/resin8081
修改目标:
CONF="-conf $RESIN_HOME/conf/resin-8080.conf" #这行是加上的,不同的文件CONF不一样
ARGS="-resin-home $RESIN_HOME $SERVER $CONF" #这行后面多加了一个$CONF
sudo update-rc.d/etc/init.d/resin-8080 defaults 99;
sudo service resin-8080 start;
sudo reboot
再访问http://192.168.3.222