Mac 下安裝tomcat

賀臣發表於2014-12-04

一. 下載tomcat

  首先要到tomcat官網去下載安裝包,官網下載地址如下:http://tomcat.apache.org/download-70.cgi , 注意請下載飛windows版本。和windows作業系統不一樣,這個裡面沒有令人厭煩的登錄檔。

  將壓縮包解壓到任意一個目錄,我這裡是存放到/ProgramFile/tomcat 目錄下面

 

二. 修改授權

  tomcat中的幾個執行服務程式都是以*.sh結尾的,在執行之前需要授權。開啟終端輸入如下命令:

 

  輸入如下命令:sudo chmod 755 /ProgramFile/tomcat/bin/*.sh

  回車出現要輸入密碼:請輸入本機賬戶密碼

 

三. 啟動tomcat服務

  先使用 cd 命令進入tomcat的bin目錄,命令如下:

  cd /ProgramFile/tomcat/bin/

  啟動服務命令:

  sudo sh startup.sh

  啟動成功,會出現如下結果:

Using CATALINA_BASE:   /ProgramFile/tomcat
Using CATALINA_HOME:   /ProgramFile/tomcat
Using CATALINA_TMPDIR: /ProgramFile/tomcat/temp
Using JRE_HOME:        /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH:       /ProgramFile/tomcat/bin/bootstrap.jar:/ProgramFile/tomcat/bin/tomcat-juli.jar
Tomcat started.

  如果出現如上結果,說明tomcat啟動成功

 

四. tomcat 相關配置的修改

  開啟tomcat中的 /tomcat/conf/tomcat-users.xml 檔案。

<tomcat-users>
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.
-->
<!--
  NOTE:  The sample user and role entries below are wrapped in a comment
  and thus are ignored when reading this file. Do not forget to remove
  <!.. ..> that surrounds them.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="manager"/>
<user username="tomcat" password="root" roles="manager"/>
</tomcat-users>

  預設<role> 都是被註釋的,這裡新增如下:

<role rolename="manager"/>
<user username="tomcat" password="root" roles="manager"/>

  更多配置修改,可以檢視tomcat的相關資料

  這個時候輸入 http://localhost:8080/ 應該就可以訪問了,做java web開發的應該很熟悉,這裡不再討論

 

相關文章