更新时间:2023-06-12 GMT+08:00
分享

搭建网站

已有服务

搭建流程

搭建数据库

安装MySQL

本文档以CentOS 7.2操作系统为例安装MySQL。

  1. 远程登录云服务器discuz01,填写用户名和密码。
  2. 依次执行以下命令,安装MySQL。

    wget -i -c 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 --nogpgcheck

配置MySQL

  1. 执行以下命令,启动MySQL服务。

    systemctl start mysqld

    systemctl enable mysqld

  2. 查看MySQL运行状态。

    systemctl status mysqld.service

    回显信息如下所示:

    # systemctl status mysqld.service
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Mon 2021-08-23 10:54:55 CST; 7s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
     Main PID: 7873 (mysqld)
       CGroup: /system.slice/mysqld.service
               └─7873 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    Aug 23 10:54:49 ecs-adc3-420652-aed6 systemd[1]: Starting MySQL Server...
    Aug 23 10:54:55 ecs-adc3-420652-aed6 systemd[1]: Started MySQL Server.
  3. 执行以下命令,获取安装MySQL时自动设置的root用户密码。

    grep 'temporary password' /var/log/mysqld.log

    回显如下类似信息。
    2021-08-16T11:33:37.790533Z 1 [Note] A temporary password is generated for root@localhost: ;8nPd29lhs,k
  4. 执行以下命令,并按照回显提示信息进行操作,加固MySQL。

    mysql_secure_installation

    Securing the MySQL server deployment.
    
    Enter password for user root:    #输入上一步骤中获取的安装MySQL时自动设置的root用户密码
    The existing password for the user account root has expired. Please set a new password.
    
    New password:  #设置新的root用户密码
    
    Re-enter new password:   #再次输入密码
    The 'validate_password' plugin is installed on the server.
    The subsequent steps will run with the existing configuration of the plugin.
    Using existing password for root.
    
    Estimated strength of the password: 100
    Change the password for root ? ((Press y|Y for Yes, any other key for No) : N   #是否更改root用户密码,输入N
    
     ... skipping.
    By default, a MySQL installation has an anonymous user,
    allowing anyone to log into MySQL without having to have
    a user account created for them. This is intended only for
    testing, and to make the installation go a bit smoother.
    You should remove them before moving into a production
    environment.
    
    Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y   #是否删除匿名用户,输入Y
    Success.
    
    Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   #禁止root远程登录,输入Y
    Success.
    
    By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.
    
    Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y   #是否删除test库和对它的访问权限,输入Y
     - Dropping test database...
    Success.
    
     - Removing privileges on test database...
    Success.
    
    Reloading the privilege tables will ensure that all changes
    made so far will take effect immediately.
    
    Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y   #是否重新加载授权表,输入Y
    Success.
    
    All done!
  5. 执行以下命令,再根据提示输入数据库管理员root账号的密码进入数据库。

    mysql -u root -p

  6. 执行以下命令,使用MySQL数据库。

    use mysql;

  7. 执行以下命令,查看用户列表。

    select host,user from user;

    此命令及以下数据库语句均以分号结尾,请勿忽略。

  8. 执行以下命令,刷新用户列表并允许所有IP对数据库进行访问。

    update user set host='%' where user='root' LIMIT 1;

  9. 执行以下命令,强制刷新权限。允许同一子网中设置为允许访问的云服务器通过私有IP对MySQL数据库进行访问。

    flush privileges;

  10. 执行以下命令,退出数据库。

    quit

  11. 执行以下命令,重启MySQL服务。

    systemctl restart mysqld

  12. 执行以下命令,设置开机自动启动MySQL服务。

    systemctl enable mysqld

  13. 执行以下命令,关闭防火墙。

    systemctl stop firewalld.service

  14. 重新查看防火墙状态是否为关闭。

    systemctl status firewalld

搭建Web环境

安装Web环境

  1. 将弹性公网IP从云服务器discuz01上解绑,并绑定至云服务器discuz02上。

  2. 远程登录云服务器discuz02,填写用户名和密码。

  3. 依次执行以下命令,安装MySQL。

    wget -i -c 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 --nogpgcheck

  4. 执行以下命令,安装Apache服务器、PHPFastCGI管理器、MySQL客户端和MySQL数据库服务器。

    yum install -y httpd php php-fpm mysql mysql-server php-mysql

    回显如下,说明安装成功。
    Complete!
  5. 执行以下命令,更新安装Apache服务器、PHPFastCGI管理器、MySQL客户端和MySQL数据库服务器。

    yum reinstall -y httpd php php-fpm mysql mysql-server php-mysql

    回显如下,更新安装成功。
    Complete!

配置Web环境

  1. 执行以下命令,启动httpd服务。

    service httpd start

  2. 执行以下命令,设置开机自动启动httpd服务。

    chkconfig httpd on

  3. 执行以下命令,启动php-fpm服务。

    service php-fpm start

  4. 执行以下命令,设置开机自动启动php-fpm服务。

    chkconfig php-fpm on

  5. 执行以下命令,关闭防火墙。

    systemctl stop firewalld.service

  6. 执行以下命令,重新查看防火墙状态是否为关闭。

    systemctl status firewalld

  7. 执行以下命令,启动MySQL服务。

    systemctl start mysqld

  8. 执行以下命令,设置开机自动启动MySQL服务。

    systemctl enable mysqld.service

  9. 在浏览器中输入http://弹性公网IP地址 ,即可访问服务器的默认主页。

部署网站代码

  1. 远程登录云服务器discuz02,执行以下命令,安装Discuz软件。
    wget https://www.discuz.net/down/Discuz_X3.4_SC_UTF8_20220811.zip
    • 以上软件来自第三方网站,仅作示例。建议自行获取需要的版本软件,以应对不同需求。
    • 上述软件仅为搭建网站指导示例,若搭建的网站做商业用途请自行准备所需软件。
  2. 执行以下命令,解压Discuz安装包。

    unzip Discuz_X3.4_SC_UTF8_20220811.zip

  3. 执行以下命令,将解压后的“upload”文件夹下的所有文件复制到“var/www/html”路径下。

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

  4. 执行以下命令,将写权限赋予给其他用户。

    chmod -R 777 /var/www/html

  5. 在浏览器里输入地址:http://弹性公网IP地址进入安装界面,按照Discuz安装向导进行安装。
    1. 确认协议,并单击“我同意”。
    2. 开始安装后,检查安装环境并单击“下一步”。
    3. 设置运行环境,并单击“下一步”。
    4. 安装数据库,填写数据库信息,单击“下一步”完成安装。
      • 数据库服务器地址即为discuz01的私有IP地址。
      • 数据库密码是discuz01配置的数据库管理员root账号的密码。
      • 自定义管理员信息。

验证搭建结果

在浏览器中输入:http://弹性公网IP地址/forum.php 可登录论坛主页则说明网站搭建成功。

分享:

    相关文档

    相关产品