1. 程式人生 > >攜程Apollo一鍵編譯腳本+部署實現

攜程Apollo一鍵編譯腳本+部署實現

inf pri nexus rec mar mysql script apt grep -v

系統編譯安裝

  • ubuntu16.11
  • java 1.8

系統規劃

  • Portal共用
  • 其它環境每個兩臺機器
  • mysql都做主從,所以每個環境的機器上都會安裝admin 服務,config服務,以及一個mysql服務

envipusage
all 192.168.1.1 portal
dev 192.168.2.1 admin+config+configdb
dev 192.168.2.2 admin+config+configdb
test 192.168.3.1 admin+config+configdb
test 192.168.3.2 admin+config+configdb
pre 192.168.4.1 admin+config+configdb
pre 192.168.4.2 admin+config+configdb
pro 192.168.5.1 admin+config+configdb
pro 192.168.5.2 admin+config+configdb

#!/bin/bash
## 先安裝jdk1.8以上到/usr/local/java 並設置系統環境變量
java -version
base_home="/home/test/Desktop"
############################################################################
dev_meta="http://192.168.2.1:8080,http://192.168.2.2:8080"
fat_meta="http://192.168.3.1:8080,http://192.168.3.2:8080"
uat_meta="http://192.168.4.1:8080,http://192.168.4.2:8080"
pro_meta="http://192.168.5.1:8080,http://192.168.5.2:8080"

########### portal 數據庫 ,共用一個
# apollo portal db info
apollo_portal_db_url=jdbc:mysql://192.168.1.1:3306/ApolloPortalDB?characterEncoding=utf8
apollo_portal_db_password=portal_root_db_password

############ 四個環境的配置數據庫
# apollo dev config db info
dev_apollo_config_db_url=jdbc:mysql://192.168.2.1:3306/ApolloConfigDB?characterEncoding=utf8
dev_apollo_config_db_password=dev_config_root_db_password
# apollo fat config db info
fat_apollo_config_db_url=jdbc:mysql://192.168.3.1:3306/ApolloConfigDB?characterEncoding=utf8
fat_apollo_config_db_password=fat_config_root_db_password
# apollo uat config db info
uat_apollo_config_db_url=jdbc:mysql://192.168.4.1:3306/ApolloConfigDB?characterEncoding=utf8
uat_apollo_config_db_password=uat_config_root_db_password
# apollo pro config db info
pro_apollo_config_db_url=jdbc:mysql://192.168.5.1:3306/ApolloConfigDB?characterEncoding=utf8
pro_apollo_config_db_password=pro_config_root_db_password

########################## 以下勿更改
build_sh() {
    cd "$base_home/apollo"
    cp -pr apollo apollo_$1
    cd apollo_$1/scripts
    # apollo config db info
    apollo_config_db_url=$2
    apollo_config_db_username=root
    apollo_config_db_password=$3
    # apollo portal db info
    apollo_portal_db_url=$4
    apollo_portal_db_username=root
    apollo_portal_db_password=$5
    # meta server url, different environments should have different meta server addresses
    dev_meta=$6
    fat_meta=$7
    uat_meta=$8
    pro_meta=$9
    META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_meta -Dpro_meta=$pro_meta"
    # =============== Please do not modify the following content =============== #
    # go to script directory
    cd "${0%/*}"
    cd ..
    # package config-service and admin-service
    echo "==== starting to build config-service and admin-service ===="
    mvn clean package -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password
    echo "==== building config-service and admin-service finished ===="
    echo "==== starting to build portal ===="
    mvn clean package -DskipTests -pl apollo-portal -am -Dapollo_profile=github,auth -Dspring_datasource_url=$apollo_portal_db_url -Dspring_datasource_username=$apollo_portal_db_username -Dspring_datasource_password=$apollo_portal_db_password $META_SERVERS_OPTS
    echo "==== building portal finished ===="
    echo "==== starting to build client ===="
    mvn clean install -DskipTests -pl apollo-client -am $META_SERVERS_OPTS
    echo "==== building client finished ===="

}

####################初始化環境,下載apollo
sudo apt-get install -y maven git
sudo sed -i ‘/<mirrors>/a\<mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url></mirror>‘ /etc/maven/settings.xml
mkdir -p apollo
cd apollo
git clone https://github.com/ctripcorp/apollo.git
source /etc/profile
sudo mv /usr/bin/java /usr/bin/java_bak
sudo ln -s /usr/local/java/bin/java /usr/bin/
###########################################

