三台centos7
centos7.1 IP 192.168.150.128 安装 yum install httpd -y
centos7.2 IP 192.168.150.130 安装yum install -y php-fpm php-mbstring php-mcrypt php-mysql lrzsz -y
centos7.3 IP 192.168.150.187 安装yum install mariadb-server
每台主机同步时间 关闭iptables 关闭selinux
蓝色标注为执行的命令,红色标注为需要注意的地方以及注释
centos 7.1配置
[root@localhost ~]# cat /etc/httpd/conf.d/web1.conf
<VirtualHost 192.168.150.128:80>
ServerName www.web1.com
DocumentRoot "/app/web1"
ProxyRequests off
DirectoryIndex index.php
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.150.130:9000/app/web1/$1
ProxyPassMatch ^/(pmstatus.*)$ fcgi://192.168.150.130:9000/$1
<Directory "/app/web1">
Options FollowSymLinks ##中间有一次报错,这里注释了,改为None,可以登录,但是后来改为现在的状态测试又可以登录不报错了,不知道为什么
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
[root@localhost ~]# cat /etc/httpd/conf.d/web2.conf
<VirtualHost 192.168.150.128:80>
ServerName www.web2.com
DocumentRoot "/app/web2"
ProxyRequests off
DirectoryIndex index.php
ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.150.130:9000/app/web2/$1
<Directory "/app/web2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
~]# vim /etc/httpd/conf/httpd.conf
ServerName 192.168.150.128:80 ##把IP修改为自己本机IP
mkdir /app/web{1,2} -pv ##不创建也可以,因为这里用不到,但是一直提示感觉太麻烦,还是创建吧
httpd -t ##测试语法
systemctl start httpd
在windows主机上解析域名
C:\Windows\System32\drivers\etc ##编辑文件下host文件
192.168.150.128 www.web1.com www.web2.com ##在文件末尾加上这一行
centos 7.2配置
]# vim /etc/my.cnf ##编辑配置文件加以下两行,跳过主机名解析
[mysqld]
innodb_file_per_table=ON
skip_name_resolve=ON
mkdir /app/web{1,2} -pv ##后来经过测试php的语法和shell不一样,这里使用的八个空格,使用一个tab不显示php页面。
vim /app/web1/index.php
<h1>www.web1.com</h1>
<?php
phpinfo();?>
~]# vim /etc/php-fpm.d/www.conf
11 ; Note: This value is mandatory.
12 listen = 192.168.150.130:9000 ##原本127.0.0.1 改为本机IP
......
23 ; Default Value: any
24 listen.allowed_clients = 192.168.150.128 ##改为前端httpd主机
unzip phpMyAdmin-4.0.10.20-all-languages.zip ##解压phpMyAdmin到当前目录,最好是低版本这里注明的版本及以下,因为实验的时候版本过高不兼容
ln -sv phpMyAdmin-4.0.10.20-all-languages pma ##创建软连接,方便平滑升级,
cp /app/web1/pma/config.sample.inc.php /app/web1/pma/config.inc.php ##拷贝一个文件并改名
vim /app/web1/pma/config.inc.php
17 $cfg['blowfish_secret'] = 'a8ssgjlkfjsffb7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
......
28 /* Authentication type */
29 $cfg['Servers'][$i]['auth_type'] = 'config'; ##改为config,否则不能登录
30 $cfg['Servers'][$i]['host'] = '192.168.150.187';
31 $cfg['Servers'][$i]['user'] = 'web_one'; ##这里加密码网页认证的时候就不用加了,方便,生产环境不要这样,这一行是自己单加的
32 $cfg['Servers'][$i]['password'] = '111111';
33 /* Server parameters */
34 $cfg['Servers'][$i]['host'] = '192.168.150.187';
35 $cfg['Servers'][$i]['connect_type'] = 'tcp';
36 $cfg['Servers'][$i]['compress'] = false;
37 /* Select mysql if your server does not have mysqli */
38 $cfg['Servers'][$i]['extension'] = 'mysqli'; ##
39 $cfg['Servers'][$i]['AllowNoPassword'] = false;
实验中登录之后点击任何地方都会提示令牌不符
在vim /app/web1/pma/libraries/common.inc.php
......
483 $token_mismatch = true;
484 if (PMA_isValid($_REQUEST['token'])) { 485 $token_mismatch = ! hash_equals($_SESSION[' PMA_token '], $_REQUEST ['token']);
486 $token_mismatch = false; ##加上这一行问题就可以解决,不过这里路径是针对当前环境相对的,文件是在自己配置环境的phpmyadmin管理目录下找。
487 }
vim /app/web2/index.php
<h1>www.web2.com</h1>
<?php
phpinfo();?>
unzip wordpress-4.8-zh_CN.tar.gz
tar -xvf wordpress-4.8-zh_CN.tar.gz
cp/app/web2/wordpress/wp-config-sample.php /app/web2/wordpress/wp-config.php
vim /app/web2/wordpress/wp-config.php
23 define('DB_NAME', 'web1');
24
25 /** MySQL数据库用户名 */
26 define('DB_USER', 'web1');
27
28 /** MySQL数据库密码 */
29 define('DB_PASSWORD', '111111');
30
31 /** MySQL主机 */
32 define('DB_HOST', '192.168.150.187');
33
34 /** 创建数据表时默认的文字编码 */
35 define('DB_CHARSET', 'utf8');
36
37 /** 数据库整理类型。如不确定请勿更改 */
38 define('DB_COLLATE', '');
centos 7.3配置
]# vim /etc/my.cnf ##编辑配置文件加以下两行,跳过主机名解析
[mysqld]
innodb_file_per_table=ON
skip_name_resolve=ON
systemctl start mariadb
MariaDB [(none)]> CREATE DATABASE web1 ; CREATE DATABASE web2;
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user 'web1'@'192.168.150.135' identified by '111111';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> create user 'web2'@'192.168.150.135' identified by '111111';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on web1.* to 'web1'@'192.168.150.135' identified by '111111';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
[root@station27 ~]# 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.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n ##是否更改当前root密码,如果没有设置密码此时可以创建
... skipping.
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] n ##是否删除匿名用户
... 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] n ##是否允许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] n ##是否删除测试库
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] n ##现在重新加载授权表吗
... skipping.
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!