建立並測試範例應用程式的基本 Cloud Assembly 範本後,將其擴充到多層應用程式,該應用程式可部署至開發、測試環境,並最終部署到生產環境。
若要擴充雲端範本,請新增下列增強功能。
- 用於叢集化應用程式伺服器以增加容量的選項
- 應用程式伺服器前方的公用網路和負載平衡器
- 具有封存儲存區的備份伺服器
程序
範例: 擴充的雲端範本代碼已完成的範例
inputs: env: type: string enum: - 'env:dev' - 'env:prod' - 'env:test' default: 'env:dev' title: Environment description: Target Environment size: type: string enum: - small - medium - large description: Size of Nodes title: Tier Machine Size username: type: string minLength: 4 maxLength: 20 pattern: '[a-z]+' title: Database Username description: Database Username userpassword: type: string pattern: '[a-z0-9A-Z@#$]+' encrypted: true title: Database Password description: Database Password databaseDiskSize: type: number default: 4 maximum: 10 title: MySQL Data Disk Size description: Database Disk Size count: type: integer default: 2 maximum: 5 minimum: 2 title: WordPress Cluster Size description: WordPress Cluster Size (Number of Nodes) archiveDiskSize: type: number default: 4 maximum: 10 title: WordPress Archive Disk Size description: Archive Storage Disk Speed archiveusage: type: string enum: - 'usage:general' - 'usage:fast' description: Archive Storage Disk Speed title: Archive Disk Speed resources: DBTier: type: Cloud.Machine properties: name: mysql image: ubuntu-16 flavor: '${input.size}' constraints: - tag: '${input.env}' networks: - network: '${resource["WP-Network-Private"].id}' assignPublicIpAddress: true remoteAccess: authentication: usernamePassword username: '${input.username}' password: '${input.userpassword}' cloudConfig: | #cloud-config repo_update: true repo_upgrade: all packages: - mysql-server runcmd: - sed -e '/bind-address/ s/^#*/#/' -i /etc/mysql/mysql.conf.d/mysqld.cnf - service mysql restart - mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysqlpassword';" - mysql -e "FLUSH PRIVILEGES;" attachedDisks: [] WebTier: type: Cloud.Machine properties: name: wordpress flavor: '${input.size}' image: 'ubuntu-16' count: '${input.count}' constraints: - tag: '${input.env}' networks: - network: '${resource["WP-Network-Private"].id}' assignPublicIpAddress: true storage: disks: - capacityGb: '${input.archiveDiskSize}' name: ArchiveDisk cloudConfig: | #cloud-config repo_update: true repo_upgrade: all packages: - apache2 - php - php-mysql - libapache2-mod-php - php-mcrypt - mysql-client runcmd: - mkdir -p /var/www/html/mywordpresssite && cd /var/www/html && wget https://wordpress.org/latest.tar.gz && tar -xzf /var/www/html/latest.tar.gz -C /var/www/html/mywordpresssite --strip-components 1 - i=0; while [ $i -le 10 ]; do mysql --connect-timeout=3 -h ${DBTier.networks[0].address} -u root -pmysqlpassword -e "SHOW STATUS;" && break || sleep 15; i=$((i+1)); done - mysql -u root -pmysqlpassword -h ${DBTier.networks[0].address} -e "create database wordpress_blog;" - mv /var/www/html/mywordpresssite/wp-config-sample.php /var/www/html/mywordpresssite/wp-config.php - sed -i -e s/"define( 'DB_NAME', 'database_name_here' );"/"define( 'DB_NAME', 'wordpress_blog' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define( 'DB_USER', 'username_here' );"/"define( 'DB_USER', 'root' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define( 'DB_PASSWORD', 'password_here' );"/"define( 'DB_PASSWORD', 'mysqlpassword' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define( 'DB_HOST', 'localhost' );"/"define( 'DB_HOST', '${DBTier.networks[0].address}' );"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define('DB_HOST', 'localhost');"/"define('DB_HOST', '${DBTier.networks[0].address}');"/ /var/www/html/mywordpresssite/wp-config.php - service apache2 reload LoadBalancer: type: Cloud.LoadBalancer properties: name: myapp-lb network: '${resource["WP-Network-Public"].id}' instances: - '${WebTier.id}' routes: - protocol: HTTP port: '80' instanceProtocol: HTTP instancePort: '80' healthCheckConfiguration: protocol: HTTP port: '80' urlPath: /mywordpresssite/wp-admin/install.php intervalSeconds: 6 timeoutSeconds: 5 unhealthyThreshold: 2 healthyThreshold: 2 internetFacing: true WP-Network-Private: type: Cloud.Network properties: name: WP-Network-Private networkType: existing constraints: - tag: 'type:isolated-net' - tag: '${input.env}' WP-Network-Public: type: Cloud.Network properties: name: WP-Network-Public networkType: public constraints: - tag: 'type:public-net' - tag: '${input.env}' backup: type: Cloud.Machine properties: name: backup flavor: '${input.size}' image: 'ubuntu-16' networks: - network: '${resource["WP-Network-Private"].id}' constraints: - tag: '${input.env}' attachedDisks: - source: '${ArchiveDisk.id}' ArchiveDisk: type: Cloud.Volume properties: name: ArchiveDisk capacityGb: 5 constraints: - tag: '${input.archiveusage}' - tag: '${input.env}'
後續步驟
定義您自己的基礎結構,並建立您自己的雲端範本。