1. 程式人生 > >openssl+apache+tomcat生產機配置

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 []:

[email protected]//隨你喜歡
這樣就生成了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 []:[email protected]

這樣就生成了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:'[email protected]'
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這一行,去掉前面的註釋即可。

四、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 [email protected]::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/)完全同步了


如大家有什麼問題或更好的方法,歡迎與我聯絡:[email protected],[email protected],[email protected]

相關推薦

openssl+apache+tomcat生產配置

圖中??是rose匯出後的亂碼!應為 "客戶"   圖中apache代表apache 2.0.55服務,worker為tomcat5.0.30服務,數字代表機子的IP,如06則代表 192.168.20.6這臺機子trans為交易撮合的伺服器!一、openssl-0.9.7i

Apache Tomcat安裝、配置、啟動與後續操作步驟

文件解壓 相對 ref 自己的 控制臺 應用 為我 。。 start 1.第一,我們在安裝Apache Tomcat之前,我們首先安裝和配置好jdk; 2.第二,我們要清楚自己的jdk版本。因為我們Apache Tomcat配置的成功的前提是版本相對應。在這裏,博主是用下圖

nginx 和 tomcat 生產環境配置 建議和方法

線程鎖 nginx參數 java_opts 持久 maxperm tex 防止 線程 jsp 參考 以下內容: http://blog.csdn.net/lifetragedy/article/details/7708724

apache tomcat ajp的配置

首先mod_proxy 和 mod_ajp_proxy 的配置要放開 <VirtualHost *:80> ServerName localhost DocumentRoot d:/wamp64/www <Directory "d:/wam

Apache Tomcat伺服器安裝配置和部署執行

Apache Tomcat伺服器安裝配置和部署執行 在Windows 64位系統上安裝配置和部署執行Apache Tomcat伺服器。 1,先下載適應於64為Windows作業系統的Tomcat伺服器。 連線:http://tomcat.apache.org/ 我下載的是: 2,

Tomcat 生產環境配置優化

執行模式 Tomcat Connector三種執行模式(BIO, NIO, APR)的比較和優化。 org.apache.coyote.http11.Http11Protocol:BIO org.apache.coyote.http11.Http11NioProtocol

Mac Apache Tomcat WebServer 伺服器配置

1、配置準備工作 1)配置伺服器準備工作 在 Finder 中建立一個 “workspace” 的資料夾,可直接建立在 /Users/QianChia(當前使用者名稱)目錄下。 下載相關軟體

apache+tomcat二級域名配置方法

1、  環境 Apache2.0.43.0 Tomcat 4.1.13 mod_jk-2.0.43 jdk 1.4 Windows 2003 關鍵檔案位置: Server.xml:$tomcat_home\conf Httpd.conf:$apache_home\conf

apache + tomcat動靜分離配置

環境說明 線上環境使用apache+tomcat的形式部署應用程式,前端使用apache監聽80埠,後端使用tomcat部署應用。tomcat的靜態資源響應能力和併發處理能力均不如apache,經測試,apache響應靜態資源的速度比tomcat快10%左右。 因此,有必要

web叢集之一 linux下apache+tomcat負載均衡配置-筆記

負載均衡叢集配置(7):Apache配置——建立workers.properties    httpd.conf的最後新增的配置中workers.properties檔案是不存在的,需要我們自己在apache/conf路徑下建立。workers.properties檔案用於對負載均衡的負載器worker (

Apache+Tomcat+JK叢集配置

轉:http://www.iteye.com/topic/1017961 參考:http://blog.csdn.net/parine26/article/details/4162326 第一步下載安裝apache:http://jingyan.baidu.com/arti

apache tomcat虛擬路徑配置

1.開啟Tomcat\config下的server.xml檔案 2.找到<Host>標籤,在其內部寫入 <Context docBase="F:\java\upload\temp" path="/pic" reloadable="false"/>

ApacheTomcat整合的配置

str windows nec x86 logs info ogr 級別 oca 下載jk連接器地址:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/ 把jk連接器即“m

配置tomcat監聽80端口、配置tomcat虛擬tomcat日誌

classname nginx代理 data restart cal 停止 環境 生產環境 netstat 配置tomcat監聽80端口 tomcat 監聽的是8080端口,如果想要直接訪問,不加8080端口(默認輸入一個IP或者域名,訪問80端口時是可以省略IP後端口號

在Mac系統中安裝及配置Apache Tomcat

class 安裝 配置 span pat body 網址 cat 驗證 1.下載Tomcat http://tomcat.apache.org/download-80.cgi .tar.gz結尾和zip均可 2:解壓至想要的文件下 3:配置(註:輸入路徑自定) 使用終端

eclipse配置apache tomcat執行時訪問路徑不需要專案名稱

問題:tomcat執行專案預設是要帶上專案名的,有時候不想要專案名來訪問,如何解決呢? 方法: 1:雙擊開啟tomcat 2:選擇Modules,選擇你要修改的專案 3:點選Edit,把path修改成空或者你自己想要的路徑即可! 轉載自

eclipse 配置tomcat路徑映射

ast 映射 https bsp 分享 技術 info .net details https://blog.csdn.net/Master_chaoAndQi/article/details/80330513 eclipse 配置tomcat本機路徑映射

Tomcat生產中優化JVM的配置實例

ast ali com 配置 class upa oot pac 實例 root 1208 1 0 11月25 ? 00:15:32 /home/root/jvm/jdk1.7.0_79/bin/java -Djava.util.logging.con

Tomcat生產中優化JVM的配置例項

root 1208 1 0 11月25 ? 00:15:32 /home/root/jvm/jdk1.7.0_79/bin/java -Djava.util.logging.config.file=/home/appuser/tomcat1/conf/logging.properties

配置mysql資料庫連線池錯誤:javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cann

[javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL '