公有云技術

公有云技術php

公有云雲服務器的申請與使用

華爲雲介紹

華爲雲立足於互聯網領域,依託於華爲公司雄厚的資本和強大的雲計算研發實力,面向互聯網增值服務運營商、大中小型企業、政府、科研院所等廣大企事業用戶提供包括雲主機雲託管雲存儲等基礎雲服務、超算、內容分發與加速、視頻託管與發佈、企業IT、雲電腦雲會議、遊戲託管、應用託管等服務和解決方案html

 

申請雲服務器

登陸華爲雲

打開瀏覽器訪問華爲雲平臺地址https://www.huaweicloud.com/node

 

點擊登陸,進入登陸界面,輸入帳號密碼進行登陸mysql

 

登陸成功後進入華爲雲控制檯linux

登陸控制檯

左上角選擇虛擬私有云VPC,選擇虛擬私有云,點擊右上角建立虛擬私有云sql

 

選擇訪問控制中的安全組 數據庫

 

點擊名稱, 入方向規則,添加規則端口80,3306apache

 

登陸ECS

點擊左上角選擇彈性雲服務器ECS,選擇彈性雲服務器,點擊右上角購買彈性雲服務器api

 

選擇按需付費,點擊下一步瀏覽器

 

 選擇靜態BGP,點擊下一步

 

設置密碼,「雲備份」選擇暫不分配

 

 

查看配置,點擊當即購買

 

 

 建立完成

 

 

 點擊名稱,查看雲主機基本信息

 

 

公有云數據庫服務的申請與使用

申請雲數據庫MySQL

登陸控制檯

登陸控制檯選擇雲數據庫,點擊右上角購買數據庫實例

 

 

 

 

選擇完成後點擊當即購買,顯示數據庫基本信息

 

 點擊提交以後點擊返回

 

 等待建立完成,點擊登陸

 

 輸入帳號密碼,點擊登陸

 

 

 

 點擊鏈接管理,查看信息

 

 

 

 

 

 

 

 

點擊安全組,進行關聯實例

 

公有云塊存儲服務的申請與使用 

建立EBS卷

返回控制檯,點擊雲硬盤

 

 

點擊右上角購買磁盤

 

 選擇完成,點擊當即購買,顯示基本信息

 

點擊提交以後點擊返回

 

 點擊掛載

 

 

在雲主機進行磁盤初始化 

查看磁盤信息,並進行分區

# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x0002af06

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vda1   *        2048    83886079    41942016   83  Linux

 

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

 

[root@ecs-ab57 ~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x0b673d44.

 

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):

Using default value 41943039

Partition 1 of type Linux and of size 20 GiB is set

 

Command (m for help): p

 

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x0b673d44

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048    41943039    20970496   83  Linux

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

進行掛載

# partprobe 

# mkfs -t ext4 /dev/vdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5242624 blocks

262131 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2153775104

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

        4096000

 

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done  

 

建立文件系統

# mkdir df /mnt/sdk

# mount /dev/vdb1 /mnt/sdk/

# df -TH

Filesystem     Type      Size  Used Avail Use% Mounted on

devtmpfs       devtmpfs  2.0G     0  2.0G   0% /dev

tmpfs          tmpfs     2.0G     0  2.0G   0% /dev/shm

tmpfs          tmpfs     2.0G  9.1M  2.0G   1% /run

tmpfs          tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup

/dev/vda1      ext4       43G  2.2G   38G   6% /

tmpfs          tmpfs     398M     0  398M   0% /run/user/0

/dev/vdb1      ext4       22G   47M   20G   1% /mnt/sdk

公有云對象存儲服務的申請與使用

建立桶服務

回到控制檯選擇對象存儲服務,選擇建立桶

 

點擊當即建立

 

博客系統上公有云實踐 

使用建立的EC2實例

搭建LAMP環境

升級系統內核

鏈接到已建立的EC2實例。

爲確保全部軟件包都處於最新狀態,須要對實例執行內核升級,此過程可能須要幾分鐘的時間,但能確保EC2系統擁有最新的安全更新和缺陷修復。

# yum upgrade -y

查看Amazon Linux的版本。

# cat /etc/redhat-release

CentOS Linux release 7.7.1908 (Core)

配置防火牆規則和SELinux

清除防火牆規則

# iptables -t filter -F

# iptables -t filter -X

永久關閉SELinux

# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# getenforce

