1、实验需求:
1)CentOS 7, amp + xcache, rpm包,php-fpm;
a) httpd, php, mariadb分别部署在一个单独的主机上;
b) 一个虚拟主机提供wordpress,另一个虚拟主机提供;phpMyAdmin
c) 为phpMyAdmim提供https服务;
这里需要配置 mysql 根用户和密码、清除其他用户、清除不需要的数据库等。输出类似于下面的执行过程,其中需要我们从键盘输入的内容用蓝色注释出来了:
/usr/bin/mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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):这里直接回车,这里可不是 Linux root 用户,而是 MariaDB 数据库的 root 用户
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
New password:输入你的数据库root用户密码
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 --删除匿名用户?
... 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 --不允许远程root登录吗?
... 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 --删除测试数据库和访问吗?
- 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 --现在重新加载权限表吗?
... 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!
2.1输入密码后回车,下面是输出示例,可以看到命令提示符变为 MariaDB [(none)]>
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.37-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2.3创建一个新用户,并将该数据库的权限赋给他(这里只是举例,用户名为 ly,密码为 lyuserpassword)
MariaDB [(none)]> grant all on wordpress.* to 'ly'@'172.16.%.%' identified by 'lyuserpassword';
1.2生成自签证书
CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Beijing
Common Name (eg, your name or your server's hostname) []:www2
1.3提供辅助文件
CA]# touch index.txt
CA]# echo 01 > serial 序列号
CA]# tree
.
├── cacert.pem
├── certs
├── crl
├── index.txt
├── newcerts
├── private
│ └── cakey.pem
└── serial
2.2生成证书签署请求:
ssl]# openssl req -new -key httpd.key -out httpd.csr
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Beijing
Common Name (eg, your name or your server's hostname) []:www2
2.3把请求发给CA
ssl]# cp httpd.csr /tmp/
3.CA签发证书
3.1签署证书
~]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt