IBM Cloud 2019 - Cloud Load Balance 负载均衡 教程01

IC云上面的负载均衡有 CIS, CLB, LLB 多种不同类型。

CLB - Cloud LB网上有教程,大家可以简单联系一下,熟悉整个操作过程和参数配置。(其实所有的云的LB配置都较简单)

教程说明

教程01 https://cloud.ibm.com/docs/tutorials?topic=solution-tutorials-highly-available-and-scalable-web-application

说明: 1个CLB连到2台web, 这2台web配置成双份(同步)文件存储和备份。2台Web 连到1台DB.

 

IBM Cloud 2019 - Cloud Load Balance 负载均衡 教程01_第1张图片

 

 

教程步骤

教程01 操作步骤

 

0. 权限,VPN等前提条件都配置好

 

1. 创建1 vm

Name= db1

OS= ubuntu minimal

Size= 1C1G25GB,100Mbps

 

 

2. 安装配置mysql

ssh root@

# apt-get update

# apt-get -y install mysql-server

# mysql_secure_installation    pwd= password

# mysql -u root -p

CREATE DATABASE wordpress;

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO root@'%' IDENTIFIED BY 'password';

FLUSH PRIVILEGES;

show databases;

exit

# nano /etc/mysql/my.cnf

[mysqld]

bind-address    = 0.0.0.0

 

# systemctl restart mysql

# netstat --listen --numeric-ports | grep 3306

 

3 创建 file storage

https://cloud.ibm.com/catalog/infrastructure/file-storage

Type= Endurance, Loc= hk2, bill=hour, size=20, IOPS= 2, snapshot=0,

 

Order id = 54898142,

File storage 创建后的名字            IBM02SEV1503677_95,

mount endpoint = fsf-hkg0201e-fz.service.softlayer.com:/IBM02SEV1503677_95/data01

菜单 authr device, 选device guest= 刚才创建的VM,进行授权

 

View list https://cloud.ibm.com/classic/storage/file

如果item太多,可以在菜单file storage filter 机房位置,大小来缩小查找范围

 

 

4. 在db1 VM上mount

# apt-get update

# apt-get -y install nfs-common

# touch /etc/systemd/system/mnt-database.mount

# nano /etc/systemd/system/mnt-database.mount

[Unit]

Description = Mount for Container Storage

[Mount]

What= fsf-hkg0201e-fz.service.softlayer.com:/IBM02SEV1503677_95/data01

Where=/mnt/database

Type=nfs

Options=vers=3,sec=sys,noauto

[Install]

WantedBy = multi-user.target

 

# mkdir /mnt/database

# systemctl enable --now /etc/systemd/system/mnt-database.mount

# mount

 

5. 创建备份脚本

# vi /root/dbbackup.sh

#!/bin/bash

mysqldump -u root -p CHANGE_ME --all-databases --routines | gzip > /mnt/datamysql/backup-`date '+%m-%d-%Y-%H-%M-%S'`.sql.gz

 

# chmod 700 /root/dbbackup.sh

# crontab -e 修改crontab 输入下面内容

# 0 23 * * * /root/dbbackup.sh

 

6. 创建2 VM php web

Name=app1, app2, os=ubuntu minimal, size=1c1c25gb, 100Mbps,

 

7,创建 file storage between 2 web vm

https://cloud.ibm.com/catalog/infrastructure/file-storage

Type= Endurance, Loc= hk2, bill=hour, size=20, IOPS= 2, snapshot=20,

Order id= 54906554

File storage 创建后的名字            IBM02SEV1503677_96,

mount endpoint = fsf-hkg0201f-fz.service.softlayer.com:/IBM02SEV1503677_96/data01

 

edit snapshot 这一步可以不做

 hourly 30, 24 copy

 daily 11pm, 7 copy

 weekly 1am,4 copy

Authorized Hosts, click Authorize Host to authorize the application servers(app1 and app2)

 

 

8. 在app1 和 app2 的VM上mount

# apt-get update

# apt-get -y install nfs-common

# touch /etc/systemd/system/mnt-www.mount

# vi /etc/systemd/system/mnt-www.mount

[Unit]

Description = Mount for Container Storage

[Mount]

What= fsf-hkg0201f-fz.service.softlayer.com:/IBM02SEV1503677_96/data01

Where=/mnt/www

Type=nfs

Options=vers=3,sec=sys,noauto

[Install]

WantedBy = multi-user.target

 

# mkdir /mnt/www

