Bo's Oracle Station

【博客文章2026】将整个博客整体迁移到Oracle云上的Compute实例来运行---以本博客为例

2026-2-25 10:53| 发布者: admin| 查看: 147| 评论: 0|原作者: Bo Tang

摘要: 是一份原创的分步教程,将提供实际操作指导,详细介绍如何将本博客整体迁移至Oracle云上运行——也就是读者当前正在浏览的这个网页。本教程包含以下8个步骤: 一、梳理原博客的构成 二、选择目标架构并在OCI上搭建新环境 三、在计算实例上安装配置MySQL数据库 四、迁移计算实例上的MySQL数据库 五、在计算实例上安装HTTPD服务器与PHP 六、迁移计算实例上的文件 七、签署HTTPS证书 八、测试验证

【博客文章2026】将整个博客整体迁移到Oracle云上的Compute实例来运行---以本博客为例


Author: Bo Tang

1. 评估原博客的构成

    由于这是一个涉及到内容、应用和数据库的综合工程,所以为了将整个博客整体迁移到Oracle Cloud Infrastructure (OCI) 之前,需要评估原博客的构成。在迁移www.botangdb.com博客(原先位于hostgator提供的香港虚拟主机)之前,了解到其包含以下这些内容:
    1. 静态内容‌:HTML、CSS、JavaScript、图片、大量视频等文件。
‌    2. 动态应用‌:运行博客的程序为北京康盛新创公司推出的开源社区论坛软件系统Discuz(基于Php和MySQL数据库)。
‌    3. 数据库‌:存储文章、评论、用户信息等的MySQL数据库。
‌    4. 配置与依赖‌:服务器配置、域名设置和SSL 证书。
    在动手迁移前,必须彻底了解博客的当前架构。迁移博客到 OCI 的核心思路是:‌将博客的静态内容、动态应用和数据存储,整体迁移到 OCI 的弹性、安全且高可用的云服务上‌。这不仅能提升访问速度和可靠性,还能显著降低运维成本。

2. 选择目标架构,在OCI 上构建新环境

2.1 准备目标环境‌:在 OCI 上创建 VCN和子网:
    使用 ‌Virtual Cloud Network (VCN)‌ 配置安全的网络环境,设置子网、安全列表和路由规则,确保博客应用能安全地访问数据库和互联网。创建VCN和并配置子网:登录Oracle Cloud后,找到链接路径为Networking--->Virtual cloud networks。


    创建一个VCN:本例子中,它的名字叫vcn1,它的IPv4网段:10.0.0.0/16。



    点击Security选项卡:



    除了默认的Default Security List for vcn1外,需要创建一个新的Security List:本例子中,它的名字叫s1。



    s1的Security Rules是:



    只要添加Ingress Rules就可以。需要添加两条Ingress Rule:

    1)Staleless为No;Source为0.0.0.0/0;IP Protocol为TCP;Source Port Range为ALL;Destination Port Range为80;Type and Code为空值;Allow为:TCP traffic for ports 80;Desscription为空值。

    2)Staleless为No;Source为0.0.0.0/0;IP Protocol为TCP;Source Port Range为ALL;Destination Port Range为443;Type and Code为空值;Allow为:TCP traffic for ports 443HTTPS;Desscription为空值。



2.2 准备目标环境‌:在 OCI 上创建 Compute实例:

    创建Compute实例:链接路径为Compute--->Instances。使用 ‌Oracle Cloud Compute‌ 创建虚拟机(VM)实例。



    创建一个Compute实例:本例子中,它的名字叫botang。创建时,选择与原博客(运行在hostgator主机服务商)相同或相似的操作系统镜像:Oracle Enterprise Linux 8.10。



    它的网络是之前创建的vcn1,它的外网地址是(自动分配的)40.233.91.144。



3. 在Compute实例上安装并配置MySQL数据库

    下载Compute实例的私钥,使用ssh连接工具来连接Compute实例的外网地址:

Windows PowerShell
版权所有(C) Microsoft Corporation。保留所有权利。

安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows

PS C:\Users\Administrator> cd Downloads
PS C:\Users\Administrator\Downloads> ssh -i .\ssh-key-2025-12-31.key opc@40.233.91.144
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Thu Feb 26 13:09:37 2026 from 124.16.209.29
[opc@botang ~]$

    安装MySQL Server:

[opc@botang ~]$sudo yum install mysql
[opc@botang ~]$sudo yum  install   mysql-server*
[opc@botang ~]$sudo systemctl enable mysqld
[opc@botang ~]$sudo systemctl start mysqld
[opc@botang ~]$sudo firewall-cmd --permanent --add-service=mysql
[opc@botang ~]$sudo mysql_secure_installation

