Use PolarDB and ECS to build a portal

Experience goal

This scenario is based on PolarDB and ECS to build a portal website.

background knowledge

Introduction to PolarDB database
PolarDB is a next-generation relational cloud database developed by Alibaba Cloud. It has three independent engines, which are 100% compatible with MySQL, 100% compatible with PostgreSQL, and highly compatible with Oracle syntax. The storage capacity is up to 100TB, and the single database is at most It can be expanded to 16 nodes and is suitable for enterprise diversified database application scenarios.

PolarDB adopts an architecture that separates storage and computing. All computing nodes share a data, providing minute-level configuration upgrades, second-level failure recovery, global data consistency, and free data backup and disaster recovery services. PolarDB not only integrates the stable, reliable, high-performance, and scalable characteristics of commercial databases, but also has the advantages of open source cloud databases that are simple, open, and self-iterative. For example, PolarDB MySQL can increase its performance up to 6 times that of MySQL, while the cost is only 1% of commercial databases. /10. Cluster architecture, separation of computing and storage.

  • Cluster architecture, separation of computing and storage.

PolarDB adopts a multi-node cluster architecture. There is a Writer node (primary node) and multiple Reader nodes (read nodes) in the cluster. Each node shares the underlying storage (PolarStore) through a distributed file system (PolarFileSystem).

  • Read and write separation.

When the application uses the cluster address, PolarDB MySQL/PostgreSQL provides services to the outside through the internal proxy layer (Proxy), and application requests are proxied first before accessing the database node. The proxy layer can not only perform security authentication and protection, but also parse SQL, send write operations (such as transactions, UPDATE, INSERT, DELETE, DDL, etc.) to the master node, and distribute read operations (such as SELECT) to multiple clients in a balanced manner. Read node, realize automatic read-write separation. For applications, it is as simple as using a single-point MySQL database. The internal proxy layer (Proxy) will support PolarDB to be compatible with the Oracle syntax engine in the future.

Experience preparation

In this scenario, PolarDB and ECS need to be opened. Alibaba
Cloud Experience Lab provides a 2-hour ECS experience
. New PolarDB users can purchase
1 yuan to open a PolarDB instance and storage package.

Connect to ECS server

  1. Open the terminal tool.
    • Windows: Open a command window.
    • MAC: Open the command line terminal Terminal.

Windows users, please check whether the SSH tool is installed in the system. Inspection Method:

Enter the command ssh -V in the terminal.

ssh -V

If the SSH version is displayed, it means it has been installed, as shown in the figure below.
Insert picture description here
If it is not installed, please download and install the OpenSSH tool.

  1. Enter the connection command ssh [username]@[ipaddress] in the terminal.
    You need to replace username and ipaddress with the elastic public IP of the ECS server created in step 1. E.g:
ssh [email protected]

Insert picture description here
The command display results are as follows:
Insert picture description here

  1. Enter yes.
  2. After agreeing to continue, you will be prompted to enter the login password. The password is the login password of the ECS of the created cloud service.
    Insert picture description here
    After successful login, the following information will be displayed.
    Insert picture description here

Install LAMP environment

LAMP refers to the environment of Apache, MySQL and PHP running under Linux. Refer to the following operations to install the development environment on the cloud server.
1. On the ECS server, execute the following commands to install the Apache service and its extension packages.

yum -y install httpd httpd-manual mod_ssl mod_perl mod_auth_mysql

If a result similar to the following figure is returned, the installation is successful.
Insert picture description here
2. PbootCMS is a CMS system developed using PHP language. Refer to the following operations to install the PHP environment.
Execute the following command to install PHP.

yum -y install php php-mysql gd php-gd gd-devel php-xml php-common php-mbstring php-ldap php-pear php-xmlrpc php-imap

3. Execute the following commands to download and install MySQL.

wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server

4. Execute the following command to start the MySQL database.

systemctl start mysqld

Build a portal website

After completing the environment deployment, refer to the following operations to build a portal website.
1. On the ECS server, execute the following command to install Git.

yum -y install git

2. On the ECS server, execute the following command to download the PbootCMS source file.

cd ~ && git clone https://gitee.com/hnaoyun/PbootCMS.git

3. Execute the following command to copy the installation package to Apache's wwwroot directory.

cp -r PbootCMS/* /var/www/html/

4. Execute the following command to modify the file permissions of the site root directory.

chmod -R a+w /var/www/html

5. Import the initial data of CMS into the database.
Execute the following command to initialize the table structure and data of the database pbootcms.
Note: Before executing the command, please modify the three parameters.

  • For the database connection address (public network address), please refer to the link address section application at the bottom of the cluster details page.
  • test_user is the database account created in step 2.
  • Password1213 The database password created in step 2.
sql_file="/var/www/html/static/backup/sql/"$(ls /var/www/html/static/backup/sql/) &&
mysql -h数据库连接地址 -utest_user -pPassword1213 -Dpbootcms < $sql_file

6. Execute the following commands to modify the CMS system database configuration.
Note: Before executing the command, please replace your database configuration according to the parameter description.

cat > /var/www/html/config/database.php << EOF
<?php
return array(
    'database' => array(
        'type' => 'mysqli', // 数据库连接驱动类型: mysqli,sqlite,pdo_mysql,pdo_sqlite
        'host' => '数据库连接地址', // PolarDB数据库链接地址
        'user' => 'test_user', // PolarDB数据库的用户名
        'passwd' => 'Password1213', // PolarDB数据库的密码
        'port' => '3306', // 数据库端口
        'dbname' => 'pbootcms' //数据库名称
    )
);
EOF

7. Return to the ECS console. On the ECS instance list page, click the created ECS instance ID link to enter the ECS details page.

  1. In the left navigation bar, click the security group of this instance, and then click the ID link of the security group to view the security group configuration.

Make sure that the security group opens port 80 for access, otherwise you cannot access the established portal. A security group is a virtual firewall with stateful inspection and packet filtering capabilities, and is used to divide security domains in the cloud. By configuring security group rules, you can control the inbound and outbound traffic of one or more ECS instances in the security group.
Insert picture description here

  1. Visit the program.
    Execute the following command to restart the Apache service.
systemctl restart httpd

Enter the public IP address of the cloud server in the browser address bar to enter the portal homepage.

The default access path of the system backend is http://<ECS public network IP address>/admin.php. The default account is admin and the password is 123456.

At this point, you have completed the construction of the portal website. You can customize the content of the portal website according to the needs of the company.
Insert picture description here

PolarDB cloud database real
experience experience Gartner global database leader PolarDB, the highest value is 1,200 yuan Alibaba Cloud certification qualification is free!

Guess you like

Origin blog.51cto.com/14981263/2608905