设为首页 收藏本站
查看: 341|回复: 0

[经验分享] apache+resin+pureftp的虚拟主机和负载均衡

[复制链接]

尚未签到

发表于 2017-1-10 07:50:17 | 显示全部楼层 |阅读模式
apache+resin+pureftp的虚拟主机和负载均衡[原创]
http://www.chinaunix.net 作者:peng  发表于:2009-05-12 13:12:15【发表评论】【查看原文】【Linux讨论区】【关闭】 <!-- 正文begin -->1、前言
  apache+resin来做想来大家都比较熟悉了,一般的配置都是很熟悉的了,我查看了一些论坛上的文章,这方便的文章比较多。在这里,我只要写写apache+resin实现独立的虚拟主机和resin自带的负载均衡。

2、系统和环境:
redhat9 and solaris9
httpd-2.50
resin-3.06
pure-ftpd-1.0.17a.tar.gz
3、安装软件:

3.1、安装apache:

# tar zxvf httpd-2.49.tar.gz
# cd httpd-2.49
# ./configure --prefix=/usr/local/apache2 --enable-so --with-mpm=worker
# make
# make install

3.2、安装resin:

# tar zxvf resin-3.06.tar.gz
# cd resin03.06
# ./configure --prefix=/usr/local/resin --with-apxs=/usr/local/apache2/bin/apxs
# make
# make install

3.3、安装pureftp

# tar zxvf pure-ftpd-1.0.17a.tar.gz 
# cd pure-ftpd-1.0.17a
# ./configure --prefix=/usr/local/pureftpd
   --without-inetd --with-puredb
   --with-cookie --with-throttling
   --with-ratios --with-quotas 
   --with-ftpwho --with-largefile
   --with-welcomemsg
# make
# make install
# mkdir /usr/local/pureftpd/etc

4、配置软件:

目的:用apache和resin做基于域名的虚拟主机,启用resin自身的负载均衡的引擎。resin的负载均衡引擎实际上是可以启动多个java响应进程,通过内部机制来进行负载均衡。

4.1、配置apache:

# vi /usr/local/apache2/conf/httpd.conf
---------------------------------------
 DirctoryIndex index.html index.jsp
 AddDefaultCharset Off
 User nobody
 Group nobody
 NamevirtualHost 211.11.11.11
 <VirtualHost 211.11.11.11:80>;
    ServerAdmin peng.zhang@bj.china.com
    DocumentRoot /data/web/xcity
    ServerName xcity.chinaunix.com
    ErrorLog logs/xcity.chinaunix.com-error_log
    CustomLog logs/xcity.chinaunix.com-access_log common
</VirtualHost>;

<VirtualHost 211.11.11.11:80>;
    ServerAdmin peng.zhang@bj.china.com
    DocumentRoot /data/web/sports
    ServerName sports.chinaunix.com
    ErrorLog logs/sports.chinaunix.com-error_log
    CustomLog logs/sports.chinaunix.com-access_log common
</VirtualHost>;
........
....
# mod_caucho Resin Configuration
#

LoadModule caucho_module /usr/local/apache2/modules/mod_caucho.so

ResinConfigServer 127.0.0.1
---------------------------------------

4.2、配置resin:

# vi /usr/local/resin/conf/resin.conf
----------------------------------------

    <cluster>;
      <srun id="a" host="127.0.0.1" port="6801" index="1"/>;
      <srun id="b" host="127.0.0.1" port="6802" index="2"/>;
      <srun id="c" host="127.0.0.1" port="6803" index="3"/>;
      <srun id="d" host="127.0.0.1" port="6804" index="4"/>;
    </cluster>;

---注解:
(这里面,我用了系统本身的127.0.0.1,绑定了4个端口做伏在均衡。还可以用不同的ip地址和同一端口,来作。例如:
<cluster>;
      <srun id="a" host="211.11.11.11" port="6802" index="1"/>;
      <srun id="b" host="211.11.11.12" port="6802" index="2"/>;
      <srun id="c" host="211.11.11.13" port="6802" index="3"/>;
      <srun id="d" host="211.11.11.14" port="6802" index="4"/>;
    </cluster>;
还有些人,喜欢在apache中设置每一个java进程服务一个虚拟,这里我们不推荐,这样做,就会失去引擎本身的意义。)

