Open-Falcon install script(Open-Falcon監控一鍵安裝腳本)

#!/bin/bash
#This is Open-Falcon install script
#Data is 2018/1/10
#Editer Zhanxing 
#本腳本使用Red 7和CentOS 7系統安裝Open-Falcon
install_preparation()
{
yum install -y wget vim
yum install -y git  pip epel-release golang  redis 
python get-pip.py
pip install gunicorn
systemctl start redis
systemctl enable redis
systemctl stop firewalld
systemctl disable firewalld
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0 
}
install_mysql()
{
wget -P /tmp http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
    if [ $? -eq 0 ]; then
        echo "mysql yum源下載成功"
    else
        echo "mysql yum源下載失敗"
        exit
    fi
rpm -ivh /tmp/mysql-community-release-el7-5.noarch.rpm
yum install mysql-server -y
    if [ $? -eq 0 ]; then
        echo "mysql 安裝成功"
    else
        echo "mysql 安裝失敗"
        exit
    fi
systemctl start mysql
systemctl enable mysql
echo "自行設置MySQL密碼,方便記錄"
read -p "please input mysql password:"pwd
mysqladmin -u root password "$pwd"
export GOROOT=/usr/lib/golang
export GOPATH=/home
mkdir -p $GOPATH/src/github.com/open-falcon
cd $GOPATH/src/github.com/open-falcon
git clone https://github.com/open-falcon/falcon-plus.git
    if [ $? -eq 0 ]; then
        echo "git源碼成功"
    else
        echo "git源碼失敗"
        exit
    fi
cd $GOPATH/src/github.com/open-falcon/falcon-plus/scripts/mysql/db_schema/
#mysql -u root -p123.com  < /home/src/github.com/open-falcon/falcon-plus/scripts/mysql/db_schema/1_uic-db-schema.sql
mysql -h 127.0.0.1 -u root -p$pwd < 1_uic-db-schema.sql
mysql -h 127.0.0.1 -u root -p$pwd < 2_portal-db-schema.sql
mysql -h 127.0.0.1 -u root -p$pwd < 3_dashboard-db-schema.sql
mysql -h 127.0.0.1 -u root -p$pwd < 4_graph-db-schema.sql
mysql -h 127.0.0.1 -u root -p$pwd < 5_alarms-db-schema.sql
cd $GOPATH/src/github.com/open-falcon/falcon-plus/
go get github.com/open-falcon/rrdlite
make all
make pack
}
install_after()
{
export WORKSPACE= 
mkdir -p $WORKSPACE
cd $GOPATH/src/github.com/open-falcon/falcon-plus/
tar -xzvf *.tar.gz -C $WORKSPACE
sed -i 's/root:/root:$pwd/g' /home/work/aggregator/config/cfg.json
sed -i 's/root:/root:$pwd/g' /home/work/graph/config/cfg.json
sed -i 's/root:/root:$pwd/g' /home/work/hbs/config/cfg.json
sed -i 's/root:/root:$pwd/g' /home/work/nodata/config/cfg.json
sed -i 's/root:/root:$pwd/g' /home/work/api/config/cfg.json
sed -i 's/root:/root:$pwd/g' /home/work/alarm/config/cfg.json
cd $WORKSPACE
./open-falcon start
    if [ $? -eq 0 ]; then
        echo "open-falcon啓動成功"
    else
        echo "open-falcon啓動失敗"
        exit
    fi
}
install_before()
{
export FRONTSPACE=/home/front/open-falcon
mkdir -p $FRONTSPACE
cd $FRONTSPACE
git clone https://github.com/open-falcon/dashboard.git
    if [ $? -eq 0 ]; then
        echo "git 前端代碼成功"
    else
        echo "git 前端代碼失敗"
        exit
    fi
    
yum install -y python-virtualenv python-devel openldap-devel mysql-devel
yum groupinstall "Development tools" -y
cd $FRONTSPACE/dashboard/
virtualenv ./env
./env/bin/pip install -r pip_requirements.txt
bash control start
    if [ $? -eq 0 ]; then
        echo "dashboard啓動成功"
    else
        echo "dashboard啓動失敗"
        exit
    fi
}
#檢測網絡
ping -c 1 -t 1 www.baidu.com >/dev/null 2>&1
if [[ \$? == 2 ]]; then
    echo "nameserver 114.114.114.114
nameserver 8.8.8.8" > /etc/resolv.conf
fi
ping -c 1 -t 1 www.baidu.com >/dev/null 2>&1
if [[ $? == 2 ]]; then
    echo "Network problems,Please check!"
    exit
fi
#更換阿里YUM源和fedora的epel倉庫
yum install wget vim net-tools -y
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum install -y epel-release
#開始安裝
echo "1 安裝準備環境"
echo "2 安裝MySQL"
echo "3 安裝後端組件"
echo "4 安裝前端組件"
echo "5 單機組合安裝"
echo "輸入您需要安裝的組件編號[1-5]"
read aNum
case  $aNum in
    1) 
    install_preparation
    ;;
    2) 
    install_mysql
    ;;
    3) 
    install_after
    ;;
    4) 
    install_before
    ;;
    5) 
    install_preparation 
    install_mysql
    install_after
    install_before
    echo "安裝完成,請通過http://IP:8081進行訪問"
    ;;
esac


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章