Mac os x 10.9 mavericks安装Tomcat

Standard

用mac搭建服务器环境,apache使用苹果server软件自带的,所以第一个问题就是安装tomcat。参考以下这篇文章,然后增加了一些配置用户名和密码等的内容。我自己已经有了java开发环境,所以是从下载tomcat步骤开始的,下载的版本是7.0.53而不是文章中的7.0.49,中文版已经针对版本号进行修改。

如果头疼不想看英文,可以跳到最后,有我的中文精简版,从安装tomcat开始,到配置管理用户名和密码结束。不过出于对原作的尊重,还是将原作放在前面。

—————–

Installing Tomcat 7.0.x on OS X

by  | Dec 14, 2013 | Mac OS X

While Tomcat 8 is close to be released (Tomcat 8.0.0-RC5 (alpha) is released already), Tomcat 7 was the first Apache Tomcat release to support the Servlet 3.0, JSP 2.2, and EL 2.2 specifications. Please note that Tomcat 7 requires Java 1.6 or better, which shouldn’t be a problem, if you are running OS X 10.5 or 10.6.

On OS X 10.7, 10.8 (Mnt Lion), and 10.9 (Mavericks) however, Java is not installed anymore, at least not initially. The easiest way to get Java onto your Mac is probably to open the Terminal app and enter java. You will be asked if you want to install it and OS X takes care of the rest – you would end up with Java 6.

Prerequisite: Java

On 10.9 (Mavericks), Apple changed this once again, now sending you to Oracle’s Java SE web page, where you can download the JDK, (currently 7 jdk-7u45-macosx-x64.dmg). While at Oracle, I usually also download the Java SE Development Kit 7 Documentation, allowing me to stay away from their site for many months.

The JDK installer package come in an dmg and installs easily on the Mac; and after opening the Terminal app again,

java -version

now shows something like this:

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

Whatever you do, when opening Terminal and running java -version, you should see something like this, with a version of at least 1.6.x

sudo is a program for Unix-like operating systems, allowing you to run programs with the security privileges of another user (normally the superuser, or root). Since we are creating directories, outside of your home folder, administrator right are required. I.e., when executing sudo you will be asked to enter your password; and your Mac User account needs to be an ‘Admin’ account.

Installing Tomcat

Here are the easy to follow steps to get it up and running on your Mac

  1. Download a binary distribution of the core module: apache-tomcat-7.0.47.tar.gz from here. I picked the tar.gz in Binary Distributions / Core section.
  2. Opening/unarchiving the archive will create a folder structure in your Downloads folder: (btw, this free Unarchiver app is perfect for all kinds of compressed files and superior to the built-in Archive Utility.app)
    ~/Downloads/apache-tomcat-7.0.47
  3. Open to Terminal app to move the unarchived distribution to /usr/local
    sudo mkdir -p /usr/local
    sudo mv ~/Downloads/apache-tomcat-7.0.47 /usr/local
  4. To make it easy to replace this release with future releases, we are going to create a symbolic link that we are going to use when referring to Tomcat (after removing the old link, you might have from installing a previous version):
    sudo rm -f /Library/Tomcat
    sudo ln -s /usr/local/apache-tomcat-7.0.47 /Library/Tomcat
  5. Change ownership of the /Library/Tomcat folder hierarchy:
    sudo chown -R <your_username> /Library/Tomcat
  6. Make all scripts executable:
    sudo chmod +x /Library/Tomcat/bin/*.sh

Instead of using the start and stop scripts, like so:
Last login: Sun Aug 14 15:20:38 on ttys000
wpbookpro:~ wolf$ /Library/Tomcat/bin/startup.sh
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /Library/Java/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
wpbookpro:~ wolf$ /Library/Tomcat/bin/shutdown.sh
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /Library/Java/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
wpbookpro:~ wolf$

—————–

简单地说,就是如果你已经有了java的开发环境,那么你只需要:

1.打开http://tomcat.apache.org/download-70.cgi网站,往下翻一点找到(或者直接点击下面链接):

7.0.53

Please see the README file for packaging information. It explains what every distribution contains.

Binary Distributions的Core部分,下载tar.gz版本;

2.打开并解压这个文件在默认的downloads目录;

3.在terminal终端里依次输入以下命令(会要求你输入密码),请注意将第五行的<your_username>改为你的用户名,例如“Peter”:

sudo mkdir -p /usr/local
sudo mv ~/Downloads/apache-tomcat-7.0.53 /usr/local

sudo rm -f /Library/Tomcat
sudo ln -s /usr/local/apache-tomcat-7.0.53 /Library/Tomcat

sudo chown -R <your_username> /Library/Tomcat

sudo chmod +x /Library/Tomcat/bin/*.sh

至此,安装已经完成。上面创建了一个链接,使得你对tomcat目录的访问变得很方便(/library/tomcat/即可访问);

4.继续在终端输入以下命令以启动tomcat服务:

/Library/Tomcat/bin/startup.sh

如果需要关闭,则输入:

/Library/Tomcat/bin/shutdown.sh

即可。

至此,访问http://localhost:8080即可访问,出现如下界面说明安装成功:

 

 

接下来,这时候你需要配置tomcat的用户名和密码。

1.打开/library/tomcat/conf 目录,找到tomcat-users.xml文件,使用textedit文本编辑器打开,使用以下内容覆盖:

<?xml version=’1.0′ encoding=’utf-8′?>
<tomcat-users>

<role rolename=”tomcat”/>
<role rolename=”role1″/>
<user username=”admin” password=“admin” roles=”manager-gui,manager-script,manager-status,manager-jmx”/>
</tomcat-users>

这个时候你已经创建了一个用户名和密码均为“admin”的最高权限管理员,推荐你将上面的密码部分修改一下。

2.打开http://localhost:8080 然后在页面中点击“状态”、“管理程序”等按钮,输入刚刚设置的用户名和密码即可。

 

接下来,教你最简单的方式不熟自己的网页。

1.进入/library/tomcat/webapps 目录,将目前的ROOT文件夹更改一个名字,例如“ROOT2”;

2.新建一个名为“ROOT”的文件夹,在里面放入你的网站即可。

 

注意:

1*. 可以不创建链接。如果不想创建/library/tomcat的链接或者创建失败,那就不要创建了,将文中所有/library/tomcat的部分均改为/usr/local/apache-tomcat-7.0.53 即可;

2*.如何进入目录?找不到某个目录?请移步Mac os x下的finder技巧一文,学习3、4两点即可。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.