##### dev
build_sh "dev" "$dev_apollo_config_db_url"     "$dev_apollo_config_db_password"     "$apollo_portal_db_url"     "$apollo_portal_db_password"     "$dev_meta" "$fat_meta" "$uat_meta" "$pro_meta"
build_sh "fat" "$fat_apollo_config_db_url"     "$fat_apollo_config_db_password"     "$apollo_portal_db_url"     "$apollo_portal_db_password"     "$dev_meta" "$fat_meta" "$uat_meta" "$pro_meta"

build_sh "uat" "$uat_apollo_config_db_url"     "$uat_apollo_config_db_password"     "$apollo_portal_db_url"     "$apollo_portal_db_password"     "$dev_meta" "$fat_meta" "$uat_meta" "$pro_meta"

build_sh "pro" "$pro_apollo_config_db_url"     "$pro_apollo_config_db_password"     "$apollo_portal_db_url"     "$apollo_portal_db_password"     "$dev_meta" "$fat_meta" "$uat_meta" "$pro_meta"

######################### 添加本地jar包到本地mvn
dev_home="$base_home/apollo/apollo_dev"
apollo_version=`ls $dev_home/apollo-client/target/apollo-client-*.jar |grep -v sources |sed ‘s/.jar//g‘ |sed "s#.*apollo-client-##g"`
mvn install:install-file -DgroupId=com.ctrip.framework.apollo -DartifactId=apollo-client -Dversion=$apollo_version -Dpackaging=jar -Dfile=$dev_home/apollo-client/target/apollo-client-$apollo_version.jar
mvn install:install-file -DgroupId=com.ctrip.framework.apollo -DartifactId=apollo-core -Dversion=$apollo_version -Dpackaging=jar -Dfile=$dev_home/apollo-core/target/apollo-core-$apollo_version.jar
mvn install:install-file -DgroupId=com.ctrip.framework.apollo -DartifactId=apollo-buildtools -Dversion=$apollo_version -Dpackaging=jar -Dfile=$dev_home/apollo-buildtools/target/apollo-buildtools-$apollo_version.jar
mvn install:install-file -DgroupId=com.ctrip.framework.apollo -DartifactId=apollo-common -Dversion=$apollo_version -Dpackaging=jar -Dfile=$dev_home/apollo-common/target/apollo-common-$apollo_version.jar
#mkdir -p /opt/setting
#echo ‘env=DEV‘ > /opt/setting/server.properties

安裝Portal

Portal是共用的,代碼都一樣,所以這裏從dev環境拿個編譯包就可以

  1. portal服務器的mysql上面執行該SQL : apollo/apollo_dev/scripts/sql/apolloportaldb.sql
    1. 修改數據表ApolloPortalDB.ServerConfig配置如下,修改 apollo.portal.envs : dev,fat,uat,pro
  2. 上傳 apollo/apollo_dev/apollo-portal/target/apollo-portal-0.11.0-SNAPSHOT-github.zip 到 portal服務器(192.168.1.1)/data/apollo_portal
  3. unzip apollo-portal-0.11.0-SNAPSHOT-github.zip
  4. 啟動portal ./scripts/startup.sh
  5. 訪問portal管理後臺 http://192.168.1.1:8080/ . 默認管理員 : apollo / admin

安裝config服務

···這裏以DEV環境設置為例···

  1. dev環境的兩個mysql做好主從,執行 apollo/apollo_dev/scripts/sql/apolloconfigdb.sql 的sql文件創建庫表
  2. 修改apolloconfigdb庫中的ServerConfig
    • 修改 eureka.service.url : http://192.168.2.1:8080/eureka/,http://192.168.2.1:8080/eureka/
    • 這裏根據環境不同修改,這裏配置的是dev環境的IP
  3. 上傳apollo/apollo_dev/apollo-configservice/target/apollo-configservice-0.11.0-SNAPSHOT-github.zip 到 dev兩個機器的/data/apollo_config 目錄裏面
  4. unzip apollo-configservice-0.11.0-SNAPSHOT-github.zip
  5. 啟動: ./scripts/startup.sh

安裝admin服務

  1. 上傳apollo/apollo_dev/apollo-adminservice/target/apollo-adminservice-0.11.0-SNAPSHOT-github.zip 到dev兩個服務器的/data/apollo_admin 目錄裏面
  2. unzip apollo-adminservice-0.11.0-SNAPSHOT-github.zip
  3. 啟動 scripts/startup.sh

  • 如果能看懂這個圖,Apollo的基本架構也就理解了。下一篇就開始來講講Apollo的一些組件,或是服務

技術分享圖片

攜程Apollo一鍵編譯腳本+部署實現