安装和设置MariaDB和phpMyAdmin

本次将安装和配置MariaDB和phpMyAdmin。

与上一次相同的环境。
~ 樱花VPS 1G计划 ~
内存:1G
CPU:虚拟2核
存储:HDD 100GB
操作系统:CentOS 7(自定义操作系统)

假设,账号名称为root或abc123,域名为abc.com。

首先

前提是能够在终端登录。

[root@abc ~]# 

安装 MariaDB

执行以下命令安装MariaDB。

[root@abc ~]# yum -y install mariadb-server
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi-safe: ftp.riken.jp

〜〜省略〜〜

インストール:
  mariadb-server.x86_64 1:5.5.56-2.el7                                          

依存性関連をインストールしました:
  mariadb.x86_64 1:5.5.56-2.el7       perl-DBD-MySQL.x86_64 0:4.023-6.el7      

完了しました!

执行以下命令以启动MariaDB。

[root@abc ~]# systemctl start mariadb

执行以下命令,以使MariaDB在操作系统启动时自动启动。

[root@abc ~]# systemctl enable mariadb

2. 安装MariaDB

执行以下命令并设置登录密码:

[root@abc ~]# mysql_secure_installation

然后会显示如下内容。
由于默认情况下密码未设置,因此不需要输入任何内容,按下回车键即可。

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 

会不会被问到要设置密码。

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] 

输入 “Y”,然后按回车键,再输入所需设置的密码,再次按下回车键。

Set root password? [Y/n] Y
New password:

然后会显示如下内容。

Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 

输入”Y”,然后按下回车键。

Remove anonymous users? [Y/n] 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? [Y/n] 

输入相同的”Y”并按下回车键。

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB 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? [Y/n] 

输入相同的”Y”并按下回车键。

Remove test database and access to it? [Y/n] 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? [Y/n] 

输入相同的“Y”,然后按下回车键。

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@abc ~]# 

安装phpMyAdmin

执行以下命令以安装phpMyAdmin。

[root@abc ~]# yum -y install --enablerepo=remi,remi-php73 phpMyAdmin
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi: ftp.riken.jp
 * remi-php73: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.iij.ad.jp

〜〜省略〜〜

  php-symfony3-translation.noarch 0:3.4.12-1.el7.remi                           
  php-twig.noarch 0:1.35.3-1.el7.remi.7.3                                       
  php-twig-extensions.noarch 0:1.5.1-1.el7.remi                                 
  php-xml.x86_64 0:7.1.19-1.el7.remi                                            
  recode.x86_64 0:3.6-38.el7                                                    

完了しました!
[root@abc ~]# 

4. 设置phpMyAdmin

执行以下命令,打开phpMyAdmin的配置文件。

[root@abc ~]# vim /etc/httpd/conf.d/phpMyAdmin.conf

为了让第三方难以猜测到phpMyAdmin的URL, 在第8行的”phpMyAdmin”后面以及第9行的”phpmyadmin”后面加上一些合适的字符。

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

请将以下内容以中文进行本地化释义,只需提供一种选择:

请用中文翻译以下内容,只需要提供一种选项:

Alias /phpMyAdmin2ekS8nA /usr/share/phpMyAdmin
Alias /phpmyadmin2ekS8nA /usr/share/phpMyAdmin

为了仅允许SSL通信,请在第13行输入”SSLRequireSSL”。

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   Require local

请将以下内容翻译成中文,只需要一种版本:

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   SSLRequireSSL
   Require local

为了能从任何地方访问,将第14行的”Require local”改为”Require all granted”。

     SSLRequireSSL
     Require local
  </Directory>

请将以下内容用中文进行释义。只需要一个选项:

请把下面的内容改成中文,只需要一个版本:

     SSLRequireSSL
     Require all granted
  </Directory>

执行以下命令以安装mod_ssl。

[root@abc ~]# yum -y install mod_ssl

为了使设置生效,重新启动Apache。

[root@abc ~]# systemctl restart httpd

使用浏览器访问https://”您的IP地址”/phpMyAdmin”设置的字符串”。
由于没有SSL证书,会显示错误消息,但需要执行允许的操作以确认可以访问。
这时只有root用户,因此输入用户名为root,密码为上面设置的密码进行登录。
如果无法登录或显示403错误等,则需要从头再试一次。

广告
将在 10 秒后关闭
bannerAds