dgiot/dgiot_install.sh

1606 lines
66 KiB
Bash
Raw Normal View History

2021-09-08 19:01:21 +08:00
#!/bin/bash
# This file is used to install dgiot on linux systems. The operating system
# is required to use systemd to manage services at boot
export PATH=$PATH:/usr/local/bin
2022-04-18 21:10:15 +08:00
function help() {
2023-07-21 15:38:09 +08:00
echo "Usage: $(basename $0) -v [single | cluster | devops | ci] -s [dgiot_n] -p [your_dgiot_plugin] -d [your_domain_name] -m [dgiotmd5] -e [pg_eip] -a [pg_auth] -n [islanip]"
2022-04-18 21:10:15 +08:00
exit 0
}
2021-09-08 19:01:21 +08:00
2022-04-18 21:10:15 +08:00
function check_os_type() {
# get the operating system type for using the corresponding init file
# ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification
#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
if [[ -e /etc/os-release ]]; then
2023-07-21 15:38:09 +08:00
osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2) || :
2022-04-18 21:10:15 +08:00
else
osinfo=""
fi
echo "osinfo: ${osinfo}"
os_type=0
2023-07-21 15:38:09 +08:00
if echo $osinfo | grep -qwi "ubuntu"; then
# echo "This is ubuntu system"
2022-04-18 21:10:15 +08:00
os_type=1
2023-07-21 15:38:09 +08:00
elif echo $osinfo | grep -qwi "debian"; then
# echo "This is debian system"
2022-04-18 21:10:15 +08:00
os_type=1
2023-07-21 15:38:09 +08:00
elif echo $osinfo | grep -qwi "Kylin"; then
# echo "This is Kylin system"
2022-04-18 21:10:15 +08:00
os_type=1
2023-07-21 15:38:09 +08:00
elif echo $osinfo | grep -qwi "centos"; then
# echo "This is centos system"
2022-04-18 21:10:15 +08:00
os_type=2
2023-07-21 15:38:09 +08:00
elif echo $osinfo | grep -qwi "fedora"; then
# echo "This is fedora system"
2022-04-18 21:10:15 +08:00
os_type=2
2023-07-21 15:38:09 +08:00
elif echo $osinfo | grep -qwi "Amazon"; then
# echo "This is Amazon system"
2022-04-18 21:10:15 +08:00
os_type=2
2023-07-21 15:38:09 +08:00
elif echo $osinfo | grep -qwi "Red"; then
# echo "This is Red Hat system"
2022-04-18 21:10:15 +08:00
os_type=2
else
echo " osinfo: ${osinfo}"
echo " This is an officially unverified linux system,"
echo " if there are any problems with the installation and operation, "
echo " please feel free to contact www.iotn2n.com for support."
os_type=3
fi
}
2021-09-08 19:01:21 +08:00
2022-04-18 21:10:15 +08:00
function dgiot_shell() {
# Color setting
RED='\033[0;31m'
GREEN='\033[1;32m'
GREEN_DARK='\033[0;32m'
GREEN_UNDERLINE='\033[4;32m'
NC='\033[0m'
script_dir=$(dirname $(readlink -f "$0"))
csudo=""
2023-07-21 15:38:09 +08:00
if command -v sudo >/dev/null; then
csudo="sudo"
2022-04-18 21:10:15 +08:00
fi
}
2021-09-08 19:01:21 +08:00
2022-04-18 21:10:15 +08:00
function dgiot_fqdn() {
lanip=""
wlanip=""
serverFqdn=""
dgiot_data=""
2021-09-08 19:01:21 +08:00
# 网络检查pre_install
get_lanip
get_wanip
2022-04-18 21:10:15 +08:00
# 获取进程数
2021-09-08 19:01:21 +08:00
get_processor
2022-04-18 21:10:15 +08:00
}
function install_openssl() {
2023-07-21 15:38:09 +08:00
yum install -y glibc-headers &>/dev/null
yum install -y openssl openssl-devel &>/dev/null
yum install -y libstdc++-devel openssl-devel &>/dev/null
2022-04-18 21:10:15 +08:00
}
# rand password
#https://bcrypt-generator.com/
function dgiot_password() {
install_openssl
2023-07-21 15:38:09 +08:00
pg_pwd=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
2022-04-18 21:10:15 +08:00
parse_user=dgiot
2023-07-21 15:38:09 +08:00
parse_pwd=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_appid=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_master=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_readonly_master=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_file=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_client=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_javascript=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_restapi=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_dotnet=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
parse_webhook=$(openssl rand -hex 8 | md5sum | cut -f1 -d ' ')
2022-04-18 21:10:15 +08:00
}
function dgiot_path() {
# package from path
fileserver="https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0"
fileparseserver="https://dgiot-parse-server-1306147891.cos.ap-nanjing.myqcloud.com"
fileversionserver="https://dgiot-version-1306147891.cos.ap-nanjing.myqcloud.com"
2022-04-18 21:10:15 +08:00
updateserver="http://dgiot-1253666439.cos.ap-shanghai-fsi.myqcloud.com/dgiot_release/update"
2023-08-11 10:09:37 +08:00
otpversion="24.3.4.2"
2022-04-18 21:10:15 +08:00
#install path
install_dir="/data/dgiot"
#backup path
2023-07-21 15:38:09 +08:00
randtime=$(date +%F_%T)
2022-04-18 21:10:15 +08:00
backup_dir=${install_dir}/${randtime}
mkdir ${backup_dir} -p
2023-07-21 15:38:09 +08:00
#service path
2022-04-18 21:10:15 +08:00
service_dir="/lib/systemd/system"
}
function dgiot_auto_variables() {
# ============================= get auto variables =================================================
dgiot_path
dgiot_fqdn
dgiot_password
}
2021-09-08 19:01:21 +08:00
2022-04-18 21:10:15 +08:00
## 1.3. 部署前处理
function pre_install() {
2021-09-08 19:01:21 +08:00
## 1.4 关闭防火墙selinux
2022-02-10 16:49:38 +08:00
if systemctl is-active --quiet firewalld; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} firewalld is running, stopping it...${NC}"
${csudo} systemctl stop firewalld $1 &>/dev/null || echo &>/dev/null
${csudo} systemctl disable firewalld $1 &>/dev/null || echo &>/dev/null
2022-02-10 16:49:38 +08:00
fi
2022-04-18 21:10:15 +08:00
# setenforce 0
2021-11-02 18:08:28 +08:00
sed -ri s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
2022-02-10 16:49:38 +08:00
2022-01-17 14:15:25 +08:00
## 1.5 配置yum源
if [ ! -f /etc/yum.repos.d/CentOS-Base.repo ]; then
2023-07-21 15:38:09 +08:00
curl -o /etc/yum.repos.d/CentOS-Base.repo https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0/CentOS-Base.repo &>/dev/null
2021-12-22 19:35:48 +08:00
fi
2021-09-08 19:01:21 +08:00
2022-01-23 20:01:36 +08:00
## 1.6 echo "installing tools"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} installing tools${NC}"
yum -y install vim net-tools wget ntpdate &>/dev/null
yum -y groupinstall "Development Tools" &>/dev/null
2021-09-08 19:01:21 +08:00
## 1.7 时间同步
echo "*/10 * * * * /usr/sbin/ntpdate ntp.aliyun.com > /dev/null 2>&1" >>/etc/crontab
## 1.8 加快ssh连接
sed -ri s/"#UseDNS yes"/"UseDNS no"/g /etc/ssh/sshd_config
systemctl restart sshd
}
function get_processor() {
2023-07-21 15:38:09 +08:00
processor=$(cat /proc/cpuinfo | grep "processor" | wc -l)
2021-09-08 19:01:21 +08:00
}
function get_wanip() {
2023-07-21 15:38:09 +08:00
ping -c2 baidu.com &>/dev/null
wlanip=$(curl whatismyip.akamai.com)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} islanip=${islanip} ${NC}"
if [ "${islanip}" == "true" ]; then
wlanip=${lanip}
2022-09-27 17:34:11 +08:00
fi
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} wlanip: ${wlanip}${NC}"
2021-09-08 19:01:21 +08:00
}
function get_lanip() {
2023-07-21 15:38:09 +08:00
for nic in $(ls /sys/class/net); do
2022-01-24 20:26:12 +08:00
# shellcheck disable=SC1073
# echo -e "`date +%F_%T` $LINENO: ${GREEN} nic: ${nic}${NC}"
# ingore docker ip
if [ "${nic}" == "*docker*" ]; then
continue
fi
2022-04-18 21:10:15 +08:00
# ingore lo ip
2022-01-24 20:26:12 +08:00
if [ "${nic}" == "lo" ]; then
continue
fi
2023-07-21 15:38:09 +08:00
# ingore bridge ip
2022-01-24 20:26:12 +08:00
if [ "${nic}" == "*br-*" ]; then
continue
fi
tmpip=$(/sbin/ifconfig ${nic} | sed -nr 's/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
if [ -z "$tmpip" ]; then
continue
fi
lanip=$tmpip
done
2021-09-08 19:01:21 +08:00
if [ -z "$lanip" ]; then
2023-07-21 15:38:09 +08:00
lanip=$(/sbin/ifconfig | grep inet | grep -v inet6 | grep -v 127.0.0.1 | awk '{print $2}' | awk -F ":" '{print $2}') || :
2021-09-08 19:01:21 +08:00
fi
if [ -z "$lanip" ]; then
lanip="127.0.0.1"
fi
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} lanip: ${lanip}${NC}"
2021-09-08 19:01:21 +08:00
}
function kill_process() {
pid=$(ps -ef | grep "$1" | grep -v "grep" | awk '{print $2}')
if [ -n "$pid" ]; then
2023-07-21 15:38:09 +08:00
${csudo} kill -9 $pid || :
2021-09-08 19:01:21 +08:00
fi
}
2023-07-21 15:38:09 +08:00
function clean_services() {
2021-09-08 19:01:21 +08:00
clean_service dgiot_pg_writer
clean_service dgiot
clean_service dgiot_parse_server
2023-07-21 15:38:09 +08:00
# clean_service dgiot_redis
2021-09-08 19:01:21 +08:00
clean_service grafana-server
clean_service go_fastdfs
clean_service taosd
clean_service dgiot_tdengine_mqtt
clean_service prometheus
clean_service pushgateway
clean_service node_exporter
clean_service postgres_exporter
2021-11-18 20:15:27 +08:00
clean_service nginx
2021-09-08 19:01:21 +08:00
}
function clean_service() {
if systemctl is-active --quiet $1; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} $1 is running, stopping it...${NC}"
${csudo} systemctl stop $1 &>/dev/null || echo &>/dev/null
fi
${csudo} systemctl disable $1 &>/dev/null || echo &>/dev/null
2021-09-08 19:01:21 +08:00
${csudo} rm -f ${service_dir}/$1.service
}
# $1:service $2:Type $3:ExecStart $4:User $5:Environment $6:ExecStop
function install_service() {
2022-12-29 18:03:14 +08:00
rm -rf ${service_dir}/$1.service
2021-09-08 19:01:21 +08:00
service_config="${service_dir}/$1.service"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} build ${service_config}${NC}"
2021-09-08 19:01:21 +08:00
${csudo} bash -c "echo '[Unit]' > ${service_config}"
${csudo} bash -c "echo 'Description=$1 server' >> ${service_config}"
${csudo} bash -c "echo 'After=network-online.target' >> ${service_config}"
${csudo} bash -c "echo 'Wants=network-online.target' >> ${service_config}"
${csudo} bash -c "echo >> ${service_config}"
${csudo} bash -c "echo '[Service]' >> ${service_config}"
${csudo} bash -c "echo 'Type=$2' >> ${service_config}"
${csudo} bash -c "echo 'ExecStart=$3' >> ${service_config}"
if [ ! x"$4" = x ]; then
${csudo} bash -c "echo 'User=$4' >> ${service_config}"
${csudo} bash -c "echo 'Group=$4' >> ${service_config}"
fi
if [ ! x"$5" = x ]; then
${csudo} bash -c "echo 'Environment=$5' >> ${service_config}"
fi
2022-04-18 21:10:15 +08:00
if [ -$# -eq 6 ]; then
2021-09-08 19:01:21 +08:00
${csudo} bash -c "echo 'ExecStop=$6' >> ${service_config}"
fi
${csudo} bash -c "echo 'KillMode=mixed' >> ${service_config}"
${csudo} bash -c "echo 'KillSignal=SIGINT' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutSec=300' >> ${service_config}"
${csudo} bash -c "echo 'OOMScoreAdjust=-1000' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}"
${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}"
${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${service_config}"
${csudo} bash -c "echo 'LimitCORE=infinity' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${service_config}"
${csudo} bash -c "echo 'StandardOutput=null' >> ${service_config}"
${csudo} bash -c "echo 'Restart=always' >> ${service_config}"
${csudo} bash -c "echo 'StartLimitBurst=3' >> ${service_config}"
${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${service_config}"
${csudo} bash -c "echo >> ${service_config}"
${csudo} bash -c "echo '[Install]' >> ${service_config}"
${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}"
2023-07-21 15:38:09 +08:00
${csudo} systemctl daemon-reload &>/dev/null
${csudo} systemctl enable $1 &>/dev/null
${csudo} systemctl start $1 &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} systemctl start $1${NC}"
2021-09-08 19:01:21 +08:00
}
# $1:service $2:Type $3:ExecStart $4:Environment $5:WorkingDirectory
function install_service1() {
service_config="${service_dir}/$1.service"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} build ${service_config}${NC}"
2021-09-08 19:01:21 +08:00
${csudo} bash -c "echo '[Unit]' > ${service_config}"
${csudo} bash -c "echo 'Description=$1 server' >> ${service_config}"
${csudo} bash -c "echo 'After=network-online.target' >> ${service_config}"
${csudo} bash -c "echo 'Wants=network-online.target' >> ${service_config}"
${csudo} bash -c "echo >> ${service_config}"
${csudo} bash -c "echo '[Service]' >> ${service_config}"
${csudo} bash -c "echo 'Type=$2' >> ${service_config}"
${csudo} bash -c "echo 'ExecStart=$3' >> ${service_config}"
2023-07-21 15:38:09 +08:00
if [ ! x"$5" = x ]; then
2021-09-08 19:01:21 +08:00
${csudo} bash -c "echo 'WorkingDirectory=$5' >> ${service_config}"
fi
if [ ! x"$4" = x ]; then
${csudo} bash -c "echo 'Environment=$4' >> ${service_config}"
fi
${csudo} bash -c "echo 'KillMode=mixed' >> ${service_config}"
${csudo} bash -c "echo 'KillSignal=SIGINT' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutSec=300' >> ${service_config}"
${csudo} bash -c "echo 'OOMScoreAdjust=-1000' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}"
${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}"
${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${service_config}"
${csudo} bash -c "echo 'LimitCORE=infinity' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${service_config}"
${csudo} bash -c "echo 'StandardOutput=null' >> ${service_config}"
${csudo} bash -c "echo 'Restart=always' >> ${service_config}"
${csudo} bash -c "echo 'StartLimitBurst=3' >> ${service_config}"
${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${service_config}"
${csudo} bash -c "echo >> ${service_config}"
${csudo} bash -c "echo '[Install]' >> ${service_config}"
${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}"
2023-07-21 15:38:09 +08:00
${csudo} systemctl daemon-reload &>/dev/null
${csudo} systemctl enable $1 &>/dev/null
${csudo} systemctl start $1 &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} systemctl start $1${NC}"
2021-09-08 19:01:21 +08:00
}
2021-09-24 17:50:58 +08:00
# $1:service $2:Type $3:ExecStart
function install_service2() {
service_config="${service_dir}/$1.service"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} build ${service_config}${NC}"
2021-09-24 17:50:58 +08:00
${csudo} bash -c "echo '[Unit]' > ${service_config}"
${csudo} bash -c "echo 'Description=$1 server' >> ${service_config}"
${csudo} bash -c "echo 'After=network-online.target' >> ${service_config}"
${csudo} bash -c "echo 'Wants=network-online.target' >> ${service_config}"
${csudo} bash -c "echo >> ${service_config}"
${csudo} bash -c "echo '[Service]' >> ${service_config}"
${csudo} bash -c "echo 'Type=$2' >> ${service_config}"
${csudo} bash -c "echo 'ExecStart=$3' >> ${service_config}"
${csudo} bash -c "echo 'KillMode=mixed' >> ${service_config}"
${csudo} bash -c "echo 'KillSignal=SIGINT' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutSec=300' >> ${service_config}"
${csudo} bash -c "echo 'OOMScoreAdjust=-1000' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${service_config}"
${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${service_config}"
${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${service_config}"
${csudo} bash -c "echo 'LimitCORE=infinity' >> ${service_config}"
${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${service_config}"
${csudo} bash -c "echo 'StandardOutput=null' >> ${service_config}"
${csudo} bash -c "echo 'Restart=always' >> ${service_config}"
${csudo} bash -c "echo 'StartLimitBurst=3' >> ${service_config}"
${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${service_config}"
${csudo} bash -c "echo >> ${service_config}"
${csudo} bash -c "echo '[Install]' >> ${service_config}"
${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${service_config}"
2023-07-21 15:38:09 +08:00
${csudo} systemctl daemon-reload &>/dev/null
${csudo} systemctl enable $1 &>/dev/null
${csudo} systemctl start $1 &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} systemctl start $1${NC}"
2021-09-24 17:50:58 +08:00
}
2022-04-18 21:10:15 +08:00
find_in_file() {
2023-07-21 15:38:09 +08:00
grep "$1" "$2" >/dev/null
2022-04-18 21:10:15 +08:00
return $?
}
### set host
2023-07-21 15:38:09 +08:00
set_host() {
2022-04-18 21:10:15 +08:00
IP=$1
HOST=$2
RECORD="${IP} ${HOST}"
find_in_file "${RECORD}" /etc/hosts
if [ $? -ne 0 ]; then
2023-07-21 15:38:09 +08:00
echo ${RECORD} >>/etc/hosts
2022-04-18 21:10:15 +08:00
fi
}
2021-09-08 19:01:21 +08:00
##---------------------------------------------------------------##
#2 部署档案数据库
2022-02-11 20:52:07 +08:00
2021-09-08 19:01:21 +08:00
## 2.1 部署postgres数据库
### 2.1.1 环境准备,根据自身需要,减少或者增加
function yum_install_postgres() {
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} yum install postgres${NC}"
2022-02-11 21:31:08 +08:00
#yum_install_git #占用资源较多,先去除
2023-07-21 15:38:09 +08:00
yum install -y wget git &>/dev/null
${csudo} yum install -y gcc gcc-c++ epel-release &>/dev/null
2021-12-16 16:35:26 +08:00
# ${csudo} yum install -y llvm llvm-devel &> /dev/null
2023-07-21 15:38:09 +08:00
${csudo} yum install -y clang libicu-devel perl-ExtUtils-Embed &>/dev/null
${csudo} yum install -y readline readline-devel &>/dev/null
${csudo} yum install -y zlib zlib-devel &>/dev/null
${csudo} yum install -y pam-devel libxml2-devel libxslt-devel &>/dev/null
${csudo} yum install -y openldap-devel systemd-devel &>/dev/null
${csudo} yum install -y tcl-devel python-devel &>/dev/null
2021-09-08 19:01:21 +08:00
}
### 2.1.2 编译安装postgres
function install_postgres() {
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install_postgres${NC}"
2021-09-08 19:01:21 +08:00
##下载软件
if [ ! -f ${script_dir}/postgresql-12.0.tar.gz ]; then
2023-07-21 15:38:09 +08:00
${csudo} wget ${fileserver}/postgresql-12.0.tar.gz -O ${script_dir}/postgresql-12.0.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
### 创建目录和用户,以及配置环境变化
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} create postgres user and group ${NC}"
2021-09-24 15:55:26 +08:00
set +uxe
2021-09-09 16:07:06 +08:00
egrep "^postgres" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} postgres user and group exist ${NC}"
2021-09-09 16:07:06 +08:00
else
2023-07-21 15:38:09 +08:00
${csudo} groupadd postgres &>/dev/null
${csudo} useradd -g postgres postgres &>/dev/null
2021-09-09 16:07:06 +08:00
fi
2021-09-08 19:01:21 +08:00
### 密码设置在引号内输入自己的密码
echo ${pg_pwd} | passwd --stdin postgres
echo "export PATH=/usr/local/pgsql/12/bin:$PATH" >/etc/profile.d/pgsql.sh
source /etc/profile.d/pgsql.sh
if [ -d ${script_dir}/postgresql-12.0 ]; then
2023-07-21 15:38:09 +08:00
${csudo} rm ${script_dir}/postgresql-12.0 -rf
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
tar xvf postgresql-12.0.tar.gz &>/dev/null
2021-10-21 14:53:26 +08:00
cd ./postgresql-12.0/
2021-09-24 15:55:26 +08:00
set -ue
2021-09-08 19:01:21 +08:00
yum_install_postgres
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} configure postgres${NC}"
./configure --prefix=/usr/local/pgsql/12 --with-pgport=7432 --enable-nls --with-python --with-tcl --with-gssapi --with-icu --with-openssl --with-pam --with-ldap --with-systemd --with-libxml --with-libxslt &>/dev/null
2021-09-08 19:01:21 +08:00
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} make install postgres${NC}"
make install -j${processor} &>/dev/null
2021-09-08 19:01:21 +08:00
### 添加pg_stat_statements数据库监控插件
2023-07-21 15:38:09 +08:00
cd ${script_dir}/postgresql-12.0/contrib/pg_stat_statements/
echo -e "$(date +%F_%T) $LINENO: ${GREEN} make install pg_stat_statements ${NC}"
make install -j${processor} &>/dev/null
2021-09-08 19:01:21 +08:00
sleep 5
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2021-12-03 16:39:47 +08:00
rm ${script_dir}/postgresql-12.0 -rf
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} build postgres sueccess${NC}"
2021-09-08 19:01:21 +08:00
}
2023-07-21 15:38:09 +08:00
function init_postgres_database() {
2021-09-08 19:01:21 +08:00
### 2.1.4.搭建主数据库
if [ -d ${install_dir}/dgiot_pg_writer ]; then
2021-10-21 14:53:26 +08:00
mv ${install_dir}/dgiot_pg_writer/ ${backup_dir}/
2021-09-08 19:01:21 +08:00
fi
mkdir ${install_dir}/dgiot_pg_writer/data -p
mkdir ${install_dir}/dgiot_pg_writer/archivedir -p
2022-12-05 12:32:42 +08:00
chown -R postgres:postgres /data/
chown -R postgres:postgres /usr/local/pgsql
2021-09-08 19:01:21 +08:00
chown -R postgres:postgres ${install_dir}/dgiot_pg_writer
2021-10-21 14:53:26 +08:00
cd ${install_dir}/dgiot_pg_writer/
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/initdb -D ${install_dir}/dgiot_pg_writer/data/ -U postgres --locale=en_US.UTF8 -E UTF8 &>/dev/null
2021-09-08 19:01:21 +08:00
${csudo} bash -c "cp ${install_dir}/dgiot_pg_writer/data/{pg_hba.conf,pg_hba.conf.bak}"
${csudo} bash -c "cp ${install_dir}/dgiot_pg_writer/data/{postgresql.conf,postgresql.conf.bak}"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} initdb postgres success${NC}"
2021-09-08 19:01:21 +08:00
### 2.1.5 配置postgresql.conf
postgresql_conf="${install_dir}/dgiot_pg_writer/data/postgresql.conf"
2023-07-21 15:38:09 +08:00
cat >${postgresql_conf} <<"EOF"
2021-09-08 19:01:21 +08:00
listen_addresses = '*'
port = 7432
max_connections = 100
superuser_reserved_connections = 10
full_page_writes = on
wal_log_hints = off
max_wal_senders = 50
hot_standby = on
log_destination = 'csvlog'
logging_collector = off
log_directory = 'log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S'
log_rotation_age = 1d
log_rotation_size = 10MB
log_statement = 'mod'
log_timezone = 'PRC'
timezone = 'PRC'
unix_socket_directories = '/tmp'
shared_buffers = 512MB
temp_buffers = 16MB
work_mem = 32MB
effective_cache_size = 2GB
maintenance_work_mem = 128MB
#max_stack_depth = 2MB
dynamic_shared_memory_type = posix
## PITR
full_page_writes = on
wal_buffers = 16MB
wal_writer_delay = 200ms
commit_delay = 0
commit_siblings = 5
wal_level = replica
archive_mode = off
archive_timeout = 60s
#pg_stat_statements
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = all
EOF
archivedir="${install_dir}/dgiot_pg_writer/archivedir"
2023-07-21 15:38:09 +08:00
echo " archive_command = 'test ! -f ${archivedir}/%f && cp %p ${archivedir}/%f'" >>${postgresql_conf}
2022-04-18 21:10:15 +08:00
pg_hba_conf="${install_dir}/dgiot_pg_writer/data/pg_hba.conf"
# METHOD "trust", "reject","md5","password","scram-sha-256","gss","sspi","ident","peer","pam","ldap","radius","cert"
${csudo} bash -c "echo 'host all all ${pg_eip}/24 password' >> ${pg_hba_conf}"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} ${postgresql_conf}${NC}"
2021-09-08 19:01:21 +08:00
}
### 2.1.4 安装部署postgres
function deploy_postgres() {
clean_service dgiot_pg_writer
2021-09-09 15:00:27 +08:00
install_postgres
2021-09-08 19:01:21 +08:00
init_postgres_database
DATA_DIR="${install_dir}/dgiot_pg_writer/data"
2021-09-27 12:57:22 +08:00
install_service dgiot_pg_writer "notify" "/usr/local/pgsql/12/bin/postgres -D ${DATA_DIR}" "postgres" "DATA_DIR=${DATA_DIR}"
2021-09-08 19:01:21 +08:00
sleep 2
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -c "CREATE USER repl WITH PASSWORD '${pg_pwd}' REPLICATION;" &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} deploy postgres success${NC}"
2021-09-08 19:01:21 +08:00
}
2022-04-18 21:10:15 +08:00
function restore_parse_data() {
2022-09-27 17:34:11 +08:00
### 下载dgiot_parse_server初始数据
if [ ! -f ${script_dir}/parse_4.0.sql.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/parse_4.0.sql.tar.gz -O ${script_dir}/parse_4.0.sql.tar.gz &>/dev/null
2022-09-27 17:34:11 +08:00
fi
cp ${script_dir}/parse_4.0.sql.tar.gz ${install_dir}/dgiot_pg_writer/
2022-04-18 21:10:15 +08:00
cd ${install_dir}/dgiot_pg_writer/
2023-07-21 15:38:09 +08:00
tar xvf parse_4.0.sql.tar.gz &>/dev/null
2022-04-18 21:10:15 +08:00
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -c "ALTER USER postgres WITH PASSWORD '${pg_pwd}';" &>/dev/null
retval=$(sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -c "SELECT datname FROM pg_database WHERE datistemplate = false;" &>/dev/null)
2022-04-18 21:10:15 +08:00
if [[ $retval == *"parse"* ]]; then
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/pg_dump -F p -f ${backup_dir}/dgiot_pg_writer/parse_4.0_backup.sql -C -E UTF8 -h 127.0.0.1 -U postgres parse &>/dev/null
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -c "DROP DATABASE parse;" &>/dev/null
2022-04-18 21:10:15 +08:00
fi
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -c "CREATE DATABASE parse;" &>/dev/null
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -f ${install_dir}/dgiot_pg_writer/parse_4.0.sql parse &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} restore parse data success${NC}"
2022-04-18 21:10:15 +08:00
}
2021-09-08 19:01:21 +08:00
## 2.2 部署parse server
### 1.2.2 下载parse初始数据
### 2.1.3 安装postgres_service系统服务
function install_parse_server() {
### 备份dgiot_parse_server
if [ -d ${install_dir}/dgiot_parse_server ]; then
2023-07-21 15:38:09 +08:00
mv ${install_dir}/dgiot_parse_server/ ${backup_dir}/dgiot_parse_server
chown -R postgres:postgres ${backup_dir}/dgiot_parse_server/
2021-09-08 19:01:21 +08:00
fi
###下载dgiot_parse_server软件
2022-09-27 17:34:11 +08:00
if [ ! -f ${script_dir}/dgiot_parse_server.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileparseserver}/dgiot_parse_server.tar.gz -O ${script_dir}/dgiot_parse_server.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
cd ${script_dir}/
tar xf dgiot_parse_server.tar.gz
mv ./dgiot_parse_server ${install_dir}/dgiot_parse_server
### 配置dgiot_parse_server配置参数
parseconfig=${install_dir}/dgiot_parse_server/script/.env
${csudo} bash -c "echo '# 基础配置' > ${parseconfig}"
${csudo} bash -c "echo 'SERVER_NAME = dgiot_parse_server' >> ${parseconfig}"
${csudo} bash -c "echo 'SERVER_PORT = 1337' >> ${parseconfig}"
${csudo} bash -c "echo 'SERVER_DOMAIN = http://${wlanip}:1337' >> ${parseconfig}"
${csudo} bash -c "echo 'SERVER_PUBLIC = http://${wlanip}:1337' >> ${parseconfig}"
${csudo} bash -c "echo 'SERVER_PATH = /parse' >> ${parseconfig}"
${csudo} bash -c "echo 'GRAPHQL_PATH = http://${wlanip}:1337/graphql' >> ${parseconfig}"
${csudo} bash -c "echo '# 管理配置' >> ${parseconfig}"
${csudo} bash -c "echo 'DASHBOARD_PATH = /dashboard' >> ${parseconfig}"
${csudo} bash -c "echo 'DASHBOARD_USER = ${parse_user}' >> ${parseconfig}"
${csudo} bash -c "echo 'DASHBOARD_PASS = ${parse_pwd}' >> ${parseconfig}"
${csudo} bash -c "echo 'DASHBOARD_ENCPASS = false' >> ${parseconfig}"
${csudo} bash -c "echo '# 数据配置' >> ${parseconfig}"
2022-04-18 21:10:15 +08:00
${csudo} bash -c "echo 'DATABASE = postgres://postgres:${pg_auth}@${pg_eip}:7432/parse' >> ${parseconfig}"
2021-09-08 19:01:21 +08:00
${csudo} bash -c "echo 'REDIS_SOCKET = redis://127.0.0.1:16379/0' >> ${parseconfig}"
${csudo} bash -c "echo 'REDIS_CACHE = redis://127.0.0.1:16379/1' >> ${parseconfig}"
${csudo} bash -c "echo '# 邮箱配置' >> ${parseconfig}"
2021-10-21 14:53:26 +08:00
${csudo} bash -c "echo 'EMAIL_FROM_ADDRESS = lsxredrain@163.com' >> ${parseconfig}"
2021-09-08 19:01:21 +08:00
${csudo} bash -c "echo 'EMAIL_FROM_NAME = 系统通知' >> ${parseconfig}"
${csudo} bash -c "echo 'EMAIL_SENDMAIL = true' >> ${parseconfig}"
${csudo} bash -c "echo 'EMAIL_SMTP_HOST = smtp.163.com' >> ${parseconfig}"
${csudo} bash -c "echo 'EMAIL_SMTP_PORT = 465' >> ${parseconfig}"
${csudo} bash -c "echo 'EMAIL_SMTP_SECURE = true' >> ${parseconfig}"
${csudo} bash -c "echo 'EMAIL_SMTP_USER = lsxredrain' >> ${parseconfig}"
${csudo} bash -c "echo 'EMAIL_SMTP_PASS = youpasswd' >> ${parseconfig}"
${csudo} bash -c "echo '# 接口配置' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_APPID = ${parse_appid}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_MASTER = ${parse_master}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_READONLY_MASTER = ${parse_readonly_master}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_FILE = ${parse_file}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_CLIENT = ${parse_client}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_JAVASCRIPT = ${parse_javascript}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_RESTAPI = ${parse_restapi}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_DOTNET = ${parse_dotnet}' >> ${parseconfig}"
${csudo} bash -c "echo 'KEY_WEBHOOK = ${parse_webhook}' >> ${parseconfig}"
${csudo} bash -c "echo '# 会话配置' >> ${parseconfig}"
${csudo} bash -c "echo 'SESSION_LENGTH = 604800' >> ${parseconfig}"
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} create ${parseconfig} success${NC}"
2021-09-08 19:01:21 +08:00
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install parse_server success${NC}"
}
2021-09-08 19:01:21 +08:00
function install_dgiot_redis() {
### 2.2.3 部署dgiot_redis缓存服务
cd ${install_dir}/dgiot_parse_server/script/redis/
2023-07-21 15:38:09 +08:00
make -j${processor} &>/dev/null
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2021-09-08 19:01:21 +08:00
}
function deploy_parse_server() {
clean_service dgiot_parse_server
2023-07-21 15:38:09 +08:00
# clean_service dgiot_redis
2021-09-08 19:01:21 +08:00
install_parse_server
2022-12-30 18:39:51 +08:00
#install_dgiot_redis
#echo -e "`date +%F_%T` $LINENO: ${GREEN} install install_dgiot_redis success${NC}"
2021-09-08 19:01:21 +08:00
parsehome="${install_dir}/dgiot_parse_server"
2023-07-21 15:38:09 +08:00
# install_service2 "dgiot_redis" "simple" "${parsehome}/script/redis/src/redis-server ${parsehome}/script/redis.conf"
2021-10-21 14:53:26 +08:00
install_service2 "dgiot_parse_server" "simple" "${parsehome}/script/node/bin/node ${parsehome}/server/index.js"
2021-09-08 19:01:21 +08:00
}
#3 部署时序数据服务
##3.1 部署tdengine server
function deploy_tdengine_server() {
### 1.2.4 下载TDengine-server
if [ -f ${install_dir}/taos ]; then
2022-02-11 20:52:07 +08:00
clean_service "taosd"
2021-09-08 19:01:21 +08:00
mv ${install_dir}/taos/ ${backup_dir}/taos/
fi
2023-02-03 18:37:11 +08:00
if [ ! -f ${script_dir}/TDengine-server-3.0.2.4-Linux-x64.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/TDengine-server-3.0.2.4-Linux-x64.tar.gz -O ${script_dir}/TDengine-server-3.0.2.4-Linux-x64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2023-02-03 18:37:11 +08:00
if [ -f ${script_dir}/TDengine-server-3.0.2.4 ]; then
rm -rf ${script_dir}/TDengine-server-3.0.2.4/
2021-09-08 19:01:21 +08:00
fi
2023-02-03 18:37:11 +08:00
tar xf TDengine-server-3.0.2.4-Linux-x64.tar.gz
cd ${script_dir}/TDengine-server-3.0.2.4/
2023-01-07 10:56:06 +08:00
mkdir ${install_dir}/taos3/log/ -p
mkdir ${install_dir}/taos3/data/ -p
2023-07-21 15:38:09 +08:00
echo | /bin/sh remove.sh &>/dev/null
echo | /bin/sh install.sh &>/dev/null
2021-09-08 19:01:21 +08:00
ldconfig
2021-12-03 16:39:47 +08:00
cd ${script_dir}/
2023-02-03 18:37:11 +08:00
rm ${script_dir}/TDengine-server-3.0.2.4 -rf
2023-01-07 10:56:06 +08:00
${csudo} bash -c "echo 'logDir ${install_dir}/taos3/log/' > /etc/taos/taos.cfg"
${csudo} bash -c "echo 'dataDir ${install_dir}/taos3/data/' >> /etc/taos/taos.cfg"
${csudo} bash -c "echo 'supportVnodes 100' >> /etc/taos/taos.cfg"
2021-09-08 19:01:21 +08:00
systemctl start taosd
2022-02-10 17:34:50 +08:00
systemctl start taosadapter
2023-01-07 10:56:06 +08:00
systemctl start taoskeeper
2023-07-21 15:38:09 +08:00
${csudo} systemctl enable taosadapter &>/dev/null
${csudo} systemctl enable taoskeeper &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} tdengine_server start success${NC}"
2022-09-27 17:34:11 +08:00
# install_dgiot_tdengine_mqtt
2021-09-08 19:01:21 +08:00
}
## 3.3 部署dgiot_tdengine_mqtt桥接服务
function install_dgiot_tdengine_mqtt() {
## 3.2.setup mosquitto
### 1.2.5 下载mosquitto
if [ ! -f ${script_dir}/mosquitto-1.6.7.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/mosquitto-1.6.7.tar.gz -O ${script_dir}/mosquitto-1.6.7.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
if [ -d ${script_dir}/mosquitto-1.6.7/ ]; then
2023-07-21 15:38:09 +08:00
rm ${script_dir}/mosquitto-1.6.7/ -rf
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
cd ${script_dir}/
tar xvf mosquitto-1.6.7.tar.gz &>/dev/null
cd ${script_dir}/mosquitto-1.6.7
2021-09-08 19:01:21 +08:00
if [ -f /usr/lib/libmosquitto.so.1 ]; then
2023-07-21 15:38:09 +08:00
rm /usr/lib/libmosquitto.so.1 -rf
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
make -j${processor} &>/dev/null
make install &>/dev/null
2021-09-08 19:01:21 +08:00
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
ldconfig
2023-07-21 15:38:09 +08:00
cd ${script_dir}/
2021-09-08 19:01:21 +08:00
rm ${script_dir}/mosquitto-1.6.7/ -rf
2021-10-21 14:53:26 +08:00
#wget ${fileserver}/dgiot_tdengine_mqtt -O /usr/sbin/dgiot_tdengine_mqtt &> /dev/null
2022-09-27 17:34:11 +08:00
#rm ${script_dir}/dgiot_tdengine_mqtt/ -rf
2021-10-21 14:53:26 +08:00
rm /usr/sbin/dgiot_tdengine_mqtt -rf
2022-09-27 17:34:11 +08:00
if [ -d ${script_dir}/dgiot_tdengine_mqtt/ ]; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} git clone dgiot_tdengine_mqtt ${NC}"
git clone https://gitee.com/dgiiot/dgiot_tdengine_mqtt.git &>/dev/null
2022-09-27 17:34:11 +08:00
fi
2021-10-21 14:53:26 +08:00
cd ${script_dir}/dgiot_tdengine_mqtt/c/
2023-07-21 15:38:09 +08:00
make &>/dev/null
2021-10-21 14:53:26 +08:00
cp ${script_dir}/dgiot_tdengine_mqtt/c/dgiot_tdengine_mqtt /usr/sbin/dgiot_tdengine_mqtt
2021-09-08 19:01:21 +08:00
chmod 777 /usr/sbin/dgiot_tdengine_mqtt
2021-09-24 17:50:58 +08:00
install_service2 dgiot_tdengine_mqtt "simple" "/usr/sbin/dgiot_tdengine_mqtt 127.0.0.1"
2021-09-08 19:01:21 +08:00
}
#4 安装文件数据服务器
function install_go_fastdfs() {
if [ ! -f ${script_dir}/go_fastdfs.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/go_fastdfs.tar.gz -O ${script_dir}/go_fastdfs.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
if [ -d ${install_dir}/go_fastdfs/ ]; then
clean_service go_fastdfs
2023-07-21 15:38:09 +08:00
mv ${install_dir}/go_fastdfs ${backup_dir}/
2021-09-08 19:01:21 +08:00
fi
cd ${script_dir}/
2023-07-21 15:38:09 +08:00
tar xvf go_fastdfs.tar.gz &>/dev/null
2021-10-21 14:53:26 +08:00
cd ${script_dir}/go_fastdfs/
2021-09-08 19:01:21 +08:00
chmod 777 ${script_dir}/go_fastdfs/file
mv ${script_dir}/go_fastdfs ${install_dir}
2021-10-21 14:53:26 +08:00
${csudo} bash -c "sed -i 's!{{ip}}!${lanip}!g' ${install_dir}/go_fastdfs/cfg.json"
${csudo} bash -c "sed -i 's/{{port}}/1250/g' ${install_dir}/go_fastdfs/cfg.json"
2022-07-18 18:52:54 +08:00
${csudo} bash -c "sed -i 's/{{domain_name}}/${lanip}/g' ${install_dir}/go_fastdfs/cfg.json"
2021-11-12 18:11:03 +08:00
2021-09-08 19:01:21 +08:00
if [ -f ${install_dir}/go_fastdfs/conf/ ]; then
rm ${install_dir}/go_fastdfs/conf/ -rf
fi
mkdir ${install_dir}/go_fastdfs/conf/ -p
2023-07-21 15:38:09 +08:00
cp ${install_dir}/go_fastdfs/cfg.json ${install_dir}/go_fastdfs/conf/cfg.json
2021-09-08 19:01:21 +08:00
go_fastdhome=${install_dir}/go_fastdfs
install_service1 gofastdfs "simple" "${install_dir}/go_fastdfs/file ${go_fastdhome}" "GO_FASTDFS_DIR=${go_fastdhome}" "${go_fastdhome}"
2021-11-11 18:34:37 +08:00
2021-12-25 22:39:40 +08:00
if [ ! -d ${install_dir}/go_fastdfs/files/ ]; then
mkdir -p ${install_dir}/go_fastdfs/files/
2021-11-11 18:34:37 +08:00
fi
2021-12-28 14:35:31 +08:00
if [ ! -f ${script_dir}/dgiot_file.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/dgiot_file.tar.gz -O ${script_dir}/dgiot_file.tar.gz &>/dev/null
2021-11-11 18:34:37 +08:00
fi
cd ${script_dir}/
2021-12-28 08:09:45 +08:00
if [ -d ${script_dir}/dgiot_file/ ]; then
rm ${script_dir}/dgiot_file/ -rf
fi
2023-07-21 15:38:09 +08:00
tar xf dgiot_file.tar.gz &>/dev/null
2021-11-12 18:11:03 +08:00
mv ${script_dir}/dgiot_file ${install_dir}/go_fastdfs/files/
2021-12-28 14:35:31 +08:00
if [ ! -f ${script_dir}/dgiot_swagger.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/dgiot_swagger.tar.gz -O ${script_dir}/dgiot_swagger.tar.gz &>/dev/null
2021-11-16 21:26:03 +08:00
fi
2022-01-07 15:12:59 +08:00
2021-12-28 08:09:45 +08:00
if [ -d ${script_dir}/dgiot_swagger/ ]; then
rm ${script_dir}/dgiot_swagger/ -rf
fi
2023-07-21 15:38:09 +08:00
tar xf dgiot_swagger.tar.gz &>/dev/null
2021-11-16 21:26:03 +08:00
mv ${script_dir}/dgiot_swagger ${install_dir}/go_fastdfs/files/
2021-12-28 14:35:31 +08:00
if [ ! -f ${script_dir}/dgiot_dashboard.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/dgiot_dashboard.tar.gz -O ${script_dir}/dgiot_dashboard.tar.gz &>/dev/null
2021-11-12 18:11:03 +08:00
fi
cd ${script_dir}/
2021-12-28 08:09:45 +08:00
if [ -d ${script_dir}/dgiot_dashboard/ ]; then
rm ${script_dir}/dgiot_dashboard/ -rf
fi
2023-07-21 15:38:09 +08:00
tar xf dgiot_dashboard.tar.gz &>/dev/null
2021-12-28 08:09:45 +08:00
2023-07-21 15:38:09 +08:00
mv ${script_dir}/dgiot_dashboard ${install_dir}/go_fastdfs/files/ &>/dev/null
2022-04-18 21:10:15 +08:00
}
2021-11-12 18:11:03 +08:00
2022-04-18 21:10:15 +08:00
#4 安装文件数据服务器
function install_word_report() {
clean_service dgiot_report
if [ ! -f ${script_dir}/dgiot_report.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/dgiot_report.tar.gz -O ${script_dir}/dgiot_report.tar.gz &>/dev/null
tar xf dgiot_report.tar.gz &>/dev/null
2022-04-18 21:10:15 +08:00
fi
# $1:service $2:Type $3:ExecStart $4:User $5:Environment $6:ExecStop
2023-07-21 15:38:09 +08:00
install_service dgiot_report "simple" "${install_dir}/dgiot_report/bin/startup.sh" "root" "test=1" "${install_dir}/dgiot_report/bin/shutdown.sh"
2021-09-08 19:01:21 +08:00
}
2023-06-26 17:20:38 +08:00
function install_n2n() {
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} yum install n2n${NC}"
${csudo} yum install -y libzstd &>/dev/null
2023-06-26 17:20:38 +08:00
if [ ! -f ${script_dir}/n2n-3.0.0-1038.x86_64.rpm ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/n2n-3.0.0-1038.x86_64.rpm -O ${script_dir}/n2n-3.0.0-1038.x86_64.rpm &>/dev/null
2023-06-26 17:20:38 +08:00
fi
2023-07-21 15:38:09 +08:00
rpm -ivh --replacepkgs n2n-3.0.0-1038.x86_64.rpm --nodeps --force &>/dev/null
2023-06-26 17:20:38 +08:00
}
2023-07-21 15:38:09 +08:00
function yum_install_git() {
rm /etc/yum.repos.d/wandisco-git.repo -rf
cat >/etc/yum.repos.d/wandisco-git.repo <<"EOF"
2022-02-11 20:52:07 +08:00
[wandisco-git]
name=Wandisco GIT Repository
baseurl=http://opensource.wandisco.com/centos/7/git/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco
EOF
2023-07-21 15:38:09 +08:00
sudo rpm --import http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco &>/dev/null
yum remove -y git &>/dev/null
2022-02-11 20:52:07 +08:00
}
2023-07-21 15:38:09 +08:00
function yum_install_jenkins() {
echo -e "$(date +%F_%T) $LINENO: ${GREEN} yum_install_jenkins${NC}"
${csudo} wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo &>/dev/null
${csudo} rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key &>/dev/null
2022-02-11 20:52:07 +08:00
${csudo} yum install epel-release # repository that provides 'daemonize'
2023-07-21 15:38:09 +08:00
${csudo} yum install java-11-openjdk-devel &>/dev/null
${csudo} yum install jenkins &>/dev/null
2022-02-11 20:52:07 +08:00
# https://www.jenkins.io/doc/book/installing/linux/
}
2023-07-21 15:38:09 +08:00
function yum_install_erlang_otp() {
echo -e "$(date +%F_%T) $LINENO: ${GREEN} yum_install_erlang_otp${NC}"
yum install -y make gcc gcc-c++ &>/dev/null
yum install -y kernel-devel m4 ncurses-devel &>/dev/null
yum install -y unixODBC unixODBC-devel &>/dev/null
yum install -y libtool-ltdl libtool-ltdl-devel &>/dev/null
2021-09-08 19:01:21 +08:00
}
2022-04-18 21:10:15 +08:00
2021-09-08 19:01:21 +08:00
#5. 部署应用服务器
# 5.1 安装erlang/otp环境
function install_erlang_otp() {
yum_install_erlang_otp
2023-08-11 10:09:37 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install_erlang_otp ${otpversion} ${NC}"
if [ ! -f ${script_dir}/otp_src_${otpversion}.tar.gz ]; then
wget ${fileserver}/otp_src_${otpversion}.tar.gz -O ${script_dir}/otp_src_${otpversion}.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
2023-08-11 10:09:37 +08:00
if [ -d ${install_dir}/otp_src_${otpversion}/ ]; then
rm ${script_dir}/otp_src_${otpversion} -rf
2021-09-08 19:01:21 +08:00
fi
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2023-08-11 10:09:37 +08:00
tar xf otp_src_${otpversion}.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
2023-08-11 10:09:37 +08:00
cd ${script_dir}/otp_src_${otpversion}/
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} otp configure${NC}"
./configure &>/dev/null
echo -e "$(date +%F_%T) $LINENO: ${GREEN} otp make install${NC}"
make install &>/dev/null
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2023-08-11 10:09:37 +08:00
rm ${script_dir}/otp_src_${otpversion} -rf
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install erlang otp success${NC}"
2021-09-08 19:01:21 +08:00
}
function update_dgiot() {
2023-07-21 15:38:09 +08:00
# dgiot
if [ ! -d ${install_dir}/go_fastdfs/files/package/ ]; then
2023-07-21 15:38:09 +08:00
mkdir -p ${install_dir}/go_fastdfs/files/package/
2021-09-08 19:01:21 +08:00
fi
cd ${install_dir}/go_fastdfs/files/package/
2022-01-20 21:18:07 +08:00
if [ -f ${software}.tar.gz ]; then
2023-07-21 15:38:09 +08:00
md5=$(md5sum ${software}.tar.gz | cut -d ' ' -f1)
2022-01-20 21:18:07 +08:00
if [ "${md5}" != "${dgiotmd5}" ]; then
rm -rf ${software}.tar.gz
fi
fi
if [ ! -f ${software}.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileversionserver}/${software}.tar.gz &>/dev/null
md51=$(md5sum ${software}.tar.gz | cut -d ' ' -f1)
2022-01-20 21:18:07 +08:00
if [ "${md51}" != "${dgiotmd5}" ]; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${RED} download ${software} failed${NC}"
2022-01-20 21:18:07 +08:00
exit 1
fi
fi
2021-12-25 22:39:40 +08:00
tar xf ${software}.tar.gz
2023-07-21 15:38:09 +08:00
rm ${script_dir}/dgiot/etc/plugins/dgiot_parse.conf -rf
cp ${install_dir}/dgiot/etc/plugins/dgiot_parse.conf ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf
cp ${install_dir}/dgiot/etc/plugins/dgiot_http.conf ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_http.conf
cp ${install_dir}/dgiot/etc/emqx.conf ${install_dir}/go_fastdfs/files/package/dgiot/etc/emqx.conf
2021-09-08 19:01:21 +08:00
if [ -d ${install_dir}/dgiot/ ]; then
clean_service dgiot
2023-07-21 15:38:09 +08:00
mv ${install_dir}/dgiot ${backup_dir}/dgiot/
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
mv ${install_dir}/go_fastdfs/files/package/dgiot/ ${install_dir}/
2021-09-08 19:01:21 +08:00
2023-07-21 15:38:09 +08:00
install_service "dgiot" "forking" "/bin/sh ${install_dir}/dgiot/bin/emqx start" "root" "HOME=${install_dir}/dgiot/erts-12.3.2.2" "/bin/sh /data/dgiot/bin/emqx stop"
2021-09-08 19:01:21 +08:00
}
2022-02-10 17:34:50 +08:00
function update_tdengine_server() {
2023-07-21 15:38:09 +08:00
version=$(taos --v | awk '{print $2}') || :
2022-02-10 17:34:50 +08:00
if [ "${version}" != "2.4.0.4" ]; then
deploy_tdengine_server
fi
}
2022-01-20 21:18:07 +08:00
function update_dashboard() {
# dgiot_dashboard
cd ${install_dir}/go_fastdfs/files/
if [ -f dgiot_dashboard.tar.gz ]; then
2023-07-21 15:38:09 +08:00
dashboardmd5=$(md5sum dgiot_dashboard.tar.gz | cut -d ' ' -f1)
2022-09-23 18:25:52 +08:00
if [ "${dashboardmd5}" != "cfd6ee1d717cc0e1613f862d9c022b32" ]; then
2023-07-21 15:38:09 +08:00
rm -rf dgiot_dashboard.tar.gz &>/dev/null
2022-01-20 21:18:07 +08:00
fi
fi
if [ ! -f dgiot_dashboard.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/dgiot_dashboard.tar.gz &>/dev/null
dashboardmd52=$(md5sum dgiot_dashboard.tar.gz | cut -d ' ' -f1)
2022-09-23 18:25:52 +08:00
if [ "${dashboardmd52}" != "cfd6ee1d717cc0e1613f862d9c022b32" ]; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${RED} download dgiot_dashboard.tar.gz failed${NC}"
2022-01-20 21:18:07 +08:00
exit 1
fi
fi
if [ -d dgiot_dashboard/ ]; then
mv dgiot_dashboard/ ${backup_dir}/
fi
2023-07-21 15:38:09 +08:00
tar xf dgiot_dashboard.tar.gz &>/dev/null
2022-01-20 21:18:07 +08:00
}
2022-04-18 21:10:15 +08:00
2022-12-29 14:13:07 +08:00
function update_html() {
# dgiot_dashboard
cd ${install_dir}/nginx
2023-02-03 18:37:11 +08:00
if [ -f ${html_software}.tar.gz ]; then
2023-07-21 15:38:09 +08:00
htmlmd51=$(md5sum ${html_software}.tar.gz | cut -d ' ' -f1)
2023-02-03 18:37:11 +08:00
if [ "${htmlmd51}" != "${htmlmd5}" ]; then
2023-07-21 15:38:09 +08:00
rm -rf ${html_software}.tar.gz &>/dev/null
2022-12-29 14:13:07 +08:00
fi
fi
2023-02-03 18:37:11 +08:00
if [ ! -f ${html_software}.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/${html_software}.tar.gz &>/dev/null
htmlmd52=$(md5sum ${html_software}.tar.gz | cut -d ' ' -f1)
2023-02-03 18:37:11 +08:00
if [ "${htmlmd52}" != "${htmlmd5}" ]; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${RED} download ${html_software}.tar.gz failed${NC}"
2022-12-29 14:13:07 +08:00
exit 1
fi
fi
if [ -d html/ ]; then
mv html/ ${backup_dir}/
fi
2023-07-21 15:38:09 +08:00
tar xf ${html_software}.tar.gz &>/dev/null
2022-12-29 15:39:17 +08:00
sed -ri '/dgiot_api/d' conf/nginx.conf
2022-12-29 14:13:07 +08:00
}
2021-09-08 19:01:21 +08:00
function install_dgiot() {
2021-12-14 19:33:26 +08:00
make_ssl
if [ ! -d ${install_dir}/go_fastdfs/files/package/ ]; then
2023-07-21 15:38:09 +08:00
mkdir -p ${install_dir}/go_fastdfs/files/package/
2021-09-08 19:01:21 +08:00
fi
if [ ! -f ${install_dir}/go_fastdfs/files/package/${software}.tar.gz ]; then
2022-09-27 17:34:11 +08:00
if [ ! -f ${script_dir}/${software}.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileversionserver}/${software}.tar.gz -O ${install_dir}/go_fastdfs/files/package/${software}.tar.gz &>/dev/null
2022-09-27 17:34:11 +08:00
else
2023-07-21 15:38:09 +08:00
cp ${script_dir}/${software}.tar.gz ${install_dir}/go_fastdfs/files/package/
2022-09-27 17:34:11 +08:00
fi
fi
cd ${install_dir}/go_fastdfs/files/package/
2021-12-25 22:39:40 +08:00
tar xf ${software}.tar.gz
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install_dgiot dgiot_parse${NC}"
2021-09-09 16:42:17 +08:00
#修改 dgiot_parse 连接 配置
2023-07-21 15:38:09 +08:00
${csudo} bash -c "sed -ri '/^parse.parse_server/cparse.parse_server = http://127.0.0.1:1337' ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf"
${csudo} bash -c "sed -ri '/^parse.parse_path/cparse.parse_path = /parse/' ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf"
${csudo} bash -c "sed -ri '/^parse.parse_appid/cparse.parse_appid = ${parse_appid}' ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf"
${csudo} bash -c "sed -ri '/^parse.parse_master_key/cparse.parse_master_key = ${parse_master}' ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf"
${csudo} bash -c "sed -ri '/^parse.parse_js_key/cparse.parse_js_key = ${parse_javascript}' ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf"
${csudo} bash -c "sed -ri '/^parse.parse_rest_key/cparse.parse_rest_key = ${parse_restapi}' ${install_dir}/go_fastdfs/files/package/dgiot/etc/plugins/dgiot_parse.conf"
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install_dgiot dgiot${NC}"
2021-09-09 16:42:17 +08:00
# 修改dgiot.conf
2021-12-27 00:01:10 +08:00
${csudo} bash -c "sed -ri 's!/etc/ssl/certs/domain_name!/etc/ssl/certs/${domain_name}!g' ${install_dir}/go_fastdfs/files/package/dgiot/etc/emqx.conf"
2021-09-08 19:01:21 +08:00
if [ -d ${install_dir}/dgiot/ ]; then
clean_service dgiot
2023-07-21 15:38:09 +08:00
mv ${install_dir}/dgiot ${backup_dir}/dgiot/
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
mv ${install_dir}/go_fastdfs/files/package/dgiot ${install_dir}/
2021-09-08 19:01:21 +08:00
2023-07-21 15:38:09 +08:00
install_service "dgiot" "forking" "/bin/sh ${install_dir}/dgiot/bin/emqx start" "root" "HOME=${install_dir}/dgiot/erts-12.3.2.2" "/bin/sh /data/dgiot/bin/emqx stop"
2021-09-08 19:01:21 +08:00
}
#6 运维监控
# 6.1 安装node_exporter-0.18.1.linux-amd64.tar.gz
function install_node_exporter() {
if [ ! -f ${script_dir}/node_exporter-0.18.1.linux-amd64.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/node_exporter-0.18.1.linux-amd64.tar.gz -O ${script_dir}/node_exporter-0.18.1.linux-amd64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
if [ -d ${install_dir}/node_exporter-0.18.1.linux-amd64/ ]; then
clean_service node_exporter
mv ${install_dir}/node_exporter-0.18.1.linux-amd64/ ${backup_dir}/
fi
2023-07-21 15:38:09 +08:00
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
mv ${script_dir}/node_exporter-0.18.1.linux-amd64/ ${install_dir}/
2022-04-18 21:10:15 +08:00
install_service2 node_exporter "simple" "${install_dir}/node_exporter-0.18.1.linux-amd64/node_exporter"
cd ${script_dir}
2021-09-08 19:01:21 +08:00
}
##6.2 install postgres exporter
function install_postgres_exporter() {
if [ ! -f ${script_dir}/postgres_exporter-0.10.0.linux-amd64.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/postgres_exporter-0.10.0.linux-amd64.tar.gz -O ${script_dir}/postgres_exporter-0.10.0.linux-amd64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
retval=$(sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "SELECT * FROM pg_available_extensions;" &>/dev/null)
2021-09-08 19:01:21 +08:00
if [[ $retval == *"pg_stat_statements"* ]]; then
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} pg_stat_statements has installed${NC}"
2021-09-08 19:01:21 +08:00
else
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE EXTENSION pg_stat_statements SCHEMA public;" &>/dev/null
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE USER postgres_exporter PASSWORD 'password';" &>/dev/null
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;" &>/dev/null
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE SCHEMA postgres_exporter AUTHORIZATION postgres_exporter;" &>/dev/null
2021-10-20 14:44:29 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE FUNCTION postgres_exporter.f_select_pg_stat_activity()
2021-09-08 19:01:21 +08:00
RETURNS setof pg_catalog.pg_stat_activity
LANGUAGE sql
SECURITY DEFINER
AS \$\$
SELECT * from pg_catalog.pg_stat_activity;
2023-07-21 15:38:09 +08:00
\$\$;" &>/dev/null
2021-09-08 19:01:21 +08:00
2021-10-20 14:44:29 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE FUNCTION postgres_exporter.f_select_pg_stat_replication()
2021-09-08 19:01:21 +08:00
RETURNS setof pg_catalog.pg_stat_replication
LANGUAGE sql
SECURITY DEFINER
AS \$\$
SELECT * from pg_catalog.pg_stat_replication;
2023-07-21 15:38:09 +08:00
\$\$;" &>/dev/null
2021-09-08 19:01:21 +08:00
2021-10-20 14:44:29 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE VIEW postgres_exporter.pg_stat_replication
2021-09-08 19:01:21 +08:00
AS
2023-07-21 15:38:09 +08:00
SELECT * FROM postgres_exporter.f_select_pg_stat_replication();" &>/dev/null
2021-09-08 19:01:21 +08:00
2021-10-20 14:44:29 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "CREATE VIEW postgres_exporter.pg_stat_activity
2021-09-08 19:01:21 +08:00
AS
2023-07-21 15:38:09 +08:00
SELECT * FROM postgres_exporter.f_select_pg_stat_activity();" &>/dev/null
2021-09-08 19:01:21 +08:00
2023-07-21 15:38:09 +08:00
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;" &>/dev/null
sudo -u postgres /usr/local/pgsql/12/bin/psql -U postgres -d parse -c "GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;" &>/dev/null
2021-09-08 19:01:21 +08:00
fi
systemctl restart dgiot_pg_writer
if [ -d ${install_dir}/postgres_exporter-0.10.0.linux-amd64/ ]; then
clean_service postgres_exporter
mv ${install_dir}/postgres_exporter-0.10.0.linux-amd64/ ${backup_dir}/
fi
2023-07-21 15:38:09 +08:00
tar xvf postgres_exporter-0.10.0.linux-amd64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
mv ${script_dir}/postgres_exporter-0.10.0.linux-amd64/ ${install_dir}/
2023-07-21 15:38:09 +08:00
export DATA_SOURCE_NAME=postgresql://postgres:postgres@127.0.0.1:7432/parse?sslmode=disable
2021-09-24 17:50:58 +08:00
install_service2 postgres_exporter "simple" "${install_dir}/postgres_exporter --extend.query-path='${install_dir}/queries.yaml'"
2021-09-08 19:01:21 +08:00
}
##6.3 安装prometheus-2.17.1.linux-amd64.tar.gz
function install_prometheus() {
if [ ! -f ${script_dir}/prometheus-2.17.1.linux-amd64.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget $fileserver/prometheus-2.17.1.linux-amd64.tar.gz -O ${script_dir}/prometheus-2.17.1.linux-amd64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2023-07-21 15:38:09 +08:00
tar -zxvf prometheus-2.17.1.linux-amd64.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
if [ -d ${install_dir}/prometheus-2.17.1.linux-amd64/ ]; then
clean_service pushgateway
clean_service prometheus
2023-07-21 15:38:09 +08:00
mv ${install_dir}/prometheus-2.17.1.linux-amd64/ ${backup_dir}/prometheus-2.17.1.linux-amd64/
2021-09-08 19:01:21 +08:00
fi
2023-07-21 15:38:09 +08:00
mv ${script_dir}/prometheus-2.17.1.linux-amd64/ ${install_dir}/
2021-09-24 17:50:58 +08:00
install_service2 pushgateway "simple" "${install_dir}/prometheus-2.17.1.linux-amd64/pushgateway"
install_service2 prometheus "simple" "${install_dir}/prometheus-2.17.1.linux-amd64/prometheus \
2021-09-08 19:01:21 +08:00
--config.file=${install_dir}/prometheus-2.17.1.linux-amd64/prometheus.yml \
--storage.tsdb.path=${install_dir}/prometheus-2.17.1.linux-amd64/data"
}
2023-07-21 15:38:09 +08:00
function yum_install_grafana() {
echo -e "$(date +%F_%T) $LINENO: ${GREEN} yum_install_grafana${NC}"
yum install -y libXcomposite libXdamage libXtst cups libXScrnSaver &>/dev/null
yum install -y pango atk adwaita-cursor-theme adwaita-icon-theme &>/dev/null
yum install -y at at-spi2-atk at-spi2-core cairo-gobject colord-libs &>/dev/null
yum install -y dconf desktop-file-utils ed emacs-filesystem gdk-pixbuf2 &>/dev/null
yum install -y glib-networking gnutls gsettings-desktop-schemas &>/dev/null
yum install -y gtk-update-icon-cache gtk3 hicolor-icon-theme jasper-libs &>/dev/null
yum install -y json-glib libappindicator-gtk3 libdbusmenu libdbusmenu-gtk3 libepoxy &>/dev/null
yum install -y liberation-fonts liberation-narrow-fonts liberation-sans-fonts liberation-serif-fonts &>/dev/null
yum install -y libgusb libindicator-gtk3 libmodman libproxy libsoup libwayland-cursor libwayland-egl &>/dev/null
yum install -y libxkbcommon m4 mailx nettle patch psmisc redhat-lsb-core redhat-lsb-submod-security &>/dev/null
yum install -y rest spax time trousers xdg-utils xkeyboard-config alsa-lib &>/dev/null
2021-09-08 19:01:21 +08:00
}
###6.3.4 安装grafana-7.1.1.tar.gz
function install_grafana() {
## 部署图片报表插件
yum_install_grafana
if [ ! -f ${script_dir}/grafana-7.1.1.tar.gz ]; then
2023-07-21 15:38:09 +08:00
wget ${fileserver}/grafana-7.1.1.tar.gz -O ${script_dir}/grafana-7.1.1.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
fi
if [ -d ${install_dir}/grafana-7.1.1/ ]; then
clean_service grafana-server
2023-07-21 15:38:09 +08:00
mv ${install_dir}/grafana-7.1.1/ ${backup_dir}/grafana-7.1.1/
2021-09-08 19:01:21 +08:00
fi
2021-10-21 14:53:26 +08:00
cd ${script_dir}/
2023-07-21 15:38:09 +08:00
tar xvf grafana-7.1.1.tar.gz &>/dev/null
2021-09-08 19:01:21 +08:00
2023-07-21 15:38:09 +08:00
mv ${script_dir}/grafana-7.1.1/ ${install_dir}/
2021-09-08 19:01:21 +08:00
grafanahome=${install_dir}/grafana-7.1.1
2023-07-21 15:38:09 +08:00
${csudo} bash -c "sed -ri '/^plugins/cplugins = ${install_dir}/grafana-7.1.1/data/plugins/' ${install_dir}/grafana-7.1.1/conf/defaults.ini"
2021-09-24 17:50:58 +08:00
install_service2 grafana-server "simple" "${grafanahome}/bin/grafana-server --config=${grafanahome}/conf/defaults.ini --homepath=${grafanahome}"
2021-09-08 19:01:21 +08:00
}
2021-12-27 17:29:23 +08:00
function build_nginx() {
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} build_nginx ${NC}"
clean_service nginx
if systemctl is-active --quiet nginx; then
echo -e "$(date +%F_%T) $LINENO: ${GREEN} nginx is running, stopping it...${NC}"
rpm -e nginx
fi
### 创建目录和用户,以及配置环境变化
echo -e "$(date +%F_%T) $LINENO: ${GREEN} create nginx user and group ${NC}" &>/dev/null
set +uxe
egrep "^nginx" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo -e "$(date +%F_%T) $LINENO: ${GREEN} nginx user and group exist ${NC}" &>/dev/null
else
${csudo} groupadd nginx &>/dev/null
${csudo} useradd -g nginx nginx &>/dev/null
fi
### install nginx
yum -y install pcre-devel &>/dev/null
yum install openssl-devel &>/dev/null
if [ ! -f ${script_dir}/nginx-1.20.1.tar.gz ]; then
wget https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0/nginx-1.20.1.tar.gz -O ${script_dir}/nginx-1.20.1.tar.gz &>/dev/null
fi
cd ${script_dir}/
tar xvf nginx-1.20.1.tar.gz &>/dev/null
cd ${script_dir}/nginx-1.20.1
./configure --prefix=/data/dgiot/nginx --with-http_realip_module --with-http_ssl_module --with-http_gzip_static_module --with-stream &>/dev/null
make &>/dev/null
make install &>/dev/null
if [ ! -f ${script_dir}/nginx.conf ]; then
wget $fileserver/nginx.conf -O ${script_dir}/nginx.conf &>/dev/null
fi
if [ ! -f ${script_dir}/${domain_name}.zip ]; then
wget $fileserver/${domain_name}.zip -O ${script_dir}/${domain_name}.zip &>/dev/null
fi
rm /data/dgiot/nginx/conf/nginx.conf -rf
cp ${script_dir}/nginx.conf /data/dgiot/nginx/conf/nginx.conf -rf
echo -e "$(date +%F_%T) $LINENO: ${GREEN} ${domain_name} ${NC}"
sed -i "s!{{domain_name}}!${domain_name}!g" /data/dgiot/nginx/conf/nginx.conf
sed -i "s!{{install_dir}}!${install_dir}!g" /data/dgiot/nginx/conf/nginx.conf
echo -e "$(date +%F_%T) $LINENO: ${GREEN} ${install_dir} ${NC}"
if [ -f ${script_dir}/${domain_name}.zip ]; then
echo -e "$(date +%F_%T) $LINENO: ${GREEN} ${script_dir}/${domain_name}.zip ${NC}"
unzip -o ${script_dir}/${domain_name}.zip -d /etc/ssl/certs/ &>/dev/null
fi
#dashboard
if [ ! -f ${script_dir}/${html_software}.tar.gz ]; then
wget ${fileserver}/${html_software}.tar.gz -O ${script_dir}/${html_software}.tar.gz &>/dev/null
fi
cd ${script_dir}/
rm -rf /data/dgiot/nginx/html &>/dev/null
tar -zxvf ${html_software}.tar.gz -C /data/dgiot/nginx/ &>/dev/null
2022-12-29 14:13:07 +08:00
2023-07-21 15:38:09 +08:00
install_service2 "nginx" "forking" "/data/dgiot/nginx/sbin/nginx"
2021-12-27 17:29:23 +08:00
}
2021-12-14 19:33:26 +08:00
function make_ssl() {
2023-07-21 15:38:09 +08:00
if [ ! -d /etc/ssl/dgiot/ ]; then
mkdir -p /etc/ssl/dgiot/
cd /etc/ssl/dgiot/
2021-12-14 19:33:26 +08:00
2023-07-21 15:38:09 +08:00
# 生成自签名的CA key和证书
openssl genrsa -out ca.key 2048 &>/dev/null
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 -subj "/CN=${wlanip}" -out ca.pem &>/dev/null
2021-12-14 19:33:26 +08:00
2023-07-21 15:38:09 +08:00
# 生成服务器端的key和证书
openssl genrsa -out server.key 2048 &>/dev/null
openssl req -new -key ./server.key -out server.csr -subj "/CN=0.0.0.0" &>/dev/null
openssl x509 -req -in ./server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out server.pem -days 3650 -sha256 &>/dev/null
2021-12-14 19:33:26 +08:00
2023-07-21 15:38:09 +08:00
# 生成客户端key和证书
openssl genrsa -out client.key 2048 &>/dev/null
openssl req -new -key ./client.key -out client.csr -subj "/CN=0.0.0.0" &>/dev/null
openssl x509 -req -in ./client.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out client.pem -days 3650 -sha256 &>/dev/null
2021-12-14 19:33:26 +08:00
2023-07-21 15:38:09 +08:00
cd ${script_dir}/ &>/dev/null
fi
2021-12-14 19:33:26 +08:00
}
2023-08-11 10:09:37 +08:00
function install_ndoe() {
2022-03-21 14:06:03 +08:00
if [ ! -d ${script_dir}/node-v16.5.0-linux-x64/bin/ ]; then
2023-08-11 10:09:37 +08:00
if [ ! -f ${script_dir}/node-v16.5.0-linux-x64.tar.gz ]; then
wget https://dgiotdev-1308220533.cos.ap-nanjing.myqcloud.com/node-v16.5.0-linux-x64.tar.gz &>/dev/null
tar xvf node-v16.5.0-linux-x64.tar.gz &>/dev/null
if [ ! -f usr/bin/node ]; then
rm /usr/bin/node -rf
fi
ln -s ${script_dir}/node-v16.5.0-linux-x64/bin/node /usr/bin/node
ln -s ${script_dir}/node-v16.5.0-linux-x64/bin/yarn /usr/bin/yarn
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
2022-03-21 14:06:03 +08:00
fi
fi
2023-08-11 10:09:37 +08:00
}
2022-03-21 14:06:03 +08:00
2023-08-11 10:09:37 +08:00
function build_iotView() {
2023-07-21 15:38:09 +08:00
cd ${script_dir}/
2023-08-11 10:09:37 +08:00
if [ ! -d ${script_dir}/iotView/ ]; then
git clone -b master https://gitee.com/dgiiot/iotView.git.git iotView
2023-07-21 15:38:09 +08:00
fi
2022-03-21 14:06:03 +08:00
2023-08-11 10:09:37 +08:00
cd ${script_dir}/iotView
2023-07-21 15:38:09 +08:00
git reset --hard
git pull
2022-03-21 14:06:03 +08:00
2023-07-21 15:38:09 +08:00
export PATH=$PATH:/usr/local/bin:${script_dir}/node-v16.5.0-linux-x64/bin/
2023-08-11 10:09:37 +08:00
rm ${script_dir}/iotView/dist/ -rf
${script_dir}/node-v16.5.0-linux-x64/bin/npm install
${script_dir}/node-v16.5.0-linux-x64/bin/npm run build:prod
echo "build_iotView "
2023-07-21 15:38:09 +08:00
}
2022-03-21 14:06:03 +08:00
2023-08-11 10:09:37 +08:00
function build_iotEdit() {
2023-07-21 15:38:09 +08:00
cd ${script_dir}/
2023-08-11 10:09:37 +08:00
if [ ! -d ${script_dir}/iotEdit/ ]; then
git clone -b master https://gitee.com/dgiiot/iotEdit.git.git iotEdit
2023-07-21 15:38:09 +08:00
fi
2021-12-25 22:39:40 +08:00
2023-08-11 10:09:37 +08:00
cd ${script_dir}/iotEdit
2023-07-21 15:38:09 +08:00
git reset --hard
git pull
2021-12-25 22:39:40 +08:00
2023-07-21 15:38:09 +08:00
export PATH=$PATH:/usr/local/bin:${script_dir}/node-v16.5.0-linux-x64/bin/
2023-08-11 10:09:37 +08:00
rm ${script_dir}/iotEdit/dist/ -rf
${script_dir}/node-v16.5.0-linux-x64/bin/yarn install
${script_dir}/node-v16.5.0-linux-x64/bin/yarn build
echo "build_iotEdit"
2023-07-21 15:38:09 +08:00
}
2022-01-12 20:02:10 +08:00
function pre_build_dgiot() {
2023-07-21 15:38:09 +08:00
## 关闭dgiot
clean_service dgiot
count=$(ps -ef | grep beam.smp | grep -v "grep" | wc -l)
if [ 0 == $count ]; then
echo $count
else
killall -9 beam.smp
fi
2023-07-21 15:38:09 +08:00
cd ${script_dir}/
2023-07-21 15:38:09 +08:00
if [ ! -d ${script_dir}/$plugin/ ]; then
git clone https://gitee.com/dgiiot/dgiot.git $plugin
fi
2022-01-17 12:32:03 +08:00
2023-07-21 15:38:09 +08:00
cd ${script_dir}/$plugin/
git reset --hard
git pull
2022-01-17 12:32:03 +08:00
2023-07-21 15:38:09 +08:00
if [ $plugin == 'dgiot' ]; then
echo "dgiot plugin"
else
cd ${script_dir}/$plugin/apps/
rm $plugin -rf
git clone root@git.iotn2n.com:dgiot/$plugin.git
fi
2022-03-07 18:08:18 +08:00
2023-07-21 15:38:09 +08:00
cd ${script_dir}
rm ${script_dir}/$plugin/_build/emqx/rel/ -rf
2022-01-17 17:47:55 +08:00
2023-07-21 15:38:09 +08:00
if [ -d ${script_dir}/dgiot_dashboard/dist ]; then
rm ${script_dir}/$plugin/_build/emqx/lib/dgiot_api -rf
rm ${script_dir}/$plugin/apps/dgiot_api/priv/www/ -rf
cp ${script_dir}/dgiot_dashboard/dist/ ${script_dir}/$plugin/apps/dgiot_api/priv/www -rf
fi
2023-07-21 15:38:09 +08:00
if [ -d ${script_dir}/dgiot_dashboard_lite/dist ]; then
cp ${script_dir}/dgiot_dashboard_lite/dist/ ${script_dir}/$plugin/apps/dgiot_api/priv/www/dgiot-amis-dashboard -rf
fi
2022-03-21 14:06:03 +08:00
2023-07-21 15:38:09 +08:00
if [ -d ${script_dir}/dgiot/emqx/rel/ ]; then
rm ${script_dir}/dgiot/emqx/rel -rf
fi
2021-12-25 23:18:46 +08:00
2023-07-21 15:38:09 +08:00
rm ${script_dir}/$plugin/rebar.config -rf
cp ${script_dir}/$plugin/apps/$plugin/conf/rebar.config ${script_dir}/$plugin/rebar.config -rf
rm ${script_dir}/$plugin/rebar.config.erl -rf
cp ${script_dir}/$plugin/apps/$plugin/conf/rebar.config.erl ${script_dir}/$plugin/rebar.config.erl -rf
rm ${script_dir}/$plugin/data/loaded_plugins.tmpl -rf
cp ${script_dir}/$plugin/apps/$plugin/conf/loaded_plugins.tmpl ${script_dir}/$plugin/data/loaded_plugins.tmpl
rm ${script_dir}/$plugin/apps/dgiot_parse/etc/dgiot_parse.conf -rf
cp ${script_dir}/$plugin/apps/$plugin/conf/dgiot_parse.conf ${script_dir}/$plugin/apps/dgiot_parse/etc/dgiot_parse.conf -rf
rm ${script_dir}/$plugin/apps/dgiot_http/etc/dgiot_http.conf -rf
cp ${script_dir}/$plugin/apps/$plugin/conf/dgiot_http.conf ${script_dir}/$plugin/apps/dgiot_http/etc/dgiot_http.conf -rf
2022-03-23 16:33:22 +08:00
2023-07-21 15:38:09 +08:00
if [ -f ${script_dir}/$plugin/apps/$plugin/conf/other.sh ]; then
cd ${script_dir}/$plugin/apps/
echo | /bin/sh ${script_dir}/$plugin/apps/$plugin/conf/other.sh &>/dev/null
fi
cd ${script_dir}/$plugin/
}
2021-12-25 22:39:40 +08:00
2022-01-12 20:02:10 +08:00
function post_build_dgiot() {
2023-07-21 15:38:09 +08:00
mv ${script_dir}/$plugin/_build/emqx/rel/emqx/ ${script_dir}/$plugin/_build/emqx/rel/dgiot
cd ${script_dir}/$plugin/_build/emqx/rel
2021-12-25 22:39:40 +08:00
2023-07-21 15:38:09 +08:00
tar czf ${software}.tar.gz ./dgiot
rm ./dgiot -rf
if [ ! -d ${install_dir}/go_fastdfs/files/package/ ]; then
mkdir -p ${install_dir}/go_fastdfs/files/package/
fi
cp ./${software}.tar.gz ${install_dir}/go_fastdfs/files/package/
}
2022-01-12 20:02:10 +08:00
2022-04-18 21:10:15 +08:00
function build_keepalived() {
2023-07-21 15:38:09 +08:00
cd ~
wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz
yum install -y gcc openssl-devel popt-devel ipvsadm
tar -zxvf keepalived-2.0.20.tar.gz
mv keepalived-2.0.20 /usr/
cd /usr/keepalived-2.0.20
./configure --prefix=/usr/keepalived-2.0.20
make && make install
chmod 644 keepalived.conf
chmod +x /usr/keepalived-2.0.20/container_check.sh
systemctl enable keepalived.service
systemctl start keepalived.service
2022-01-12 20:02:10 +08:00
}
2022-03-28 11:30:25 +08:00
function install_python() {
2023-07-21 15:38:09 +08:00
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
wget https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0/Python-3.7.1.tar.xz
tar -xvf Python-3.7.1.tar.xz
cd Python-3.7.1/
./configure --prefix=/usr/local/python3 && make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 install --upgrade pip
2022-03-28 11:30:25 +08:00
}
function install_selenium() {
2023-07-21 15:38:09 +08:00
wget https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0/install-google-chrome.sh
sh ./install-google-chrome.sh
pip3 install selenium
wget https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
rm /usr/bin/chromedriver -rf
mv chromedriver /usr/bin/
2022-03-28 11:30:25 +08:00
}
2022-03-10 20:11:04 +08:00
function install_dotnet() {
2023-07-21 15:38:09 +08:00
sudo rpm -Uvh https://dgiot-release-1306147891.cos.ap-nanjing.myqcloud.com/v4.4.0/packages-microsoft-prod.rpm
sudo yum install -y dotnet-sdk-5.0
2022-03-10 20:11:04 +08:00
}
2022-04-18 21:10:15 +08:00
function install_ffmpeg() {
sudo yum install yasm
wget http://www.ffmpeg.org/releases/ffmpeg-4.1.tar.gz
tar -zxvf ffmpeg-4.1.tar.gz
cd ffmpeg-4.1
./configure --prefix=/usr/local/ffmpeg
make && make install
2023-07-21 15:38:09 +08:00
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg
}
2022-01-12 20:02:10 +08:00
2022-04-18 21:10:15 +08:00
## ==============================begin deploy type ============================
# 计划基于msys64来构建 类linux 的windows一键式部署和开发环境, 只支持单机版本
function windows() {
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} dgiot ${verType} windos deploy start${NC}"
2022-04-18 21:10:15 +08:00
set +uxe
2021-12-30 17:32:52 +08:00
# initdb -D /data/dgiot/dgiot_pg_writer/data/
# pg_ctl -D /data/dgiot/dgiot_pg_writer/data/ -l logfile start
# pg_ctl.exe register -N pgsql -D /data/dgiot/dgiot_pg_writer/data/
# net stop pgsql
# net start pgsql
/usr/local/lib/erlang/install
2022-01-17 12:32:03 +08:00
cd /data/bin/
2023-07-21 15:38:09 +08:00
wget ${fileserver}/parse_4.0.sql.tar.gz -O /data/bin/parse_4.0.sql.tar.gz &>/dev/null
tar xvf parse_4.0.sql.tar.gz &>/dev/null
2021-12-30 17:32:52 +08:00
./dgiot_hub.exe start
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} install parse_server success${NC}"
2021-12-30 17:32:52 +08:00
}
2022-04-18 21:10:15 +08:00
function centos() {
# Install app and data node
2023-07-21 15:38:09 +08:00
if [ -x ${install_dir}/dgiot ]; then
update_dgiot
update_dashboard
update_html
#update_tdengine_server
#restore_parse_data # 加载默认档案数据
else
pre_install
clean_services
deploy_postgres
restore_parse_data # 档案数据
deploy_tdengine_server # 时序数据
install_go_fastdfs # 文件数据
#install_word_report # 报告服务
deploy_parse_server # Api网关
#install_erlang_otp
install_dgiot
# install_n2n
build_nginx
#install_node_exporter
fi
2022-04-18 21:10:15 +08:00
}
2021-09-08 19:01:21 +08:00
2022-04-18 21:10:15 +08:00
function single() {
pg_eip=${lanip}
pg_auth=${pg_pwd}
## windows单机版本部署(待完成)
if [ "${os_type}" == 3 ]; then
windows
else ## linux单机版本目前只支持centos 7.6/7.9
centos
fi
}
function cluster() {
#如果数据节点ip和本机ip相同则部署数据节点
if [ ${pg_eip} == "changeyourip" ]; then
pg_eip=${lanip}
pg_auth=${pg_pwd}
cluster_data
else
cluster_app
fi
}
## dgiot集群部署包含三类节点
# 1、数据存储节点(data),可以通过eip给数据消费节点和数据生产节点提供数据读写功能
# 2、数据消费节点(consume),可以通过eip给外部用户提供高可用的数据消费,对设备数据只能读,不能写
# 3、数据生产节点(product)可以从内部子系统或者设备的数据源获取数据并通过eip存储到数据节点
# 部署顺序是首先安装数据存储节点,然后再部署数据生产节点和数据消费节点
# 部署数据生产节点和数据消费节点时需要输入数据存储节点的eip地址
### ----begin dgiot cluster ----- ##
##---- User layer -----------------##
## |eip| ##
##----- dgiot consume node --------##
## |eip| ##
##----- dgiot data node -----------##
## |eip| ##
##----- dgiot product node --------##
## |c1| |c2| |..| |cn| ##
##---- Data source layer ----------##
function cluster_data() {
#数据存储节点部署
if [ -x ${install_dir}/dgiot ]; then
build_nginx
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} please update dgiot ${verType} node by youself${NC}"
2022-04-18 21:10:15 +08:00
else
pre_install
2023-07-21 15:38:09 +08:00
deploy_postgres # 配置数据
restore_parse_data # 配置数据
deploy_tdengine_server # 时序数据
install_go_fastdfs # 文件数据
install_prometheus # 运维统计服务
install_grafana # 运维可视化服务
install_postgres_exporter # postgres数据运维监视
install_node_exporter # 服务器系统数据运维监视
2022-04-18 21:10:15 +08:00
fi
}
function cluster_app() {
#数据生产节点部署
if [ -x ${install_dir}/dgiot ]; then
update_dgiot
update_dashboard
update_tdengine_server
else
pre_install
2023-07-21 15:38:09 +08:00
deploy_parse_server # Api网关
2022-04-18 21:10:15 +08:00
install_erlang_otp
install_dgiot
build_nginx
install_node_exporter
fi
}
### ----end dgiot cluster -------
function devops() {
2023-07-21 15:38:09 +08:00
#一键式开发环境
2023-08-11 10:09:37 +08:00
install_ndoe
build_iotEdit
build_iotView
install_erlang_otp
2023-07-21 15:38:09 +08:00
pre_build_dgiot
make
post_build_dgiot
2022-04-18 21:10:15 +08:00
}
function ci() {
2023-07-21 15:38:09 +08:00
#一键式持续集成
2023-08-11 10:09:37 +08:00
install_ndoe
build_iotEdit
build_iotView
install_erlang_otp
2023-07-21 15:38:09 +08:00
pre_build_dgiot
make ci
post_build_dgiot
2022-04-18 21:10:15 +08:00
}
## ==============================end deploy type ============================
function deploy_dgiot() {
set -e
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} dgiot ${deployType} deploy start${NC}"
2022-04-18 21:10:15 +08:00
# centos单机版本部署(已完成)
if [ "${deployType}" == "single" ]; then
2023-07-21 15:38:09 +08:00
single
2022-04-18 21:10:15 +08:00
# cluster step 1 数据存储节点部署 (待完成)
elif [ "${deployType}" == "cluster" ]; then
2023-07-21 15:38:09 +08:00
cluster
2022-04-18 21:10:15 +08:00
# 本地开发环境部署 (已完成)
elif [ "${deployType}" == "devops" ]; then
2023-07-21 15:38:09 +08:00
devops
2022-04-18 21:10:15 +08:00
# 持续集成环境部署 (已完成)
elif [ "${deployType}" == "ci" ]; then
2023-07-21 15:38:09 +08:00
ci
2021-12-30 17:32:52 +08:00
else
2023-07-21 15:38:09 +08:00
echo "please input correct deployType"
2021-12-30 17:32:52 +08:00
fi
2022-04-18 21:10:15 +08:00
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${GREEN} dgiot ${deployType} deploy success end${NC}"
2022-04-18 21:10:15 +08:00
}
## ==============================Main program starts from here============================
if [ "$1" == "-h" ]; then
help
2021-09-08 19:01:21 +08:00
fi
2021-12-03 16:39:47 +08:00
2022-04-18 21:10:15 +08:00
###---------------------------- prepare config-------------------------------------------------
## 当前支持cetos 7.6/7.9, 计划支持windows
check_os_type
## shell parameter init
dgiot_shell
# ============================= get input parameters =================================================
# dgiot_install.sh -v [single | cluster | devops | ci] -s [dgiot_n] -p [dgiot_your_plugin] -m [dgiotmd5] -d [your_domain_name] -e [datanode_eip] -s [pg_auth]
# set parameters by default value
2023-07-21 15:38:09 +08:00
deployType=single # [single | cluster | devops | ci]
domain_name="prod.dgiotcloud.cn" # [prod.dgiotcloud.cn | your_domain_name]
plugin="dgiot" # [dgiot | dgiot_your_plugin]
software="dgiot_b23" # [dgiot_b20| dgiot_n]
dgiotmd5="ccaa89c901971158cbc75981e018cf46" # [dgiotmd5]
pg_eip="changeyourip" # [datanode_eip]
pg_auth='changeyourpassword' # [pg_auth]
islanip="false" # [islanip]
html_software="dgiot_html_4.8.3" # [dgiot_html_4.8.2| dgiot_html_n]
htmlmd5="31175b6acd8823087e54c3bf836786aa" # [htmlmd5]
while getopts "v:s:p:m:d:e:a:n:" arg; do
2022-04-18 21:10:15 +08:00
case $arg in
2023-07-21 15:38:09 +08:00
v)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} deployType=$OPTARG${NC}"
deployType=$(echo $OPTARG)
;;
s)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} software=$OPTARG${NC}"
software=$(echo $OPTARG)
;;
m)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} dgiotmd5=$OPTARG${NC}"
dgiotmd5=$(echo $OPTARG)
;;
p)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} plugin=$OPTARG${NC}"
plugin=$(echo $OPTARG)
ps
;;
d)
domain_name=$(echo $OPTARG)
echo "Please ensure that the certificate file has been placed in ${script_dir}"
echo -e "$(date +%F_%T) $LINENO: ${RED} Please ensure that the certificate file has been placed in ${script_dir}${NC}"
echo -e "$(date +%F_%T) $LINENO: ${GREEN} Please ensure that the certificate file has been placed in $(pwd)${NC}"
if [ ! -f ${script_dir}/${domain_name}.zip ]; then
echo -e "$(date +%F_%T) $LINENO: ${RED} ${script_dir}/${domain_name}.zip cert file not exist ${NC}"
exit 1
fi
;;
e)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} pg_eip=$OPTARG${NC}"
pg_eip=$(echo $OPTARG)
;;
a)
echo -e "$(date +%F_%T) $LINENO: ${GREEN} pg_auth=$OPTARG${NC}"
pg_auth=$(echo $OPTARG)
;;
n)
islanip=$(echo $OPTARG)
;;
?) #unknow option
help
;;
2022-04-18 21:10:15 +08:00
esac
done
## 不需要人机交互的参数初始化
dgiot_auto_variables
###---------------------------- install dgiot-------------------------------------------------
deploy_dgiot
###---------------------------- install dgiot-------------------------------------------------
2023-07-21 15:38:09 +08:00
echo -e "$(date +%F_%T) $LINENO: ${RED} database login info${NC}"
echo -e "$(date +%F_%T) $LINENO: ${RED} pg_info: postgres://postgres:${pg_auth}@${pg_eip}:7432/parse${NC}"
echo -e "$(date +%F_%T) $LINENO: ${RED} pg_info: pg_eip=${pg_eip} pg_auth=${pg_auth}${NC}"
echo -e "$(date +%F_%T) $LINENO: ${RED} parse_info: http://${wlanip}:1337/dashboard/ ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${RED} parse_info: username=${parse_user} password=${parse_pwd} ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${RED} dashboard: http://${wlanip}/ ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${RED} dashboard: username=dgiot_dev password=dgiot_dev ${NC}"