IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  AIX and UNIX | Linux | WebSphere  >

在 UNIX 和 Linux 系统上安装和配置 WebSphere Application Server

UNIX 和 Linux 是最适合 WebSphere 的平台

developerWorks
前一页第 5 页,共 11 页后一页

文档选项

样例代码


对本教程的评价

帮助我们改进这些内容


启动和停止 WebSphere Application Server

安装 WebSphere Application Server 并不会在系统上启动 WebSphere Application Server 进程。正如前一节提到的,在默认情况下 First steps 控制台在安装过程结束时提供一种马上启动 WebSphere Application Server 的简便方法。但是,在完成安装过程并退出这个控制台之后,这种启动方法就没什么价值了。

本节解释如何手工启动和停止 WebSphere Application Server,以及如何把 WebSphere Application Server 的启动和停止集成在系统的启动和关闭过程中。如果使用 WebSphere Application Server 执行实际工作或长期实验,可能希望在启动系统时自动启动它,在关闭系统时自动关闭它。

WebSphere Application Server 提供一些方便的 UNIX/Linux shell 脚本,它们可以简化从命令行或其他脚本(比如在系统的启动和关闭过程中运行的脚本)启动和停止应用服务器的过程。

启动 WebSphere Application Server

WebSphere Application Server 提供 startServer.sh shell 脚本以简化应用服务器的启动过程。此脚本有一个参数,即要启动的应用服务器的名称。在刚安装 WebSphere Application Server 的系统上,默认的服务器名称是 server1

启动应用服务器的方法是,使用 susudo -s 命令(取决于使用的是 UNIX 系统还是 Linux 发行版)变成安装 WebSphere Application Server 的系统上的特权用户。在出现提示时,分别输入根密码或您的密码。

接下来,输入以下命令启动 WebSphere Application Server:

/opt/IBM/WebSphere/AppServer/bin/startServer.sh server1

在应用服务器启动时,会看到与 图 11 所示的输出窗口相似的输出。当服务器启动过程完成,应用服务器准备好使用时,再次显示命令提示。

系统启动和关闭的集成

在系统上安装应用服务器之后,通常希望在每次重新启动系统时自动启动它。在 Microsoft Windows 等平台上安装 WebSphere Application Server 时,安装过程允许用户把服务器和管理服务器定义为在启动系统时自动启动的 Windows 服务。但是,UNIX 和 Linux 安装程序没有提供相似的启动集成机制。因此,在 UNIX 和 Linux 系统上,必须手工地把 WebSphere Application Server 集成到系统启动过程中。

所有 UNIX 和 Linux 系统都有一系列在系统启动时执行的 shell 脚本(通常称为 init 脚本),通过它们定义应该在启动和关闭过程中执行的任务。在大多数 UNIX 和 Linux 系统上,按照 SysVInit(即 System V Init,这是指 UNIX 的一个老版本)系统启动机制指定的方式组织这些脚本(更多信息请参见 参考资料)。按照这种机制,系统的主要启动脚本都放在 /etc/init.d 中(在某些系统上,此目录可能是 /etc/rc.d/init.d 目录的符号链接)。在系统引导时执行的针对特定操作级(称为 runlevel)的脚本是符号链接,它们把 /etc/rcrunlevel.d 目录中的脚本链接到 /etc/init.d 目录中的脚本。Ubuntu Linux 系统使用另一种与 SysVInit 过程兼容的启动机制,后面一节 解释这种机制。

创建 SysVInit 脚本

为了为 WebSphere Application Server 创建 SysVInit 脚本,可以采用以下方法之一:

  • 下载本教程提供的示例 SysVInit 脚本。
  • 复制并修改现有的 init 脚本,让它执行与 WebSphere Application Server 相关联的进程。

本节的其余部分解释如何下载和使用本教程提供的示例 SysVInit 脚本,见 清单 1


清单 1. 示例 SysVInit 脚本
#!/bin/bash
#
# Simple startup script for IBM WebSphere Application Server
#
# chkconfig: - 85 15
# description: IBM WebSphere Application Server is a powerful \
# middleware platform for connecting Web-based applications and \
# servers.

# Path to the WebSphere startup and shutdown scripts
startscript=/opt/IBM/WebSphere/AppServer/bin/startServer.sh
shutscript=/opt/IBM/WebSphere/AppServer/bin/stopServer.sh
prog="the WebSphere Application Server"
RETVAL=0

# modify the following line as needed to reflect any custom Java
# installation directory
PATH=/opt/IBM/ibm-java-x86_64_60/bin:$PATH

# Function to start the server 
start() {
  echo -n $"Starting $prog: "
  $startscript server1
  RETVAL=$?
  echo
  return $RETVAL
}

# Function to stop the server
stop() {
  echo -n $"Stopping $prog: "
  $shutscript server1 -username ADMINUSER -password PASSWORD
  RETVAL=$?
  echo
  return $RETVAL
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
*)
  echo $"Usage: $0 {start|stop|restart}"
  exit 1