Disabled

# reboot

安裝環境

當實例處於最新狀態後,即可以安裝Apache Web服務器、MariaDB和PHP軟件包。

# yum install -y httpd mariadb-server php php-mysql

啓動Apache Web服務器

啓動Apache Web服務器並設置開機自啓。

# systemctl start httpd

# systemctl enable httpd

測試Apache服務器

在Web瀏覽器中,輸入實例的公有IP地址。若是/var/www/html中沒有內容,則會看到Apache測試頁面

 

若是未能看到Apache測試頁面,請檢查當前EC2使用的安全組是否包含容許HTTP(端口80)流量的規則

Apache httpd提供的文件保存在Apache文檔根目錄/var/www/html中,默認狀況下歸根用戶全部

測試LAMP

在Apache文檔根目錄中建立一個PHP文件。

# echo "<?php phpinfo();?>" > /var/www/html/phpinfo.php

能正常打開相應的PHP信息頁面,說明PHP已經正常啓動;若是在頁面中能找到mysql、mysqli的信息內容,說明對PHP平臺能正常訪問mysql和mysqli接口

 

刪除phpinfo.php文件

# rm -rf /var/www/html/phpinfo.php

配置數據庫

在EC2上測試MariaDB的連通性。

# systemctl start mariadb

# systemctl enable mariadb

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

# mysql -h 192.168.1.74 -P 3306 -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 2102

Server version: 5.7.29-2-log MySQL Community Server - (GPL)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MySQL [(none)]>

部署WordPress

加壓安裝包

將提供的壓縮包wordpress-5.0.2-zh_CN.tar.gz上傳至EC2實例/root目錄並解壓。

# ll

total 10840

drwxr-xr-x 2 root root     4096 May 21 17:17 df

-rw-r--r-- 1 root root 11093953 Nov  7  2019 wordpress-5.0.2-zh_CN.tar.gz

# tar -zxvf wordpress-5.0.2-zh_CN.tar.gz

複製解壓後的wordpress目錄到/var/www/html目錄下。

# cp -rf wordpress /var/www/html/

配置WordPress

在瀏覽器輸入http://EC2_IP/wordpress,便可訪問WordPress歡迎頁面

建立數據庫和帳號

爲了讓WordPress正常運行,在數據庫中建立數據庫以及相應的帳號。

# mysql -h 192.168.1.74 -P 3306 -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 2257

Server version: 5.7.29-2-log MySQL Community Server - (GPL)

 

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MySQL [(none)]> create database wordpress;

Query OK, 1 row affected (0.01 sec)

 

MySQL [(none)]> GRANT ALL ON wordpress.* TO 'guo'@'localhost' IDENTIFIED BY "00000000";

Query OK, 0 rows affected, 2 warnings (0.00 sec)

 

MySQL [(none)]> GRANT ALL ON wordpress.* TO 'guo'@'%' IDENTIFIED BY "00000000";

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