# systemctl enable --now /etc/systemd/system/mnt-www.mount

# mount

 

9. 安装php web应用到app1和 app2 VM

# apt-get update

# apt-get -y install nginx

# apt-get -y install php-fpm php-mysql

# systemctl stop php7.2-fpm

# systemctl stop nginx

# vi /etc/nginx/sites-available/default

server {

       listen 80 default_server;

       listen [::]:80 default_server;

       root /mnt/www/html;

       index index.php;

       server_name _;

       location = /favicon.ico {

               log_not_found off;

               access_log off;

       }

       location = /robots.txt {

               allow all;

               log_not_found off;

               access_log off;

       }

       location / {

               # following https://codex.wordpress.org/Nginx

               try_files $uri $uri/ /index.php?$args;

       }

       # pass the PHP scripts to the local FastCGI server

       location ~ \.php$ {

               include snippets/fastcgi-php.conf;

               fastcgi_pass unix:/run/php/php7.2-fpm.sock;

       }

       location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {

               expires max;

               log_not_found off;

       }

       # deny access to .htaccess files, if Apache's document root

       # concurs with nginx's one

       location ~ /\.ht {

               deny all;

       }

}

 

# mkdir -p /mnt/www/html

# apt-get -y install curl

# cd /tmp

# curl -O https://wordpress.org/latest.tar.gz

# scp latest.tar.gz [email protected]:/tmp 

在另外一台机器重复操作一遍 # scp latest.tar.gz root@10.110.108.101:/tmp

 

# cd /tmp

# tar xzvf latest.tar.gz

# cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

# mkdir /tmp/wordpress/wp-content/upgrade

# rsync -av -P /tmp/wordpress/. /mnt/www/html

# chown -R www-data:www-data /mnt/www/html

find /mnt/www/html -type d -exec chmod g+s {} \;

chmod g+w /mnt/www/html/wp-content

chmod -R g+w /mnt/www/html/wp-content/themes

chmod -R g+w /mnt/www/html/wp-content/plugins

# curl -s https://api.wordpress.org/secret-key/1.1/salt/

vi /mnt/www/html/wp-config.php  修改为后台db的参数

define('DB_NAME', 'wordpress');

define('DB_USER', 'root');

define('DB_PASSWORD', 'password');

define('DB_HOST', '10.110.108.87');

 

启动服务

# systemctl start php7.2-fpm

# systemctl start nginx

 

浏览器测试一下 http://119.81.237.84/    http://119.81.237.87/   

如果需要配置wordpress , 输入http://119.81.237.87/wp-admin/  这一步先不做,后面做

 

10. 创建 Cloud Load Balance

菜单 https://cloud.ibm.com/catalog/infrastructure/ibm-cloud-load-balancer

Name= clb-app-lb-1

DC=HK2 和刚才app1,app2 同一个机房

Type=public to private,  

subnet of app1, app2,

public ip= allocate from ibm system pool

protocol = 默认

add server= app1, app2

点击create 创建

 

创建后检查,在 https://cloud.ibm.com/classic/network/loadbalancing/cloud

上面菜单按钮有refresh table, 需要等2-5分钟,才会把刚才创建的CLB item灰色变成正常使用状态

Address = clb-app-lb-1-1503677-hkg02.clb.appdomain.cloud

Ip = 119.81.229.4

 

11. 修改应用wordpress 的配置,  以使用LB URL

浏览器 http://119.81.237.84/   

菜单Settings / General, set both the Wordpress Address (URL) and Site Address (URL) to the Load Balancer address

http://119.81.237.87/wp-admin/options-general.php

wordpress address url=  http://119.81.229.4  (#就是前端CLB的IP地址)

site address url = http:// 119.81.229.4

参数参考https://wordpress.org/support/article/settings-general-screen/

 

12. 测试整个环境 LB加2Web

A 命令行

看nginx log  

# tail -f /var/log/nginx/*.log 

关闭nginx

# systemctl stop nginx

重启 nginx

# systemctl start nginx

 

B 测试次序

同时登录2台机器里面app1, app2,停止或者重启nginx, 再打开log,前端仍然不断reload page of LB url   

1) 在app1机器,停止nginx,

2) 在app2机器,停止nginx, 如果2台机器都关了,LB页面会显示503 Service Unavailable

3) 在app1机器,重启nginx,

4) 在app2机器,重启nginx,

 

 

《完》

 

 

你可能感兴趣的:(IBM,Cloud,2019)