公有云技術
公有云云服務器的申請與使用
華為云介紹
華為云立足于互聯網領域,依托于華為公司雄厚的資本和強大的云計算研發實力,面向互聯網增值服務運營商、大中小型企業、政府、科研院所等廣大企事業用戶提供包括云主機、云托管、云存盤等基礎云服務、超算、內容分發與加速、視頻托管與發布、企業IT、云電腦、云會議、游戲托管、應用托管等服務和解決方案
申請云服務器
登錄華為云
打開瀏覽器訪問華為云平臺地址https://www.huaweicloud.com/

點擊登錄,進入登錄界面,輸入賬號密碼進行登錄

登錄成功后進入華為云控制臺

登錄控制臺
左上角選擇虛擬私有云VPC,選擇虛擬私有云,點擊右上角創建虛擬私有云

選擇訪問控制中的安全組

點擊名稱, 入方向規則,添加規則埠80,3306

登錄ECS
點擊左上角選擇彈性云服務器ECS,選擇彈性云服務器,點擊右上角購買彈性云服務器

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

選擇靜態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登錄界面

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/73306.html
標籤:Linux