MySQL [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

 

MySQL [(none)]> quit

Bye

建立PHP文件

返回網頁,繼續完成WordPress的初始化操做

 

在WordPress安裝界面會提示沒法寫入wp-config.php文件,須要手動建立

 

手動建立wp-config.php文件

# cat /var/www/html/wordpress/wp-config.php

<?php

/**

 * WordPress基礎配置文件。

 *

 * 這個文件被安裝程序用於自動生成wp-config.php配置文件,

 * 能夠不使用網站生成,須要手動複製這個文件,

 * 並重命名爲「wp-config.php」,而後填入相關信息。

 *

 * 本文件包含如下配置選項:

 *

 * * MySQL設置

 * * 密鑰

 * * 數據庫表名前綴

 * * ABSPATH * * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php

 *

 * @package WordPress

 */

 // ** MySQL:設置的具體信息來自正在使用的主機 ** //

/** WordPress數據庫的名稱 */

define('DB_NAME', 'wordpress');

 

/** MySQL數據庫用戶名 */

define('DB_USER', 'root');

 

/** MySQL數據庫密碼 */

define('DB_PASSWORD', 'Gao9400@');

 

/** MySQL主機 */

define('DB_HOST', '192.168.1.74');

 

/** 建立數據表時默認的文字編碼 */

define('DB_CHARSET', 'utf8mb4');

 

/** 數據庫整理類型。如不肯定請勿更改 */

define('DB_COLLATE', '');

 

/**#@+

 * 身份認證密鑰。

 *

 * 修改成任意獨一無二的字串!

 * 或者直接訪問{@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org密鑰生成服務}

 * 任何修改都會致使全部cookies失效,全部用戶將必須從新登陸。

 *

 * @since 2.6.0

 */

define('AUTH_KEY',         'o96P/{uub3_/m#VY3,KU:c7C:eT,*},T3tU2!Z@N<d[9/K<SdKuw-QJ8!|@+~*oN');

define('SECURE_AUTH_KEY',  '1akka,TV:bg>.=qA+y6T{,rVZn)@ wifG3FH4Y[=ZTQ)I8`p,m&]}@<f-,^s@ck{');

define('LOGGED_IN_KEY',    '+9dE2i$2G_mCm~[@M^j`/)VcI[F+`js %ud>zr)h+<-hr^<0EI~+)kJcBM6vU~u{');

define('NONCE_KEY',        'I<kv;2[QpC!qw.:f}K%^97. i5PrL~xOE]ieF-#bZtL*jSzB7JxCR^[WEZ,_sn6/');

define('AUTH_SALT',        'xjFz0z>,Ia<E`B!TU0-.QPs7:AqUJ;c3PTNR5WJl5|g20<_&2<(S-(QGz?!Z[}+Q');

define('SECURE_AUTH_SALT', 'yf*?I>#jB9=E8^+:7v<WEkEBPtMW&==yU-,xZdc+TF%EWt{~zxP&VN2w,h^-5Hep');

define('LOGGED_IN_SALT',   'T.f}uR24d4U= EQUo}AnhT;.mvsN.;N(?=3kW)O^D1|R!10{u<t2*pJjj>]J9S&x');

define('NONCE_SALT',       'e32+aG!7F0 LNs|jIm&Od<#~Z9@[kHCAkKsHZ@1<mqX5roA;n+OQFUy=b)xu5l4T');

 

/**#@-*/

 

/**

 * WordPress數據表前綴。

 *

 * 若是須要在同一數據庫內安裝多個WordPress,請爲每一個WordPress設置不一樣的

 * 數據表前綴。前綴名只能爲數字、字母加下劃線。

 */

$table_prefix  = 'wp_';

 

/**

 * 開發者專用:WordPress調試模式。

 *

 * 將這個值改成true,WordPress將顯示全部用於開發的提示。

 * 強烈建議插件開發者在開發環境中啓用WP_DEBUG。

 *

*/

define('WP_DEBUG', false);

 

/* 好了!請不要再繼續編輯。請保存本文件。使用愉快! */

 

/** WordPress目錄的絕對路徑。 */

if ( !defined('ABSPATH') )

        define('ABSPATH', dirname(__FILE__) . '/');

 

/** 設置WordPress變量和包含文件。 */

require_once(ABSPATH . 'wp-settings.php');

容許WordPress使用permalink

WordPress permalink須要使用Apache.htaccess文件才能正常工做,但默認狀況下這些文件在Amazon Linux上處於禁用狀態。

修改httpd.conf文件中如下內容。

<Directory "/var/www/html">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.4/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

 

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride All  #修改此處

 

    #

    # Controls who can get stuff from this server.

    #

    Require all granted

</Directory>

修復 Apache Web 服務器的文件權限

WordPress中的某些可用功能要求具備對Apache文檔根目錄的寫入權限,例如,經過「Administration(管理)」屏幕上傳媒體

將/var/www及其內容的文件全部權授予apache用戶。

# chown -R apache /var/www

將/var/www及其內容的組全部權授予apache組。

# chgrp -R apache /var/www

更改/var/www及其子目錄的目錄權限,添加組寫入權限並設置將來子目錄上的組ID。

# chmod 2775 /var/www

# find /var/www -type d -exec sudo chmod 2775 {} \;

遞歸地更改/var/www及其子目錄的文件權限,以添加組寫入權限。

# find /var/www -type f -exec sudo chmod 0664 {} \;

重啓Apache Web服務器,讓新組和權限生效。

# systemctl restart httpd

登陸WordPress

在瀏覽器上再次訪問WordPress頁面,進入WordPress登陸信息配置界面,根據需求,設置相應的站點名稱、用戶名和密碼。

 

單擊 「安裝WordPress」按鈕,開始WordPress的安裝

單擊「登陸」按鈕,進入WordPress登陸界面

 

相關文章
相關標籤/搜索