openssl+apache+tomcat生产机配置

图中??是rose导出后的乱码!应为 "客户"   图中apache代表apache 2.0.55服务,worker为tomcat5.0.30服务,
数字代表机子的IP,如06则代表 192.168.20.6这台机子trans为交易撮合的服务器!


一、openssl-0.9.7i的安装:

#  tar zxvf openssl-0.9.7i.tar.gz
#  cd openssl-0.9.7i
#  ./config --prefix=/usr/local/ssl
#  make
#  make install

编译apache的时候,需要指定ssl的目录:--with-ssl=/usr/local/ssl ,因为它在编译的时候要用到openssl提供的头文件和库。

二、apache 2.0.55的安装:

apahce的安装有几种运行的模式apahce安装默认安装mpm是以prefore这种模式,
像现在我们mobox和ete都是用worker,worker是用进程加线程的模式,所以相对速度也快很多!
#  tar zxvf httpd-2.0.55.tar.gz
#  cd httpd-2.0.55

安装mpm=worker的模式
# cd server/mpm/worker
# vi worker.c

把下面的改为
-----------------------
#define DEFAULT_SERVER_LIMIT 25
#define DEFAULT_THREAD_LIMIT 100
-----------------------
#  ./configure --prefix=/usr/local/apache --enable-so --enable-ssl=static --with-ssl=/usr/local/ssl --enable-mods-shared=all --with-mpm=worker --enable-deflate
#  make
这里如果编译不通过可能是你的缺少相关编译程序:我的系统为基本的GCC加gcc-C++,gcc-gnat,gcc-objc,gcc-gfortran
#  make install
安装的openssl默认是没有编译成动态链接库的,因为其文档说openssl的动态链接库还不成熟,可以使用 ./config shared 编译带动态链接库的openssl,但是还处于试验阶段。
解决这个问题的办法是:将mod_ssl静态的编译到apache里面。(也就是上面的--enable-ssl=static)

三、制作证书

可以用来生成ssl所用到的证书。
现在没有这个工具了,只能自己动手生成了,对证书不熟悉的人,有一个工具可以使用:http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
# cp ssl.ca-0.1.tar.gz /usr/local/apache/conf
# cd /usr/local/apache/conf
# tar zxvf ssl.ca-0.1.tar.gz
# cd ssl.ca-0.1
# ./new-root-ca.sh (生成根证书)
No Root CA key round. Generating one
Generating RSA private key, 1024 bit long modulus
...........................++++++
....++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key: (输入一个密码)
Verifying - Enter pass phrase for ca.key: (再输入一次密码)
......
Self-sign the root CA... (签署根证书)
Enter pass phrase for ca.key: (输入刚刚设置的密码)
........
........ (下面开始签署)
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]:GuangDong//随你喜欢
Locality Name (eg, city) [Sitiawan]:GuangZhou//随你喜欢
Organization Name (eg, company) [My Directory Sdn Bhd]:GDLC//随你喜欢
Organizational Unit Name (eg, section) [Certification Services Division]:GDLC//随你喜欢
Common Name (eg, MD Root CA) []:winson CA//随你喜欢
Email Address []:yu.hanhui@gd-linux.org//随你喜欢
这样就生成了ca.key和ca.crt两个文件,下面还要为我们的服务器生成一个证书:
# ./new-server-cert.sh server (这个证书的名字是server)
......
......
Country Name (2 letter code) [MY]:CN
State or Province Name (full name) [Perak]: GuangDong
Locality Name (eg, city) [Sitiawan]: GuangZhou
Organization Name (eg, company) [My Directory Sdn Bhd]:GDLC
Organizational Unit Name (eg, section) [Secure Web Server]:GDLC
Common Name (eg, www.domain.com) []:localhost
Email Address []:yu.hanhui@gd-linux.org

这样就生成了server.csr和server.key这两个文件。
还需要签署一下才能使用的:
# ./sign-server-cert.sh server
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key: (输入上面设置的根证书密码)
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'JiangSu'
localityName :PRINTABLE:'NanJing'
organizationName :PRINTABLE:'Wiscom System Co.,Ltd'
organizationalUnitName:PRINTABLE:'ACSTAR'
commonName :PRINTABLE:'acmail.wiscom.com.cn'
emailAddress :IA5STRING:'acmail@wiscom.com.cn'
Certificate is to be certified until Jul 16 12:55:34 2005 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK
(如果这里出现错误,最好重新来过,删除ssl.ca-0.1这个目录,从解压缩处重新开始。)
下面要按照ssl.conf里面的设置,将证书放在适当的位置。
# chmod 400 server.key
# cd ..
# mkdir ssl.key
# mv ssl.ca-0.1/server.key ssl.key
# mkdir ssl.crt
# mv ssl.ca-0.1/server.crt ssl.crt
然后就可以启动啦!
# cd /usr/local/apache
# ./bin/apachectl startssl
对于这个提示:
httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
只需要编辑httpd.conf,找到ServerName xxxx这一行,去掉前面的注释即可。

浏览器输入https://192.168.20.50进行测试

四、workers2.properties的配置

在httpd的conf目录下增加workers2.properties内容如下:
[shm]
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
file=anon
size=1048576

# Defines a load balancer named lb. Use even if you only have one machine.
[lb:lb]
#worker=ajp13:worker52
#worker=ajp13:worker06

# Example socket channel, override port and host.
[channel.socket:worker52]
port=8080
host=192.168.20.52

