Ali cloud built using the WordPress website - build basic Web applications

WordPress is a very popular blog site platform, can also be used as a content management system (CMS) to use, is one of the world's most widely used blog system. There are many excellent WordPress plugin that makes this open-source product very easily scale to meet different needs.
I am ready to take advantage of a series of articles, to show a variety of products (elastic computing, database, security, etc.) If you use Ali cloud, build a complete WordPress site. content include:

First, the basic building web applications

To build a basic website is quite simple, we go step by step, this part of the organization chart below, include:

  • VPC Virtual Network: Ali established in the public cloud environment out of a two-story logically isolated local area network environment, most of the products that will be deployed in a secure environment
  • ECS server: Install WordPress application is the core of the entire site
  • MySQL database: data stored in WordPress
  • NAS file storage: Store WordPress application files and upload files
  • Elastic public network IP (EIP): Foreign exposed IP address

1

VPC Virtual Network ready

VPC Virtual Network ( https://www.aliyun.com/product/vpc ) need to plan, can be very simple, a routing table to get a VPC; can also be very complex, cross-regional and multi-room VPC also the line do not conflict. Network planning proposals take a look at this: https://help.aliyun.com/document_detail/54095.html . In order to facilitate this presentation, a simple way to the VPC.
1

EIP ready elasticity public IP

最好不要用ECS的绑定固定IP,未来升级换代迁移啥啥都不方便,买个BGP多线公网EIP(https://www.aliyun.com/product/eip),可以方便地把IP保留下来,价格也和固定IP一样,没道理不选EIP。购买之后IP记下来备用。
1

准备ECS服务器

对于WordPress来说,通用型g5系列或者计算型的c5系列都是不错的ECS服务器(https://www.aliyun.com/product/ecs)选择,操作系统我选的是CentOS,大家可以随意。
注意使用的VPC,另外注意不申请公网带宽,绑定之前那个弹性公网IP比较灵活。
1

ECS启动起来后,绑定前面买的EIP
1

1

确定安全组里面80端口是打开的(默认是打开的),WordPress一般是利用80端进行对外服务的。如果没有打开的话,填一条也很简单。

1

准备MySQL数据库

WordPress使用的是MySQL数据库(https://www.aliyun.com/product/rds/mysql)。阿里云MySQL数据库的高可用版采用经典一主一备的双机热备架构,适合80%以上的业务情况。主节点故障时,主备节点秒级完成切换,整个切换过程对应用透明。提供单可用区实例和多可用区实例,主备节点位于同一地域的不同可用区,提供跨可用区的容灾能力,且不额外收费。买的时候要注意VPC的选择。
1

启动起来之后,需要加载内网地址(添加ECS白名单)才能用起来。选择对应的ECS即可。

8
9
10
11

创建好了之后注意获取内网地址,后面会用到。
12

然后为数据库创建账号一个root,为了演示方便我开了一个高权限账号,但是也比较危险,建议大家还是老老实实用普通账号做授权吧。
13
14

然后添加一个空的数据库wordpress给应用使用,因为有了root账号,就没有用授权账号了
15
16

准备NAS文件存储

为什么要用到NAS存储(https://www.aliyun.com/product/nas)呢?主要原因在于未来进行横向扩展之后,应用数据不再需要复制同步,方便运维。可以来一个SSD性能型,另外最近还上了一款更厉害的极速型,时延可以达到0.5ms,回头有机会可以试一下。
17

创建之后添加一个挂载点,注意选择VPC。
18
19

创建完成后记录下来挂载点,备后面使用。
20

在ECS中挂载NAS

首先将NAS挂载上面,参考:https://help.aliyun.com/document_detail/91476.html
用root用户登陆到ECS里面去,并执行下面的命令,安装NFS客户端并创建挂载目录。

sudo yum install nfs-utils
mkdir /root/wordpressdata

为了可以实现开机自动挂载NFS,需要修改/etc/fstab文件并添加类似下面这样的一条记录。注意里面的挂载点要替换成前面创建的NAS挂载点,挂载目录如果有变化也需要注意。

12bcb24a3ad-mkb68.cn-hongkong.nas.aliyuncs.com:/
 /root/wordpressdata nfs4 
vers=4.0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0

21

然后重启ECS,用df –h命令查看一下是否确实挂载成功。如果没有挂载成功怎么办?再重启一次试试!
22

在ECS中安装Docker并启动WordPress镜像

WordPress installation refer to the official installation manual, https://codex.wordpress.org/zh-cn:%E5%AE%89%E8%A3%85_WordPress . The demonstration I used docker way, relatively more convenient. In the spirit of their torment more fun, he made himself a docker very convenient. Ali cloud also has its own container instance ECI elastic ( https://www.aliyun.com/product/eci ), are interested can try.
First install docker, Reference: https://docs.docker.com/install/linux/docker-ce/centos/

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

23

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

24

sudo yum install docker-ce docker-ce-cli containerd.io

25

The following two commands, first start docker, a second let docker can be started automatically restart when the ECS

sudo systemctl start docker
sudo systemctl enable docker

docker installed, and then starts pulling WordPress mirrored in the ECS. Start by creating a directory in which to store the NAS WordPress application files, and image maps in / var / www / html directory to the directory. It would also be 80-port also mapped out.

mkdir /root/wordpressdata/html
docker run --name mywordpress \
-p 80:80 \
-v /root/wordpressdata/html:/var/www/html \
-d --restart=always wordpress

26

Use docker ps look is not running again.

docker ps

27

Set in the ECS WordPress

Open your browser and enter the address of EIP, if nothing else can open the WordPress site. For the first time set the language, of course, it is Chinese friends.
28

The second step set up a database, which is the time to create a database of information previously provided.
1

Then set the site name, administrator user and other information.
30

Not surprisingly, so get with IP can access WordPress site.
1

Guess you like

Origin yq.aliyun.com/articles/702597