esac

exit $RETVAL

按照以下步骤下载和安装示例 SysVInit 脚本:

  1. 下载示例脚本。
  2. 作为根用户(或通过使用 sudo 命令)把此文件保存到系统上的 /etc/init.d 目录中,把它命名为 websphere_sysvinit.sh
  3. 使用文本编辑器编辑它,把 ADMINUSERPASSWORD 改为 在安装过程中定义的管理用户名和密码 并保存这些修改。
  4. 作为根用户或使用 sudo 命令,使用以下命令设置文件的可执行权限:
    chmod 755 /etc/init.d/websphere_sysvinit.sh
    

  5. 通过使用下面这样的命令,在与系统的默认运行级相关联的目录中创建此文件的符号链接(/etc/rc5.d 目录通常用于图形化系统,/etc/rc3.d 目录用于使用文本控制台的系统):
    ln -s /etc/init.d/websphere_sysvinit.sh /etc/rc5.d/S85ibm-was
    ln -s /etc/init.d/websphere_sysvinit.sh /etc/rc5.d/K15ibm-was
    

在下一次关闭系统时,这里创建的 K15ibm-was 符号链接会在关闭过程中自动停止 WebSphere Application Server。在下一次启动系统时,S85ibm-was 符号链接会在启动过程中自动启动 WebSphere Application Server。

创建 Ubuntu Upstart 脚本

Ubuntu Linux 发行版使用一种与 SysVInit 机制不同的启动机制。Ubuntu 启动机制称为 Upstart(参见 参考资料),这是一种为 Ubuntu 创建的非常新的事件驱动的启动机制,但是 Fedora、Red Hat 和 Centos 等其他发行版也将采用这种机制。Upstart 由于支持并发性和响应系统事件而广受欢迎。

目前,Upstart 的实现与传统的 SysVInit 模型兼容。在 下载 中可以找到一个简单的 Upstart 脚本,可以把它放在系统的 /etc/init.d 目录中并用它启动 WebSphere Application Server。此脚本的代码见 清单 2


清单 2. 示例 Upstart 脚本
#!/bin/bash -e
### BEGIN INIT INFO
# Provides:          ibm-websphere
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop IBM WebSphere Application Server
### END INIT INFO
#
# IBM WAS	This init.d script starts the IBM WebSphere 
#           Application Server.

# modify the following line as needed to reflect any custom Java
# installation directory
ENV="env -i LANG=C PATH=/opt/IBM/ibm-java-x86_64_60/bin:/usr/bin:/bin"

set -e
if [ ! -d /opt/IBM/WebSphere/AppServer/bin ] ; then
	echo "No IBM WebSphere Application Server installed"
	exit 0
fi

. /lib/lsb/init-functions

test -f /etc/default/rcS && . /etc/default/rcS

startscript=/opt/IBM/WebSphere/AppServer/bin/startServer.sh
shutscript=/opt/IBM/WebSphere/AppServer/bin/stopServer.sh

case $1 in
	start)
		log_daemon_msg "Starting application server" "IBM WAS"
		if $startscript ; then
			log_end_msg 0
		else
			log_end_msg 1
		fi
	;;
	stop)
		log_daemon_msg "Stopping application server" "IBM WAS"
		if $stopscript -user was-admin -password PASSWORD; then
			log_end_msg 0
		else
			log_end_msg 1
		fi
	restart)
		log_daemon_msg "Restarting Web server" "IBM HTTP"
		if ($stopscript -user was-admin -password PASSWORD && $startscript)
          then
            log_end_msg 0
		  else
            log_end_msg 1
          fi
	;;
	*)
		log_success_msg "Usage: /etc/init.d/websphere {start|stop|restart}"
		exit 1
	;;
esac

下载此文件之后,执行以下步骤:

  1. 作为根用户或通过 sudo 命令,把此文件保存到系统上并把它复制到 /etc/init.d 中,把它命名为 websphere_upstart.sh
  2. 作为根用户或使用 sudo 命令,使用以下命令设置文件的可执行权限:
    chmod 755 /etc/init.d/websphere_upstart.sh
    

  3. 通过使用下面这样的命令,在与系统的默认运行级相关联的目录(通常是 /etc/rc2.d 目录)中创建此文件的符号链接:
    ln -s /etc/init.d/websphere_upstart.sh /etc/rc2.d/S91ibm-was
    ln -s /etc/init.d/websphere_upstart.sh /etc/rc2.d/K15ibm-was
    

在下一次关闭系统时,这里创建的 K15ibm-was 符号链接会在关闭过程中自动停止 WebSphere Application Server。在下一次启动系统时,S91ibm-was 符号链接会在启动过程中自动启动 WebSphere Application Server。





回页首



前一页第 5 页,共 11 页后一页
    关于 IBM 隐私条约 联系 IBM 使用条款