一、部署包下载地址
1.百度网盘
链接:https://pan.baidu.com/s/1uYu-RzoL9c8AZa-2PCqgcA
提取码:to74
二、使用方法
tar xvf prometheus_V2.15.tgz
cd install_prom
sudo ./autoinstall.sh
三、部署脚本
#!/bin/bash
#AUTHOR:anqixiang
#DATE:2020-02-15
#MODIFY:
#FUNCTION:部署Prometheus+Grafana+Alertmanager
#VERSION:Prometheus-V2.15 Grafana-V5.3.4 Alertmanager-V0.20
export LC_ALL=en_US.UTF-8
[ `whoami` != "root" ] && echo "######## Please Use root Install......" && exit 71
current_dir=$(cd `dirname $0` && pwd) #当前工作目录
data_dir=/data #数据目录/data
IP=`ip addr |awk '/inet /' |sed -n '2p' |awk -F' ' '{print $2}' |awk -F'/' '{print $1}'`
######################工具函数######################
#$1代表颜色编号,$2代表输出内容
cecho(){
echo -e "\033[$1m$2\033[0m"
}
######################功能函数######################
#安装docker
Install_Docker(){
echo "############ Install_Docker..."
if ! which docker &>/dev/null;then
[ ! -f ${current_dir}/install_docker.sh ] && cecho 31 "install_docker.sh不存在" && exit 71
sed -i "/ExecStart/c ExecStart=/usr/bin/dockerd --graph ${data_dir}/docker_dir -H unix://var/run/docker.sock" ${current_dir}/install_docker.sh #设置doker存储路径为${data_dir}/docker
/bin/bash ${current_dir}/install_docker.sh
else
cecho 96 "docker已安装"
fi
}
#初始化数据卷
Deploy_Init_Data(){
echo "############ Deploy_Init_Data..."
[ ! -d ${data_dir} ] && mkdir -v ${data_dir}
echo "tar xf ${current_dir}/init_data.tgz -C ${data_dir}......"
tar xf ${current_dir}/init_data.tgz -C ${data_dir}
sed -i "s/127.0.0.1/${IP}/g" ${data_dir}/monitor/prometheus/prometheus.yml
sed -i "s/127.0.0.1/${IP}/g" ${data_dir}/monitor/prometheus/sd_config/node.yml
}
#导入镜像
Import_Images(){
echo "############ Import_Images..."
cd ${current_dir}
[ ! -f images.tgz ] && cecho 31 "images.tgz不存在" && exit 71
echo "tar xvf images.tgz......"
tar xvf images.tgz
for i in $(ls images/)
do
docker load < images/${i}
done
rm -rf images/
}
#安装node_exporter
Install_Node_Exporter(){
echo "############ Install_Node_Exporter..."
cd ${current_dir}/soft
tar xf node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 /usr/local/bin/node_exporter
/usr/local/bin/node_exporter/node_exporter &
}
#部署所有服务
Install_All_Service(){
docker volume create grafana_vol #grafana数据持久化
docker run -d -p 9090:9090 --name prometheus --restart=always \
-v ${data_dir}/monitor/prometheus:/etc/prometheus prom/prometheus
docker run -d -p 3000:3000 --name=grafana --restart=always \
-v grafana_vol:/var/lib/grafana grafana/grafana
docker run -d -p 9093:9093 --name alertmanager --restart=always \
-v ${data_dir}/monitor/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml \
prom/alertmanager
[ $? -eq 0 ] && cecho 96 "Install Success!!!" && exit 0
cecho 31 "Install Fail" && exit 71
}
######################主函数######################
Install_Docker
Deploy_Init_Data
Import_Images
Install_Node_Exporter
Install_All_Service