<!-- configures the default host, matching any host name -->;
    <host id='xcity.chinaunix.com'>;
      <document-directory>;/data/web/xcity</document-directory>;
     <!-- configures the root web-app -->;
     <web-app id='/'>;
        <!-- adds xsl to the search path -->;
        <class-loader>;
          <simple-loader path="$host-root/xsl"/>;
        </class-loader>;
   <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/>;
      </web-app>;
      </host>;

      <host id='sports.chinaunix.com'>;
      <document-directory>;/opt/web/sports</document-directory>;
      <!-- configures the root web-app -->;
      <web-app id='/'>;
        <!-- adds xsl to the search path -->;
        <class-loader>;
        <simple-loader path="$host-root/xsl"/>;
        </class-loader>;
       <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/>;
      </web-app>;
     </host>;
........
....

--------------------------------------------------

---注:这里面是基于域名的虚拟主机,如果是针对ip的虚拟主机,在<host id='*.*.*.*'>;中,就应该是对应虚拟主机的ip了。也就是说,apache和resin关于虚拟主机的地方要保持一致。还有,在resin中,对于每个虚拟主机所用的web-app目录,其实是相对于她的家目录下的/目录。

4.3、配置pureftp
1、添加用户:
# pure-pw useradd xcityr -f /usr/local/pureftp/etc/ftppasswd -u nobody -g nobody -d /data/web/xcity -m

# pure-pw useradd sports -f /usr/local/pureftp/etc/ftppasswd -u nobody -g nobody -d /data/web/sports -m

   ---注:xcity :ftp用户 
       -f ftppasswd:存放用户密码信息的文件
       -u 用户uid  一般是系统的一个用户,就是你的ftp用户的家目录的用户
       -g 用户组id
       -d 锁定用户在家目录
       -m 使pureftp.d.passwd写进pureftpd.pdb,使更改生效。

*修改用户:
# pure-pw usermod --help

*删除用户:
# pure-pw userdel <login>; [-f <passwd file>;] [-m]

*更改拥护密码:

# pure-pw passwd  <login>; [-f <passwd file>;] [-m]

*查看用户详细内容:

# pure-pw show    <login>; [-f <passwd file>;]

*生成db文件,使密码生效:
# pure-pw mkdb    [<puredb database file>; [-f <passwd file>;]]

*列出所有用户:
# pure-pw list    [-f <passwd file>;]


5、启动脚本:

当系统在solaris下:

apache和resin的启动脚本:
# vi /etc/rc2.d/S99webapp
-------------------------------
/usr/local/resin/bin/httpd.sh -pid srun1.pid -server a start
/usr/local/resin/bin/httpd.sh -pid srun2.pid -server b start
/usr/local/resin/bin/httpd.sh -pid srun3.pid -server c start
/usr/local/resin/bin/httpd.sh -pid srun4.pid -server d start
/usr/local/apache2/bin/apachectl start
--------------------------------

pureftp启动脚本:
--------------------------------
 #!/bin/sh
    
 /usr/local/pureftpd/sbin/pure-ftpd -j -lpuredb:/usr/local/pureftpd/etc/pureftpd.pdb &
-----------------------------------

在linux下,直接放到响应的开机启动等级目录下就ok了。

6、总结
 apache+resin应该是个很好的java应用平台了。实际使用中,还是有很多技巧。看了resin官方论坛的一些资料,说resin3.x以上的版本,对image和html的支持,比apache响应更快。我对此测试过,感觉还是有所欠缺。所以说,在大型一点的发布平台上,还是要apache和resin结合比较好。
  对于resin的负载均衡使用上启动的进程数,我认为还是要根据自己的机器实际情况来考虑的。少了达不到效果,多了会机器系统也是一个负载。个人认为,4个可以作为一个默认的选择来考虑。

声明: 
写文章的时候,参考很多网友资料,如有雷同,不一定纯属巧合。 
以上过程,都是本人亲自测试和使用,但也难保证有书写遗漏,欢迎指出。
本着自由、共享的精神,网友可以任意转贴,转贴时请注明作者、出处。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-326220-1-1.html 上篇帖子: windows下apache开启gzip压缩 加快网页下载速度 下篇帖子: 解决 APMServ5.2.6后apache老启动失败
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表