CentOS 7, lamp (module);
要求:(1) 三者分离于两台主机;
(2) 一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;
(3) xcache
(4) 为phpMyAdmin提供https虚拟主机;
主机1:192.168.2.110
apache+php
主机2:192.168.2.111
mariadb
一、在主机1上安装httpd、php、php-mysql
[root@localhost ~]# yum install -y httpd php php-mysql
二、创建网站路径目录
[root@localhost ~]# mkdir -pv /www/htdocs/web{1,2}
三、在httpd上配置虚拟主机
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf <VirtualHost 192.168.2.110:80> ServerName pma.mylinuxops.com DocumentRoot /www/htdocs/web1 <Directory /www/htdocs/web1> Options none AllowOverRide none Require all granted </Directory> </VirtualHost> <VirtualHost 192.168.2.110:80> ServerName wp.mylinuxops.com DocumentRoot /www/htdocs/web2 <Directory /www/htdocs/web2> Options none AllowOverRide none Require all granted </Directory> <VirtualHost>
四、检查配置文件是否有语法错误,启动httpd
[root@localhost ~]# httpd -t [root@localhost ~]# systemctl start httpd
五、在主机2上安装mariadb,启动mariadb,创建用于pma及wp的用户账号
[root@localhost ~]# yum install -y mariadb-server [root@localhost ~]# systemctl start mariadb [root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> CREATE USER 'pmauser'@'192.168.2.110' IDENTIFIED BY 'magedu'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> CREATE USER 'wpuser'@'192.168.2.110' IDENTIFIED BY 'magedu'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit Bye
六、测试LAMP链接
[root@localhost ~]# vim /www/htdocs/web1/index.php <?php $link = $msyql_connect('192.168.2.111','pmauser','magedu'); if ($link) echo "success"; else else "failure"; mysql_close(); phpinfo(); ?>
七、安装phpMyAdmin
(1)解压phpMyAdmin,并将解压出的文件复制到网站根目录下
[root@localhost ~]# unzip phpMyAdmin-4.0.10.20-all-languages.zip [root@localhost ~]# cp -a phpMyAdmin-4.0.10.20-all-languages /www/htdocs/web1 [root@localhost web1]# ln -sv /www/htdocs/web1/phpMyAdmin-4.0.10.20-all-languages /www/htdocs/web1/pma "/www/htdocs/web1/pma" -> "/www/htdocs/web1/phpMyAdmin-4.0.10.20-all-languages"
(2)修改配置文件
[root@localhost web1]# cd pma [root@localhost pma]# cp config.sample.inc.php config.inc.php [root@localhost pma]# vim config.inc.php cfg['Servers'][$i]['host'] = '192.168.2.111'; 将主机指向mysql服务器
(3)安装php-mbstring
[root@localhost web1]# yum install -y php-mbstring
(4)重启httpd服务
[root@localhost web1]# systemctl restart httpd
(5)测试
八、安装wordpress
(1)解压wordpress,并复制到网站目录下
[root@localhost ~]# tar -xf wordpress-4.9.4-zh_CN.tar.gz [root@localhost ~]# cp -a wordpress /www/htdocs/web2/
(2)修改配置文件
[root@localhost wordpress]# cp wp-config-sample.php wp-config.php [root@localhost wordpress]# vim wp-config.php /** WordPress数据库的名称 */ define('DB_NAME', 'wpdb'); /** MySQL数据库用户名 */ define('DB_USER', 'wpuser'); /** MySQL数据库密码 */ define('DB_PASSWORD','magedu'); /** MySQL主机 */ define('DB_HOST', '192.168.2.111');
(3)在mysql服务器上创建数据库并授权
[root@localhost ~]# mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database wpdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> USE wpdb Database changed MariaDB [wpdb]> GRANT ALL ON wpdb TO 'wpuser'@'192.168.2.110'; Query OK, 0 rows affected (0.01 sec) MariaDB [wpdb]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) MariaDB [wpdb]> exit Bye
(5)测试
九、安装xcache
(1)未安装xcache时进行测试
[root@localhost wordpress]# ab -c 200 -n 10000 pma.mylinuxops.com/pma This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking pma.mylinuxops.com (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.4.6 Server Hostname: pma.mylinuxops.com Server Port: 80 Document Path: /pma Document Length: 238 bytes Concurrency Level: 200 Time taken for tests: 7.286 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Non-2xx responses: 10000 Total transferred: 4780000 bytes HTML transferred: 2380000 bytes Requests per second: 1372.57 [#/sec] (mean) Time per request: 145.712 [ms] (mean) Time per request: 0.729 [ms] (mean, across all concurrent requests) Transfer rate: 640.71 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 11 86.2 5 3018 Processing: 14 80 285.2 60 7231 Waiting: 1 78 285.2 58 7231 Total: 31 91 298.6 65 7247 Percentage of the requests served within a certain time (ms) 50% 65 66% 69 75% 71 80% 72 90% 80 95% 89 98% 269 99% 470 100% 7247 (longest request)
(2)安装xcache并测试
[root@localhost wordpress]# yum install -y php-xcache [root@localhost wordpress]# systemctl restart httpd [root@localhost wordpress]# ab -c 200 -n 10000 pma.mylinuxops.com/pma This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking pma.mylinuxops.com (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: Apache/2.4.6 Server Hostname: pma.mylinuxops.com Server Port: 80 Document Path: /pma Document Length: 238 bytes Concurrency Level: 200 Time taken for tests: 4.907 seconds Complete requests: 10000 Failed requests: 0 Write errors: 0 Non-2xx responses: 10000 Total transferred: 4780000 bytes HTML transferred: 2380000 bytes Requests per second: 2037.87 [#/sec] (mean) Time per request: 98.142 [ms] (mean) Time per request: 0.491 [ms] (mean, across all concurrent requests) Transfer rate: 951.27 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 23 7.4 22 53 Processing: 26 74 14.3 71 290 Waiting: 1 64 14.7 62 280 Total: 41 97 14.4 94 325 Percentage of the requests served within a certain time (ms) 50% 94 66% 99 75% 105 80% 107 90% 113 95% 117 98% 121 99% 127 100% 325 (longest request)
十、为pma提供https
(1) 为服务器申请数字证书;
(a) 创建私有CA
[root@localhost wordpress]# cd /etc/pki/CA [root@localhost CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048) Generating RSA private key, 2048 bit long modulus ...................................................................+++ ...............................................................................................................+++ e is 65537 (0x10001) [root@localhost CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650 You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:Shanghai Locality Name (eg, city) [Default City]:Shanghai Organization Name (eg, company) [Default Company Ltd]:mylinuxops Organizational Unit Name (eg, section) []:ops Common Name (eg, your name or your server's hostname) []:ca.mylinuxops.com Email Address []:caadmin.mylinuxops.com [root@localhost CA]# touch serial index.txt [root@localhost CA]# echo 01 > serial
(b) 在服务器创建证书签署请求
[root@localhost CA]# cd /etc/httpd/ [root@localhost httpd]# mkdir ssl [root@localhost httpd]# cd ssl [root@localhost ssl]# (umask 077; openssl genrsa -out httpd.key 1024) Generating RSA private key, 1024 bit long modulus ......................++++++ .................++++++ e is 65537 (0x10001) [root@localhost ssl]# openssl req -new -key httpd.key -out httpd.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:Shanghai Locality Name (eg, city) [Default City]:Shanghai Organization Name (eg, company) [Default Company Ltd]:mylinuxops Organizational Unit Name (eg, section) []:ops Common Name (eg, your name or your server's hostname) []:pma.mylinuxops.com Email Address []:pmadmin@mylinuxops.com Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
(c) CA签证
[root@localhost ssl]# cd /etc/pki/CA/ [root@localhost CA]# openssl ca -in /etc/httpd/ssl/httpd.csr -out certs/httpd.crt Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok Certificate Details: Serial Number: 1 (0x1) Validity Not Before: Apr 14 05:42:48 2018 GMT Not After : Apr 14 05:42:48 2019 GMT Subject: countryName = CN stateOrProvinceName = Shanghai organizationName = mylinuxops organizationalUnitName = ops commonName = pma.mylinuxops.com emailAddress = pmadmin@mylinuxops.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 84:1A:5D:C1:73:2A:B2:17:F9:5E:18:5F:2C:85:C3:6A:A6:83:9D:B5 X509v3 Authority Key Identifier: keyid:E4:00:05:49:AF:4D:2A:44:92:9C:B7:FD:63:E2:D5:7A:6F:54:84:6E Certificate is to be certified until Apr 14 05:42:48 2019 GMT (365 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated
(2) 配置httpd支持使用ssl,及使用的证书;
[root@localhost ssl]# yum -y install mod_ssl
配置文件:/etc/httpd/conf.d/ssl.conf
DocumentRoot "/www/htdocs/web1/" ServerName pma.mylinuxops.com:443 <Directory /www/htdocs/web1/pma> options followsymlinks allowOverRide none require all granted </Directory> SSLCertificateFile /etc/httpd/ssl/httpd.crt SSLCertificateKeyFile /etc/httpd/ssl/httpd.key