阿里云argusagent的监控客户端的安装脚本
agent_install_necs-1.7.sh
#!/bin/bash
echo "installing"
export LANG=en_US.UTF-8
export LANGUAGE=en_US:
#有些系统下安装后可能没有写文件的权限,导致日志文件写入失败
ulimit -v unlimited
if [[ -z "${VERSION}" ]]; then
VERSION=2.1.56
fi
if [[ -z "${ARGUS_VERSION}" ]]; then
ARGUS_VERSION=3.4.3
fi
if [ -x "$(command -v wget)" ]; then
HAS_WGET=1
echo "will use wget to download"
else
HAS_WGET=0
echo "will use curl to download"
fi
if [[ -z "${CMS_HOME}" ]]; then
CMS_HOME_PREFIX="/usr/local"
if [[ -f /etc/os-release && ! -z "`egrep -i coreos /etc/os-release`" ]];then
CMS_HOME_PREFIX="/opt"
fi
fi
CMS_HOME="${CMS_HOME_PREFIX}/cloudmonitor"
if [[ `uname -m` = "x86_64" ]]; then
ARCH="amd64"
ARGUS_ARCH="linux64"
elif [[ `uname -m` = "aarch64" ]]; then
ARCH="arm"
ARGUS_ARCH="arm64"
else
ARCH="386"
ARGUS_ARCH="linux32"
fi
case `uname -s` in
Linux)
CMS_OS="linux"
;;
*)
echo "Unsupported OS: $(uname -s)"
exit 1
;;
esac
TAR_FILE=cloudmonitor_${ARGUS_ARCH}.tar.gz
DOWNLOAD_PATH=Argus/${ARGUS_VERSION}/${TAR_FILE}
DEST_UPDATE_FILE=${CMS_HOME}/${TAR_FILE}
DEST_BIN_FILE=${CMS_HOME}/bin/argusagent
DEST_START_FILE=${CMS_HOME}/cloudmonitorCtl.sh
#卸载java和goagent
GOAGENT_ELF_NAME=${CMS_HOME}/CmsGoAgent.${CMS_OS}-${ARCH}
if [[ -d ${CMS_HOME} ]] ; then
if [[ -f ${DEST_START_FILE} ]];then
${DEST_START_FILE} stop
fi
if [[ -f ${CMS_HOME}/wrapper/bin/cloudmonitor.sh ]] ; then
${CMS_HOME}/wrapper/bin/cloudmonitor.sh remove;
rm -rf ${CMS_HOME};
fi
if [[ -f ${GOAGENT_ELF_NAME} ]]; then
${GOAGENT_ELF_NAME} stop
rm -rf ${CMS_HOME}
fi
fi
download()
{
OSS_URL="http://cms-download.aliyun.com/$DOWNLOAD_PATH"
echo "${OSS_URL}"
if [[ -z "${CMS_HTTP_PROXY}" ]] ; then
if [[ "${HAS_WGET}" -eq 1 ]]; then
wget -q "$OSS_URL" -O "$DEST_UPDATE_FILE" -t 3 --connect-timeout=2
else
curl -s "$OSS_URL" -o "$DEST_UPDATE_FILE" --retry 3 -m 2
fi
else
if [[ "${HAS_WGET}" -eq 1 ]]; then
wget -e "http_proxy=${CMS_HTTP_PROXY}" -q "$OSS_URL" -O "$DEST_UPDATE_FILE" -t 3 --connect-timeout=2
else
curl -s -x ${CMS_HTTP_PROXY} "$OSS_URL" -o "$DEST_UPDATE_FILE" --retry 3 -m 2
fi
fi
}
mkdir -p ${CMS_HOME}
if [[ "linux" == "${CMS_OS}" ]]; then
chown -R root:root ${CMS_HOME}
fi
download
if [[ ! -f "${DEST_UPDATE_FILE}" ]]; then
echo "download failed: {$DEST_UPDATE_FILE}"
exit 3
fi
#解压
tar xf ${DEST_UPDATE_FILE} -C ${CMS_HOME_PREFIX}
rm -f ${DEST_UPDATE_FILE}
#配置文件拷贝
mkdir -p "$CMS_HOME/local_data/conf"
if [[ -n "${CMS_AGENT_ACCESSKEY}" ]]; then
echo cms.agent.accesskey=${CMS_AGENT_ACCESSKEY} > "${CMS_HOME}/local_data/conf/accesskey.properties"
echo cms.agent.secretkey=${CMS_AGENT_SECRETKEY} >> "${CMS_HOME}/local_data/conf/accesskey.properties"
elif [[ -f accesskey.properties ]]; then
cp accesskey.properties ${CMS_HOME}/local_data/conf
fi
if [ ! -d /etc/cloudmonitor ];then
mkdir /etc/cloudmonitor
fi
#启动agent
chmod +x ${DEST_START_FILE}
${DEST_START_FILE} uninstall
${DEST_START_FILE} install
${DEST_START_FILE} start
#版本检测
ACT_VERSION=`${DEST_BIN_FILE} -v`
if [[ -n "${ACT_VERSION}" ]]; then
echo argusagent v${ACT_VERSION} installed
else
echo argusagent install failed
exit 5
fi
标签:fi,DEST,echo,阿里,FILE,HOME,argusagent,CMS,客户端
From: https://blog.51cto.com/lenglingx/8097440