linux下的j2ee中间件安装配置方案

nginx  awstats  jdk tomcat  安装配置详细步骤

安装Tomcat和JDK
1、上传apache-tomcat-6.0.18.tar.gz和jdk-6u12-linux-i586.bin至/usr/local
2、执行如下命令安装tomcat:

#cd /usr/local
#tar zxvf apache-tomcat-6.0.18.tar.gz解压完成后将apache-tomcat-6.0.18重命名为tomcat
3、执行如下命令安装JDK

#./jdk-6u12-linux-i586.bin

4、配置环境变量:
编辑/etc下的profile文件,加上如下内容:

JAVA_HOME="/usr/local/jdk1.6.0_12"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin "
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME


5、启动tomcat并输入http://localhost:8080,如果看到猫的页面即tomcat和jdk安装成功


安装nginx(做负载均衡,集群)
1、上传nginx-0.7.63.tar.gz至/usr/local

2、执行如下命令解压nginx:
#cd /usr/local
#tar zxvf  nginx-0.7.63.tar.gz
3、编译安装nginx
#cd nginx-0.7.63
#./configure --with-http_stub_status_module --with-http_ssl_module #启动server状态页和https模块执

行完后会提示一个错误, 说缺少PCRE library 这个是HTTP Rewrite 模块,也即是url静态化的包
可上传pcre-7.9.tar.gz,输入如下命令安装:
#tar zxvf pcre-7.9.tar.gz
#cd  pcre-7.9
#./configure
#make
#make install
安装pcre成功后,继续安装nginx
#cd nginx-0.7.63
#./configure
#make
#make install


配置nginx
nginx的基本配置可知关注一个文件nginx.conf
需要做的几点
a.定义访问日志的写入格式,一般可按默认,直接取消掉log_fromat前面的#即可。
b.配置server,以下是最简单的配置样例
server {
        listen       80;
        server_name  wap0579.cn; #服务的名字。

        #charset koi8-r;

        access_log  logs/access.log  main;  #这里是指定访问日志的存放路径

       
        location / {
                index index.jsp;
                proxy_pass      http://localhost:8080;#这里将要被分发到的tomcat
                proxy_redirect off;
                proxy_set_header  X-Real-IP  $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size 50m;
                client_body_buffer_size 256k;
                proxy_connect_timeout 30;
                proxy_send_timeout 30;
                proxy_read_timeout 60;
                proxy_buffer_size 16k;
                proxy_buffers 4 32k;
                proxy_busy_buffers_size 64k;
                proxy_temp_file_write_size 64k;
        }
       
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
      
    }
c.如果要配置集群,只需稍作改动

# 负载均衡
    upstream servers {
        ip_hash; #做负载均衡的一种分发方式
        # 这里指定多个源服务器,ip:端口,80端口的话可写可不写
        server localhost:8081;
    }

location中需要改为:
proxy_pass http://servers ;



启动nginx
启动
输入:/usr/local/nginx/sbin/nginx 回车,即启动nginx
关闭:
a先查出进程号:ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print$2}'
b.再用kill pid(已查处的进程号)

到这一步,如果tomcat也正常启动了,输入:http://ip/将能够看到tomcat的欢迎页面,说明nginx配置正确



安装awstats(其实这只是解压,无需安装,只需做配置)--分析日志,生成统计页面
wget http://jaist.dl.sourceforge.net/sourceforge/awstats/awstats-6.9.tar.gz
tar zxvf awstats-6.9.tar.gz
mv awstats-6.9  /usr/local/awstats  重命名


配置awstats
1.执行配置向导,在配置过程中输入名称,譬如 www.caituo.net
注意:(
-----> Check for web server install  这项填none。
-----> Define config file name to create  这项填配置文件名字,一般用域名。
其他默认就好。

#/usr/local/awstats/awstats_configure.pl
具体向导中的选项可参看http://pigletshake.blog.sohu.com/111931504.html

2.配置向导执行完成后,默认情况下在/etc/awstats文件夹下找到awstats的主配置文件

awstats.www.caituo.net.conf
如果执行配置向导过程中出错,可删掉/etc/awstats,重新执行#/usr/local/awstats/awstats_configure.pl
3.接下来需要修改awstats.www.caituo.net.conf中的几个参数了
   a. 修改将要被分析的nginx日志源
       LogFile="/usr/local/nginx/logs/access.log"
   b.修改分析结果保存的路径
       DirData="/var/data/awstats"


执行awstats日志分析命令(注意下面的若干参数要修改成对应的)
# /usr/local/awstats/tools/awstats_buildstaticpages.pl -update  \ -config=www.caituo.net -lang=cn

-dir=/var/www/awstats  \
-awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
之后
在-dir=所指定的路径中,将会看到生成的html静态页面
awstats.www.caituo.net.html
注意:如果静态html页面的图标不能正常显示,可查看awstats.www.caituo.net.conf中的DirIcons=""路径,

做相应调整,之后重新执行分析命令。


配置每天分割、分析日志结果。
编写脚本logcron.sh,加入以下命令
#将当前日志转移到另一位置
mv /usr/local/nginx/logs/access.log /usr/local/nginx/logs/nginx_logs/access_$(date -d "yesterday"

+"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid` #重启nginx,重新生成空白的access.log文件
#分析日志输出txt文件
perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -config=www.caituo.net -update
#分析输出html
perl /usr/local/awstats/tools/awstats_buildstaticpages.pl -update -config=www.caituo.net -lang=cn

-dir=/var/www/awstats/ -awstatsprog=/usr/local/awstats/wwwroot/cgi-bin/awstats.pl
#将被分析后的页面压缩
gzip  /usr/local/nginx/logs/nginx_logs/access_$(date -d "yesterday" +"%Y%m%d").log

之后将此脚本加入到自启动任务中


参考文档:
jdk tomcat nginx参考 http://www.jsprun.net/thread-16889-1-1.html,
awstats 参考 http://pigletshake.blog.sohu.com/111931504.html,
           http://hi.baidu.com/%C2%ED%B3%A4%D5%F72008/blog/item/0f1fdca382ab15a4caefd076.html

猜你喜欢

转载自bingyingao.iteye.com/blog/1020381
今日推荐