# define the worker
[ajp13:worker52]
channel=channel.socket:worker52
group=lb

[channel.socket:worker06]
port=8080
host=192.168.20.6

# define the worker
[ajp13:worker06]
channel=channel.socket:worker06
group=lb

[channel.socket:worker50]
port=8080
host=192.168.20.50

# define the worker
[ajp13:worker50]
channel=channel.socket:worker50
group=lb
# Map the Tomcat examples webapp to the Web server uri space
#[uri:/examples/*]
#group=lb

[uri:/*.jsp,/*.do]
group=lb

[status:]
info=Status worker, displays runtime information

[uri:/jkstatus/*]
info=The Tomcat /jkstatus handler
group=status:
 
五、整合

1、apache的调整
修改/etc/httpd/conf/httpd.conf文件
LoadModule jk2_module modules/mod_jk2.so
JkSet config.file /usr/local/apache/conf/workers2.properties
<Directory ~ "/WEB-INF/">
     Order allow,deny
     Deny from all
    </Directory>
<VirtualHost * >
#ServerName www.6677.com
DocumentRoot /opt/tomcat/webapps/ROOT
DirectoryIndex index.html index.htm default.htm index.php index.jsp
<Location ~ "/*.do">
JkUriSet worker lb:lb
</Location>
<Location ~ "/*.jsp">
JkUriSet worker lb:lb
</Location>
ErrorLog logs/www.67.com-err_log
CustomLog logs/www.76.com-acc_log common
</VirtualHost>
修改/etc/httpd/conf/ssl.conf文件
增加:
<Location ~ "/*.do">
JkUriSet worker lb:lb
</Location>
<Location ~ "/*.jsp">
JkUriSet worker lb:lb
</Location>
修改:
DocumentRoot "/opt/tomcat/webapps/ROOT"  
2、tomcat的调整
修改conf目录下的jk2.properties
channelSocket.port=8080(原来是注释掉的,注意要与上面的workers2.properties中的相应的worker的端口匹配)
修改conf目录下的server.xml
请自己参考修改:
<!--  <Connector port="80"
               maxThreads="300" minSpareThreads="50" maxSpareThreads="100"
               enableLookups="false" redirectPort="8443" acceptCount="200"
               debug="0" connectionTimeout="20000"
               disableUploadTimeout="true" URIEncoding="gbk" />-->
<Connector port="8080" maxThreads="300" minSpareThreads="50" maxSpareThreads="100"
               enableLookups="false" redirectPort="8443" debug="0"
               protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="localhost" debug="0" jvmRoute="worker50">#worker50注意要与上面的workers2.properties中的相应的worker匹配
修改自己web项目的web.xml
在<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
下增加
    <distributable/>

六、优化

这一步我没什么时间研究,网上很多资料自己找吧! 
我所做的修改是:
增加linux打开文件数:
  # ulimit -a
  # ulimit -n 10000
调整apache
  因为我们是用进程与线程的方式(apache2.0后版本支持)所以修改如下:
  <IfModule worker.c>
StartServers         50
ServerLimit 15000
MaxClients         5000
MinSpareThreads     100
MaxSpareThreads     175
ThreadsPerChild     100
MaxRequestsPerChild  0
</IfModule>
 主要是为了增强并发处理能力(需要按要求与机器配置而定)
调整tomcat
待续.................

七、定时备份

rsync是类unix系统下的数据镜像备份工具,从软件的命名上就可以看出来了——remote sync。它的特性如下: 
1、可以镜像保存整个目录树和文件系统。 
2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。 
3、无须特殊权限即可安装。 
4、优化的流程,文件传输效率高。 
5、可以使用rcp、ssh等方式来传输文件,当然也可以通过直接的socket连接。 
6、支持匿名传输。
一般的linux 系统都自带有这个工具如没有的话,请自行到网上下载安装
配置server端(192.168.20.50)的/etc/rsyncd.conf文件(如没有则新建一个) 
lock file = /var/run/rsync.lock
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
[web]
path = /opt/tomcat/webapps/ROOT/
uid=root
read only = yes
list = no
ignore errors
#auth users = root
secrets file = /etc/inburst.pas
在server端生成一个密码文件/etc/inburst.pas 
zwf:hack345345drghds
出于安全目的,文件的属性必需是只有属主可读。
在server端将rsync以守护进程形式启动
# rsync --daemon 
如果要在启动时把服务起来,有几种不同的方法,比如: 

  a、加入inetd.conf 

    编辑/etc/services,加入rsync   873/tcp,指定rsync的服务端口是873 
    编加/etc/inetd.conf,加入rsync  stream  tcp   nowait  root  /bin/rsync rsync --daemon 

  b、加入rc.local 

    在各种操作系统中,rc文件存放位置不尽相同,可以修改使系统启动时rsync --daemon加载进去。

client端配置
新建一个脚本/root/sync内容为:
rsync -vzrtopg --progress --delete root@192.168.20.50::web /opt/tomcat/webapps/ROOT/
更改文件属性为可执行
#chmod 755 /root/sync
自动镜像
# crontab -e
0,30 * * * *  /root/sync
这样就可以每三十分钟使client端的/opt/tomcat/webapps/ROOT/目录下的文件与server端的rsync共享目录web(/opt/tomcat/webapps/ROOT/)完全同步了


如大家有什么问题或更好的方法,欢迎与我联系:sguzwf@voxbar.com,sguzwf@6677.com,sguzwf@21cn.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值