4. 在Compute实例上进行MySQL数据库数据库迁移‌

    下载Compute实例的私钥,使用Win SCP文件传送工具来上传原博客导出的整个MySQL数据库的逻辑备份(本例中,my.dump,在原博客数据库系统中使用mysqldump -u root -p botanmvo_1 > my.dump命令导出的)到Compute实例的外网地址的/home/opc目录:


    在Compute实例上,创建与原博客系统同名的数据库(本例中,数据库名为botanmvo_1)、创建与原博客系统同名的数据库用户(本例中,数据库用户名为botanmvo_2)并进行授权:

[opc@botang ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 56148
Server version: 8.0.44 Source distribution

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>create database botanmvo_1;
Query OK, 1 row affected (0.00 sec)

mysql> grant all   on botanmvo_1 to botanmvo_2@localhost;
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON `botanmvo_1`.* TO `botanmvo_2`@`localhost`;
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `botanmvo_2`@`localhost`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

    验证:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select  host, user  from user where  user='botanmvo_2';
+-----------+------------+
| host      | user       |
+-----------+------------+
| localhost | botanmvo_2 |
+-----------+------------+
1 row in set (0.00 sec)

mysql> show  grants for botanmvo_2@localhost;
+-----------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for botanmvo_2@localhost                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
+------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, 
SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, 
CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE
 ROLE, DROP ROLE ON *.* TO `botanmvo_2`@`localhost`                                                                                                                                                                                                                                                                                                                                                                                     |
| GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ABORT_EXEMPT,AUDIT_ADMIN,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,
BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FIREWALL_EXEMPT,
FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,
GROUP_REPLICATION_STREAM,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,
PASSWORDLESS_USER_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,
RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SENSITIVE_VARIABLES_OBSERVER,SERVICE_CONNECTION_ADMIN,
SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,
TELEMETRY_LOG_ADMIN,XA_RECOVER_ADMIN ON *.* TO `botanmvo_2`@`localhost` |
| GRANT ALL PRIVILEGES ON `botanmvo_1`.* TO `botanmvo_2`@`localhost`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| GRANT ALL PRIVILEGES ON `botanmvo_1`.`botanmvo_1` TO `botanmvo_2`@`localhost`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| GRANT ALL PRIVILEGES ON `mysql`.`botanmvo_1` TO `botanmvo_2`@`localhost`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
+------------------------------------------------------------------------------------------------------------------------------------------------+
5 rows in set (0.00 sec) 

    以opc用户导入MySQL数据:

[opc@botang ~]$mysql -u root -p botanmvo_1 < my.dump

5. 在Compute实例上安装HTTPD服务器和PHP

[opc@botang ~]$sudo yum install httpd
[opc@botang ~]$sudo firewall-cmd --permanent --add-service=http
success
[opc@botang ~]$sudo firewall-cmd --permanent --add-service=https
success
[opc@botang ~]$sudo firewall-cmd --reload
success
[opc@botang ~]$sudo systemctl start httpd
[opc@botang ~]$sudo systemctl enable  httpd

    由于原博客的PHP版本是7.4,所以注意使用dnf系统安装正确的PHP版本:

[opc@botang ~]$ sudo yum module list php
Last metadata expiration check: 3:27:39 ago on Sun 01 Mar 2026 04:53:11 AM GMT.
Oracle Linux 8 Application Stream (x86_64)
Name               Stream                Profiles                                    Summary
php                7.2 [d]               common [d], devel, minimal                  PHP scripting language
php                7.3                   common [d], devel, minimal                  PHP scripting language
php                7.4 [e]               common [d] [i], devel, minimal              PHP scripting language
php                8.0                   common [d], devel, minimal                  PHP scripting language
php                8.2                   common [d], devel, minimal                  PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[opc@botang ~]$sudo yum module enable php:7.4
[opc@botang ~]$sudo yum -y install  mod*
[opc@botang ~]$ php -v
PHP Warning:  PHP Startup: Unable to load dynamic library 'zip.so' (tried: /usr/lib64/php/modules/zip.so (/usr/lib64/php/modules/zip.so: undefined symbol: zip_register_cancel_callback_with_state), /usr/lib64/php/modules/zip.so.so (/usr/lib64/php/modules/zip.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP 7.4.33 (cli) (built: Feb 11 2026 10:36:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
6. 在Compute实例上进行文件迁移‌:

    上传包含原博客的/var/www/html整个tar包,然后将其移动到Compute实例的/var/www/html目录下,进行解压缩:

[opc@botang ~]$sudo mv /home/opc/html.tgz   /var/www/html
[opc@botang ~]$sudo tar zxvf html.tgz
[opc@botang ~]$sudo chown -R  apache:apache /var/www/html/
[opc@botang ~]$sudo chmod  -R o+rX   html

    可选:如果有需要可以更改/var/ww/html下的Discuz程序的配置文件,主要是config目录下的config_global.php和source目录下的function_core.php。本例中由于所有配置都保留原样,所以不做改动。

7. HTTPS证书签名:

    首次获取CA签名证书:

[opc@botang ~]$sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
[opc@botang ~]$sudo yum list snapd
Last metadata expiration check: 4:25:38 ago on Sun 01 Mar 2026 04:53:11 AM GMT.

Installed Packages

snapd.x86_64                                              2.72-1.el8                                               @epel

[opc@botang ~]$sudo yum -y install snapd
[opc@botang ~]$sudo systemctl start snapd
[opc@botang ~]$sudo snap install --classic certbot
[opc@botang ~]$sudo ln -s /var/lib/snapd/snap /snap
[opc@botang ~]$sudo ln -s /snap/bin/certbot /usr/bin/certbot
[opc@botang ~]$sudo certbot certonly   --standalone

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): www.botangdb.com
Requesting a certificate for www.botangdb.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Could not bind TCP port 80 because it is already in use by another process on
this system (such as a web server). Please stop the program in question and then
try again.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(R)etry/(C)ancel: C
Could not bind TCP port 80 because it is already in use by another process on this system (such as a web server). Please stop the program in question and then try again.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

    以上报错这样处理:为了申请签名,需要暂时关闭httpd:

[opc@botang ~]$ sudo systemctl stop httpd
[opc@botang ~]$ sudo certbot certonly   --standalone
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Please enter the domain name(s) you would like on your certificate (comma and/or
space separated) (Enter 'c' to cancel): www.botangdb.com
Requesting a certificate for www.botangdb.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/www.botangdb.com-0001/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/www.botangdb.com-0001/privkey.pem
This certificate expires on 2026-05-30.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[opc@botang ~]$ sudo systemctl start httpd

    发布CA证书:

[opc@botang ~]$ sudo mv /etc/pki/tls/certs/localhost.crt /etc/pki/tls/certs/localhost.crt.ori
[opc@botang ~]$ sudo mv /etc/pki/tls/private/localhost.crt /etc/pki/tls/private/localhost.crt.ori
[opc@botang ~]$ sudo cp  /etc/letsencrypt/live/www.botangdb.com/privkey.pem   /etc/pki/tls/private/localhost.key
[opc@botang ~]$ sudo cp  /etc/letsencrypt/live/www.botangdb.com/fullchain.pem   /etc/pki/tls/certs/localhost.crt
[opc@botang ~]$sudo systemctl start httpd

    以后如果需要续签证书:

[opc@botang ~]$openssl x509 -in /etc/pki/tls/certs/localhost.crt -noout -dates
notBefore=Jan  2 02:09:46 2026 GMT
notAfter=Apr  2 02:09:45 2026 GMT
[opc@botang ~]$sudo certbot renew   --standalone

‌8. 测试与验证‌:

    在新环境中进行全面测试,确保所有功能(文章发布、评论、搜索、媒体播放等)正常运行,数据完整无误。‌切换与上线‌:将域名解析(DNS)指向 OCI 上的新博客地址(本例中是40.233.91.144)。

[opc@botang ~]$ dig www.botangdb.com

; <<>> DiG 9.11.36-RedHat-9.11.36-16.el8_10.6 <<>> www.botangdb.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46058
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1372
;; QUESTION SECTION:
;www.botangdb.com.              IN      A

;; ANSWER SECTION:
www.botangdb.com.       3600    IN      A       40.233.91.144

;; Query time: 117 msec
;; SERVER: 169.254.169.254#53(169.254.169.254)
;; WHEN: Mon Mar 02 01:56:48 GMT 2026
;; MSG SIZE  rcvd: 61

‌    现在博客已经运行在Oracle Cloud之上了,就是读者所浏览的当前这个网页。       




路过

雷人

握手

鲜花

鸡蛋

QQ|手机版|Bo's Oracle Station   

GMT+8, 2026-2-27 15:29 , Processed in 0.056090 second(s), 21 queries .

返回顶部