版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liaoyanyunde/article/details/87258944
使用的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=`echo $ROOT | sed 's/\/$//'`
export PATH=$ROOT/usr/lib/ambari-server/*:$PATH:/sbin/:/usr/sbin
export AMBARI_CONF_DIR=$ROOT/etc/ambari-server/conf
PYTHON_WRAP="$ROOT/usr/bin/ambari-python-wrap"
AMBARI_ENV="$ROOT/var/lib/ambari-server/ambari-env.sh"
AMBARI_PYTHON_EXECUTABLE="$ROOT/usr/sbin/ambari-server.py"
AMBARI_EXECUTABLE="$ROOT/usr/sbin/ambari-server"
if [ -z "$PYTHON" ] ; then
export PYTHON=`readlink $PYTHON_WRAP`
fi
if [ -a "$AMBARI_ENV" ]; then
. "$AMBARI_ENV"
fi
if [ -z "$AMBARI_PASSPHRASE" ]; then
AMBARI_PASSPHRASE="DEV"
fi
if [ -n "$JAVA_HOME" ]; then
export JAVA_HOME=$JAVA_HOME
fi
export AMBARI_PASSPHRASE=$AMBARI_PASSPHRASE
# check for version
majversion=`$PYTHON -V 2>&1 | awk '{print $2}' | cut -d'.' -f1`
minversion=`$PYTHON -V 2>&1 | awk '{print $2}' | cut -d'.' -f2`
numversion=$(( 10 * $majversion + $minversion))
if (( $numversion < 26 )); then
echo "Need python version > 2.6"
exit 1
fi
echo "Using python " $PYTHON
ret=0
case "$1" in
start)
echo -e "Starting ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
stop)
echo -e "Stopping ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
reset)
echo -e "Resetting ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
restart)
echo -e "Restarting ambari-server"
$0 stop
$0 start
;;
upgrade)
echo -e "Upgrading ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
status)
echo -e "Ambari-server status"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
upgradestack)
echo -e "Upgrading stack of ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup)
echo -e "Setup ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-jce)
echo -e "Updating jce policy"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-ldap)
echo -e "Setting up LDAP properties..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
sync-ldap)
echo -e "Syncing with LDAP..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
set-current)
echo -e "Setting current version..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-security)
echo -e "Security setup options..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
refresh-stack-hash)
echo -e "Refreshing stack hashes..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
backup)
echo -e "Backing up Ambari File System state... *this will not backup the server database*"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
restore)
echo -e "Restoring Ambari File System state"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
update-host-names)
echo -e "Updating host names"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
check-database)
echo -e "Checking database"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
enable-stack)
echo -e "Enabling stack(s)..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-sso)
echo -e "Setting up SSO authentication properties..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
db-cleanup)
echo -e "Cleanup database..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
install-mpack)
echo -e "Installing management pack"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
upgrade-mpack)
echo -e "Upgrading management pack"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
*)
echo "Usage: $AMBARI_EXECUTABLE
{start|stop|restart|setup|setup-jce|upgrade|status|upgradestack|setup-ldap|sync-ldap|set-current|setup-security|setup-sso|refresh-stack-hash|backup|restore|update-host-names|enable-stack|check-database|db-cleanup} [options]
Use $AMBARI_PYTHON_EXECUTABLE <action> --help to get details on options available.
Or, simply invoke ambari-server.py --help to print the options."
exit 1
esac
exit $?
4、修改ambari-server开机启动脚本
将$ROOT的取值置为空字符串
修改后的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=`echo $ROOT | sed 's/\/$//'`
ROOT=""
export PATH=$ROOT/usr/lib/ambari-server/*:$PATH:/sbin/:/usr/sbin
export AMBARI_CONF_DIR=$ROOT/etc/ambari-server/conf
PYTHON_WRAP="$ROOT/usr/bin/ambari-python-wrap"
AMBARI_ENV="$ROOT/var/lib/ambari-server/ambari-env.sh"
AMBARI_PYTHON_EXECUTABLE="$ROOT/usr/sbin/ambari-server.py"
AMBARI_EXECUTABLE="$ROOT/usr/sbin/ambari-server"
if [ -z "$PYTHON" ] ; then
export PYTHON=`readlink $PYTHON_WRAP`
fi
if [ -a "$AMBARI_ENV" ]; then
. "$AMBARI_ENV"
fi
if [ -z "$AMBARI_PASSPHRASE" ]; then
AMBARI_PASSPHRASE="DEV"
fi
if [ -n "$JAVA_HOME" ]; then
export JAVA_HOME=$JAVA_HOME
fi
export AMBARI_PASSPHRASE=$AMBARI_PASSPHRASE
# check for version
majversion=`$PYTHON -V 2>&1 | awk '{print $2}' | cut -d'.' -f1`
minversion=`$PYTHON -V 2>&1 | awk '{print $2}' | cut -d'.' -f2`
numversion=$(( 10 * $majversion + $minversion))
if (( $numversion < 26 )); then
echo "Need python version > 2.6"
exit 1
fi
echo "Using python " $PYTHON
ret=0
case "$1" in
start)
echo -e "Starting ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
stop)
echo -e "Stopping ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
reset)
echo -e "Resetting ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
restart)
echo -e "Restarting ambari-server"
$0 stop
$0 start
;;
upgrade)
echo -e "Upgrading ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
status)
echo -e "Ambari-server status"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
upgradestack)
echo -e "Upgrading stack of ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup)
echo -e "Setup ambari-server"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-jce)
echo -e "Updating jce policy"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-ldap)
echo -e "Setting up LDAP properties..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
sync-ldap)
echo -e "Syncing with LDAP..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
set-current)
echo -e "Setting current version..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-security)
echo -e "Security setup options..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
refresh-stack-hash)
echo -e "Refreshing stack hashes..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
backup)
echo -e "Backing up Ambari File System state... *this will not backup the server database*"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
restore)
echo -e "Restoring Ambari File System state"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
update-host-names)
echo -e "Updating host names"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
check-database)
echo -e "Checking database"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
enable-stack)
echo -e "Enabling stack(s)..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
setup-sso)
echo -e "Setting up SSO authentication properties..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
db-cleanup)
echo -e "Cleanup database..."
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
install-mpack)
echo -e "Installing management pack"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
upgrade-mpack)
echo -e "Upgrading management pack"
$PYTHON "$AMBARI_PYTHON_EXECUTABLE" $@
;;
*)
echo "Usage: $AMBARI_EXECUTABLE
{start|stop|restart|setup|setup-jce|upgrade|status|upgradestack|setup-ldap|sync-ldap|set-current|setup-security|setup-sso|refresh-stack-hash|backup|restore|update-host-names|enable-stack|check-database|db-cleanup} [options]
Use $AMBARI_PYTHON_EXECUTABLE <action> --help to get details on options available.
Or, simply invoke ambari-server.py --help to print the options."
exit 1
esac
exit $?