使用的ambari版本为AMBARI-2.4.0.1
环境为centos7.2
问题:安装完ambari-server之后,开机自启动失败
原因:ambari-server的启动脚本有问题
1、开机启动脚本一般在/etc/rc.d/init.d目录下
2、不同的开机启动级别,启动脚本的范围不一样
开机启动级别:
运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动,对应的启动脚本目录rc0.d
运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆,对应的启动脚本目录rc1.d
运行级别2:多用户状态(没有NFS),对应的启动脚本目录rc2.d
运行级别3:完全的多用户状态(有NFS),登陆后进入控制台命令行模式,对应的启动脚本目录rc3.d
运行级别4:系统未使用,保留,对应的启动脚本目录rc4.d
运行级别5:X11控制台,登陆后进入图形GUI模式,对应的启动脚本目录rc5.d
运行级别6:系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动,对应的启动脚本目录rc6.d
开机的时候,如果开机启动级别是3(最常用),那么就执行rc3.d下面的脚本
可以看到,rc3.d下面的脚本实际上是/etc/rc.d/init.d目录下脚本的软连接,相当于执行的是/etc/rc.d/init.d里面的脚本。
3、手动执行ambari-server开机启动脚本,打印调试信息
[root@brms01 rc3.d]# pwd
/etc/rc.d/rc3.d
[root@brms01 rc3.d]# sh -x S95ambari-server
+ VERSION=2.4.0.1-1
+ HASH=8c0e2bdc031b1a36bd90753210313951f5178a93
+ case "$1" in
+++ dirname S95ambari-server
++ cd .
++ pwd
+ SCRIPT_DIR=/etc/rc.d/rc3.d
+++ dirname /etc/rc.d/rc3.d
++ dirname /etc/rc.d
+ export ROOT=/etc
+ ROOT=/etc
++ echo /etc
++ sed 's/\/$//'
+ ROOT=/etc
+ export 'PATH=/etc/usr/lib/ambari-server/*:/usr/local/openssl/bin:/usr/jdk1.8.0_91/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/oracle/112/client/bin:/root/bin:/root/bin:/sbin/:/usr/sbin'
+ PATH='/etc/usr/lib/ambari-server/*:/usr/local/openssl/bin:/usr/jdk1.8.0_91/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/oracle/112/client/bin:/root/bin:/root/bin:/sbin/:/usr/sbin'
+ export AMBARI_CONF_DIR=/etc/etc/ambari-server/conf
+ AMBARI_CONF_DIR=/etc/etc/ambari-server/conf
+ PYTHON_WRAP=/etc/usr/bin/ambari-python-wrap
+ AMBARI_ENV=/etc/var/lib/ambari-server/ambari-env.sh
+ AMBARI_PYTHON_EXECUTABLE=/etc/usr/sbin/ambari-server.py
+ AMBARI_EXECUTABLE=/etc/usr/sbin/ambari-server
+ '[' -z '' ']'
++ readlink /etc/usr/bin/ambari-python-wrap
+ export PYTHON=
+ PYTHON=
+ '[' -a /etc/var/lib/ambari-server/ambari-env.sh ']'
+ '[' -z '' ']'
+ AMBARI_PASSPHRASE=DEV
+ '[' -n /usr/jdk1.8.0_91 ']'
+ export JAVA_HOME=/usr/jdk1.8.0_91
+ JAVA_HOME=/usr/jdk1.8.0_91
+ export AMBARI_PASSPHRASE=DEV
+ AMBARI_PASSPHRASE=DEV
++ -V
++ awk '{print $2}'
++ cut -d. -f1
+ majversion=line
++ -V
++ awk '{print $2}'
++ cut -d. -f2
+ minversion=line
+ numversion=0
+ (( 0 < 26 ))
+ echo 'Need python version > 2.6'
Need python version > 2.6
+ exit 1
可以看到这几个目录和文件的路径其实是错误的
根源是脚本中$ROOT的取值是错误的,看如下的脚本中,在启动、停止、重启ambari-server时,使用的是脚本
- AMBARI_PYTHON_EXECUTABLE=/etc/usr/sbin/ambari-server.py
- AMBARI_EXECUTABLE=/etc/usr/sbin/ambari-server
明显是错误的,正确的应该是:
- AMBARI_PYTHON_EXECUTABLE=/usr/sbin/ambari-server.py
- AMBARI_EXECUTABLE=/usr/sbin/ambari-server
原始的脚本:
#!/usr/bin/env bash
# chkconfig: 345 95 20
# description: ambari-server daemon
# processname: ambari-server
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
### BEGIN INIT INFO
# Provides: ambari-server
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
### END INIT INFO
# /etc/init.d/ambari-server
VERSION="2.4.0.1-1"
HASH="8c0e2bdc031b1a36bd90753210313951f5178a93"
case "$1" in
--version)
echo -e $VERSION
exit 0
;;
--hash)
echo -e $HASH
exit 0
;;
esac
SCRIPT_DIR="$( cd "$( dirname "${
BASH_SOURCE[0]}" )" && pwd )"
export ROOT=`dirname $(dirname $SCRIPT_DIR)`
ROOT=