之路 on it Road.com

在 RHEL 8 上安装 MySQL 数据库 8.0

对于数据库后端安装,我们可以选择 MySQL 和 MariaDB。

这里我们安装 MySQL。

MySQL 8.0 在本地 AppStream 存储库中可用,因此,让我们使用 dnf 命令安装它。

[root@rhel-8-lamp ~]# dnf install -y mysql-server

启动并启用 MySQL 服务。

[root@rhel-8-lamp ~]# systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service -> /usr/lib/systemd/system/mysqld.service.
[root@rhel-8-lamp ~]# systemctl start mysqld.service

配置和保护 MySQL 数据库实例如下所示。

[root@rhel-8-lamp ~]# mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:
LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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
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
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
 - 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
Success.
All done!

使用以下命令验证 MySQL 数据库安装。

[root@rhel-8-lamp ~]# mysql -e "SHOW DATABASES;" -p
Enter password:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

在 RHEL 8 上安装 Apache HTTP Server 2.4

登录到服务器, rhel8.onitroad.com。

使用 dnf 命令安装 Apache HTTP Server。

[root@rhel-8-lamp ~]# dnf install -y httpd

启用并启动 httpd.service 。

[root@rhel-8-lamp ~]# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service -> /usr/lib/systemd/system/httpd.service.
[root@rhel-8-lamp ~]# systemctl start httpd.service

在 Linux 防火墙中允许 HTTP 服务。

[root@rhel-8-lamp ~]# firewall-cmd --permanent --add-service=http
success
[root@rhel-8-lamp ~]# firewall-cmd --reload
success

使用浏览器打开L http://rhel8.onitroad.com。

可以看到Apache HTTP Server 的默认页面。

在 RHEL 8 上安装 PHP 7.2

在本地 AppStream 存储库中,PHP 7.2 可用,因此我们只需执行 dnf 命令即可安装它。

[root@rhel-8-lamp ~]# dnf install -y php php-mysqlnd php-mbstring php-pdo php-gd

在安装过程中,PHP 在 Apache 配置目录中创建了必要的配置文件。
因此,我们必须重新启动 httpd.service 才能将 PHP 与 Apache HTTP Server 集成。

[root@rhel-8-lamp ~]# systemctl restart httpd.service

创建一个 PHP 文件以验证 PHP 安装及其与 Apache HTTP 服务的集成。

[root@rhel-8-lamp ~]# echo "<?php phpinfo() ?>" > /var/www/html/info.php

使用浏览器打开 http://rhel-8-lemp.example.com/info.php。
将可以看到PHP的有关信息。

在 RHEL 8 服务器上安装 LAMP 堆栈

测试环境

  • 主机名 - rhel8.onitroad.com
  • IP 地址 - 192.168.1.100/24
  • OS - 红帽企业 Linux (RHEL) 8
日期:2020-09-17 00:12:32 来源:oir作者:oir