#!/bin/bash
mkdir -p /www/wwwroot/keyer
cd /www/wwwroot/keyer
yum -y install netdate

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum install -y wget
yum install -y unzip
wget https://axure.keyersoft.com/download/jdk-8u411-linux-x64.tar.gz
tar -xzvf jdk-8u411-linux-x64.tar.gz
export BASE_DIR=`pwd`
export JAVA_HOME=$BASE_DIR/jdk1.8.0_411
echo "export JAVA_HOME=$JAVA_HOME" >> /etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >>  /etc/profile
source /etc/profile
wget https://axure.keyersoft.com/download/mariadb-10.4.34-rhel-7-x86_64-rpms.tar
tar -xvf mariadb-10.4.34-rhel-7-x86_64-rpms.tar
cd mariadb-10.4.34-rhel-7-x86_64-rpms
yum -y  install rsync nmap lsof perl-DBI nc
rpm -ivh jemalloc-3.6.0-1.el7.x86_64.rpm
rpm -ivh jemalloc-devel-3.6.0-1.el7.x86_64.rpm
yum install boost-devel.x86_64 -y
rpm --import http://yum.mariadb.org/RPM-GPG-KEY-MariaDB
yum -y localinstall  galera-4-26.4.18-1.el7.centos.x86_64.rpm
yum install -y libaio
yum install -y automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel
wget https://archive.apache.org/dist/thrift/0.20.0/thrift-0.20.0.tar.gz
tar -xzvf thrift-0.20.0.tar.gz
cd thrift-0.20.0
./configure
make && make install
cd ../
wget http://rpmfind.net/linux/epel/7/x86_64/Packages/j/Judy-devel-1.0.5-8.el7.x86_64.rpm
yum localinstall -y Judy-devel-1.0.5-8.el7.x86_64.rpm
yum localinstall -y  MariaDB-common-10.4.34-1.el7.centos.x86_64.rpm MariaDB-compat-10.4.34-1.el7.centos.x86_64.rpm MariaDB-client-10.4.34-1.el7.centos.x86_64.rpm MariaDB-server-10.4.34-1.el7.centos.x86_64.rpm
systemctl restart mariadb
cd $BASE_DIR
mkdir sql
cd sql
wget https://axure.keyersoft.com/download/sql/xxl_job.sql
wget https://axure.keyersoft.com/download/sql/ks_industry_park.sql
wget https://axure.keyersoft.com/download/sql/ks_industry_book.sql
mysql -uroot  -e "CREATE USER 'keyersoft'@'%' IDENTIFIED BY 'Lkgl123456~@123'; GRANT ALL PRIVILEGES ON *.* TO 'keyersoft'@'%'; FLUSH PRIVILEGES;"
mysql -uroot  -e "CREATE DATABASE ks_industry_park  CHARACTER SET utf8mb4   COLLATE utf8mb4_unicode_ci;"
mysql -uroot  -e "CREATE DATABASE xxl_job  CHARACTER SET utf8mb4   COLLATE utf8mb4_unicode_ci;"
mysql -uroot  -e "CREATE DATABASE ks_industry_book  CHARACTER SET utf8mb4   COLLATE utf8mb4_unicode_ci;"
mysql -uroot  xxl_job <  $BASE_DIR/sql/xxl_job.sql
mysql -uroot  ks_industry_park <  $BASE_DIR/sql/ks_industry_park.sql
mysql -uroot  ks_industry_book <  $BASE_DIR/sql/ks_industry_book.sql
cd $BASE_DIR
wget  https://axure.keyersoft.com/download/nginx-1.26.1.tar.gz
tar -xzvf nginx-1.26.1.tar.gz
cd nginx-1.26.1
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
yum install -y fontconfig
wget http://kkfileview.keking.cn/fonts.zip
cp fonts.zip /usr/share/fonts/
cd /usr/share/fonts
unzip fonts.zip 
rm -rf fonts.zip 
mkfontscale
mkfontdir
fc-cache
cd $BASE_DIR
#yum install -y docker
sudo yum remove docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
wget -O /etc/yum.repos.d/docker-ce.repo https://axure.keyersoft.com/download/docker-ce.repo
sudo sed -i 's+download.docker.com+repo.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum makecache fast
sudo yum install -y docker-ce
systemctl start docker
mkdir docker
cd docker
wget https://axure.keyersoft.com/download/emqx_5.3.0.tar
wget https://axure.keyersoft.com/download/influxdb_2.7.1.tar
wget https://axure.keyersoft.com/download/kkfileview_4.1.0.tar
wget https://axure.keyersoft.com/download/rabbitmq_3.12-management.tar
docker load -i  emqx_5.3.0.tar
docker load -i influxdb_2.7.1.tar
docker load -i  kkfileview_4.1.0.tar
docker load -i rabbitmq_3.12-management.tar
chown -R 777 emqx
wget https://axure.keyersoft.com/download/docker-compose.yml
wget https://axure.keyersoft.com/download/docker-compose-Linux-x86_64
rename docker-compose-Linux-x86_64 docker-compose docker-compose-Linux-x86_64
wget https://axure.keyersoft.com/download/docker.zip
unzip docker.zip
chown -R 777 emqx
chmod +x docker-compose
./docker-compose up -d
firewall-cmd --zone=public --add-port=8090-8110/tcp --add-port=9000-9100/tcp --add-port=15060/tcp --add-port=15070/tcp --add-port=10000/tcp --add-port=10001/tcp --add-port=11935/tcp --add-port=30000-30249/tcp --add-port=15060/udp --add-port=15070/udp --add-port=10000/udp --add-port=10001/udp --add-port=11935/udp --add-port=30000-30500/udp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
cd $BASE_DIR
mkdir vhost
cd vhost
wget https://axure.keyersoft.com/download/nginx/nginx.conf
wget https://axure.keyersoft.com/download/nginx/book.conf
wget https://axure.keyersoft.com/download/nginx/park.conf
mv /usr/local/nginx/conf/nginx.conf  /usr/local/nginx/conf/nginx.keyer.bak
mv -r nginx.conf /usr/local/nginx/conf/
cd $BASE_DIR
mkdir service
cd service
wget https://axure.keyersoft.com/download/service/book.zip
wget https://axure.keyersoft.com/download/service/park.zip
wget https://axure.keyersoft.com/download/service/xxljob.zip
unzip book.zip
unzip park.zip
unzip xxljob.zip


