linux下安裝apache與配置tomcat. 超詳細分享.,apachetomcat

來源:互聯網
上載者:User

linux下安裝apache與配置tomcat. 超詳細分享.,apachetomcat

以下就是我在 Red hat enterprise linux5 環境中安裝apache的詳細過程.  基本複製黏貼命令進行執行即可.

 

下載 httpd-2.4.10.tar.gz,apr-1.5.1.tar.gz,apr-util-1.5.4.tar.gz,pcre-8.36.zip,tomcat-connectors-1.2.40-src.tar.gz

或瀏覽我的資源. apache_all.zip. 不需要資源分.

比如我預設放到 /Software下. 則進入這個目錄開始.


 
安裝 apr
# tar -zxf apr-1.5.1.tar.gz
# cd  apr-1.5.1
# ./configure --prefix=/usr/local/apr 
# make && make install


安裝 APR-util
# tar -zxf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config 
# make && make install


安裝pcre
#unzip -o pcre-8.36.zip
#cd pcre-8.36 
#./configure --prefix=/usr/local/pcre 
#make && make install

安裝apache 
# tar -zxf httpd-2.4.10.tar.gz
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache2 --enable-so --with-apr=/usr/local/apr --with-included-apr  --with-apr-util=/usr/local/apr-util/  --with-pcre=/usr/local/pcre
# make && make install


注意:
使用 --with-included-apr 參數可能會報 configure: error: Bundled APR requested but not found at ./srclib/.錯誤
需複製 apr 和apr-util 到httpd裡面.
#cd ..
#cp -rf ./apr-1.5.1  ./httpd-2.4.10/srclib/apr
#cp -rf ./apr-util-1.5.4  ./httpd-2.4.10/srclib/apr-util
保守起見,可先執行 #make clean 再重新編譯安裝.

編譯產生mod_jk。
# tar xzvf tomcat-connectors-1.2.40-src.tar.gz
# cd tomcat-connectors-1.2.40-src/native
# ./configure --with-apxs=/usr/local/apache2/bin/apxs
# make
# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/


進入 /usr/local/apache2/conf/ 修改apache設定檔. 這裡是使用tomcat worker的模式.方便進行叢集,添加和修改.
對於單一的應用. 可直接使用proxy模式. 進行轉寄. 怎麼配置proxy這裡就不詳述了.
準備建立三個設定檔mod_jk.conf , jk.conf, workers.properties。

添加 mod_jk.conf
#mod_jk.conf start
#指出mod_jk模組工作所需要的工作檔案workers.properties的位置
JkWorkersFile /usr/local/apache2/conf/workers.properties

# Where to put jk logs
JkLogFile /usr/local/apache2/logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
#mod_jk.conf end

添加worker.properties
worker.list = tomcatGdxr,tomcatSdw

# ------------------------
# First tomcat server
# ------------------------
worker.tomcatGdxr.port=8009
worker.tomcatGdxr.host=localhost
worker.tomcatGdxr.type=ajp13


##添加 jk.conf
<VirtualHost *:80>
  ServerName gdxinrong.cn 此處為你的網站網域名稱.
  ServerAlias   www.gdxinrong.cn 網域名稱別名.
  JkMount /* tomcatGdxr
</VirtualHost>


編輯httpd.conf #vi httpd.conf
找到LoadModule列表...如:
LoadModule alias_module modules/mod_alias.so
預設應該是這個位置: #LoadModule rewrite_module modules/mod_rewrite.so

在後面加入:
LoadModule jk_module modules/mod_jk.so
Include /usr/local/apache2/conf/mod_jk.conf
Include /usr/local/apache2/conf/jk.conf

修改你tomcat的server.xml,注意連接埠衝突. apache預設使用80連接埠.
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!--添加或修改Engine一行.-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatGdxr" >

 

其他:
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
它的意思是說:需要下載apr和apr-utils並解壓到 ./srclib/ 目錄下, 再進行編譯。
view source?
1
cd /usr/local/src  #源碼包統一放到此目錄
2
wget -c http://apache.etoak.com/apr/apr-util-1.4.1.tar.gz
3
wget -c http://apache.etoak.com/apr/apr-1.4.6.tar.gz
4
 
5
tar -xzvf ./apr-1.4.6.tar.gz
6
tar -xzvf ./apr-utli-1.4.1.tar.gz
7
cp -rf ./apr-1.4.6  ./httpd-2.4.6/srclib/apr
8
cp -rf ./apr-util-1.4.6  ./httpd-2.4.6/srclib/apr-util
#重新執行 configure 命令,
偶爾會出現 重新make&&make install 也失敗的情況. 可試一下先執行 make clean. 清除已編譯的對象.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.