基于LAMP应用phpmyadmin
[root@Centos7 ~]# yum install httpd mariadb-server php php-mysql php-mbstring
[root@Centos7 ~]# wget https://files.phpmyadmin.net/phpMyAdmin/4.4.15.10/phpMyAdmin-4.4.15.10-all-languages.tar.xz
[root@Centos7 ~]# systemctl start httpd mariadb
[root@Centos7 ~]# mysql_secure_installation #初始化数据库
[root@Centos7 ~]# tar xf phpMyAdmin-4.4.15.10-all-languages.tar.xz -C /var/www/html
[root@Centos7 ~]# cd /var/www/html
[root@Centos7 html]# ls
[root@Centos7 html]# mv phpMyAdmin-4.4.15.10-all-languages/ phpmyadmin
[root@Centos7 html]# cd phpmyadmin
[root@Centos7 phpmyadmin]# cp config.sample.inc.php config.inc.php
#测试
http://192.168.37.7/phpmyadmin
实现wordpress个人博客系统
#2台服务器分开做,A:httpd B:mariadb
#mariadb-server
[root@Centos7 ~]# yum install mariadb-server
[root@Centos7 ~]# systemctl start mariadb
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wpuser@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#http-server
[root@Centos7 ~]# wget https://cn.wordpress.org/wordpress-5.1.4-zh_CN.tar.gz
[root@Centos7 ~]# yum install httpd php php-mysql
[root@Centos7 ~]# vim /etc/php.ini
date.timezone = Asia/Shanghai
[root@Centos7 ~]# systemctl restart httpd
[root@Centos7 ~]# tar xf wordpress-5.1.4-zh_CN.tar.gz -C /var/www/html
[root@Centos7 ~]# cd /var/www/html
[root@Centos7 html]# chown apache:apache wordpress/
[root@Centos7 html]# cd wordpress/
[root@Centos7 wordpress]# cp wp-config-sample.php wp-config.php
[root@Centos7 wordpress]# vim wp-config.php
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );
/** MySQL数据库用户名 */
define( 'DB_USER', 'wpuser' );
/** MySQL数据库密码 */
define( 'DB_PASSWORD', 'centos' );
/** MySQL主机 */
define( 'DB_HOST', '192.168.37.17' );
#测试
http://192.168.37.7/wordpress
实现discuz! 实现论坛
#mariadb-server
MariaDB [(none)]> create database ultrax;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on ultrax.* to fourm@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#http-server
[root@Centos7 discuz]# unzip Discuz_X3.3_SC_UTF8_0301.zip
[root@Centos7 discuz]# cp -r upload /var/www/html/fourm
[root@Centos7 discuz]# setfacl -Rm u:apache:rwx /var/www/html/fourm/
#测试
http://192.168.37.7/forum
实现powerdns
#单独1台服务器做
[root@Centos7 ~]# yum install pdns pdns-backend-mysql httpd php php-mysql mariadb-server
#依赖包
[root@Centos7 ~]# yum -y install httpd php php-devel php-gd php-mcrypt php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-mbstring php mcrypt php-mhash gettext
[root@Centos7 ~]# wget http://downloads.sourceforge.net/project/poweradmin/poweradmin-2.1.7.tgz
[root@Centos7 ~]# systemctl start mariadb
[root@Centos7 ~]# mysql -uroot -p
--创建powerdns相关表
MariaDB [(none)]> create database powerdns;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on powerdns.* to 'powerdns'@'localhost' identified by 'magedu';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> use powerdns;
Database changed
--官方说明需要创建的表
MariaDB [powerdns]> CREATE TABLE domains (
id INT AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
master VARCHAR(128) DEFAULT NULL,
last_check INT DEFAULT NULL,
type VARCHAR(6) NOT NULL,
notified_serial INT DEFAULT NULL,
account VARCHAR(40) DEFAULT NULL,
PRIMARY KEY (id)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE UNIQUE INDEX name_index ON domains(name);
Query OK, 0 rows affected (0.04 sec)
MariaDB [powerdns]> CREATE TABLE records (
id BIGINT AUTO_INCREMENT,
domain_id INT DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL,
type VARCHAR(10) DEFAULT NULL,
content VARCHAR(64000) DEFAULT NULL,
ttl INT DEFAULT NULL,
prio INT DEFAULT NULL,
change_date INT DEFAULT NULL,
disabled TINYINT(1) DEFAULT 0,
ordername VARCHAR(255) BINARY DEFAULT NULL,
auth TINYINT(1) DEFAULT 1,
PRIMARY KEY (id)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE INDEX nametype_index ON records(name,type);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE INDEX domain_id ON records(domain_id);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE INDEX recordorder ON records (domain_id, ordername);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE TABLE supermasters (
ip VARCHAR(64) NOT NULL,
nameserver VARCHAR(255) NOT NULL,
account VARCHAR(40) NOT NULL,
PRIMARY KEY (ip, nameserver)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE TABLE comments (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
type VARCHAR(10) NOT NULL,
modified_at INT NOT NULL,
account VARCHAR(40) NOT NULL,
comment VARCHAR(64000) NOT NULL,
PRIMARY KEY (id)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE INDEX comments_domain_id_idx ON comments (domain_id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE INDEX comments_name_type_idx ON comments (name, type);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE INDEX comments_order_idx ON comments (domain_id, modified_at);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE TABLE domainmetadata (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
kind VARCHAR(32),
content TEXT,
PRIMARY KEY (id)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE INDEX domainmetadata_idx ON domainmetadata (domain_id, kind);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE TABLE cryptokeys (
id INT AUTO_INCREMENT,
domain_id INT NOT NULL,
flags INT NOT NULL,
active BOOL,
content TEXT,
PRIMARY KEY(id)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE INDEX domainidindex ON cryptokeys(domain_id);
ngine=InnoDB;Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [powerdns]> CREATE TABLE tsigkeys (
id INT AUTO_INCREMENT,
name VARCHAR(255),
algorithm VARCHAR(50),
secret VARCHAR(255),
PRIMARY KEY (id)
) Engine=InnoDB;
Query OK, 0 rows affected (0.00 sec)
MariaDB [powerdns]> CREATE UNIQUE INDEX namealgoindex ON tsigkeys(name, algorithm);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
#修改powerdns配置文件
[root@Centos7 ~]# vim /etc/pdns/pdns.conf
launch=gmysql
gmysql-host=192.168.37.7
gmysql-port=3306
gmysql-dbname=powerdns
gmysql-user=powerdns
gmysql-password=magedu
#准备好poweradmin程序
[root@Centos7 ~]# tar xf poweradmin-2.1.7.tgz -C /var/www/html
[root@Centos7 ~]# cd /var/www/html/
[root@Centos7 html]# mv poweradmin-2.1.7/ poweradmin
#重启服务
[root@Centos7 html]# systemctl restart httpd
客户端安装:
http://192.168.37.7/poweradmin/install/
第一步:
image.png 第二步: image.png第三步:
image.png第四步:
image.png第五步:
image.pngMariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE ON powerdns.* TO 'poweradmin'@'localhost' IDENTIFIED BY 'magedu';
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
第六步:
image.png[root@Centos7 html]# vim poweradmin/inc/config.inc.php
<?php
$db_host = 'localhost';
$db_user = 'poweradmin';
$db_pass = 'magedu';
$db_name = 'powerdns';
$db_type = 'mysql';
$db_layer = 'PDO';
$session_key = 'b!0&e@T2i0_87cGFD1YqN3Cm$tcvY1Bh-w59[-v#OwjFB(';
$iface_lang = 'en_EN';
$dns_hostmaster = 'dnsserver';
$dns_ns1 = '192.168.37.7';
$dns_ns2 = '';
第七步:
image.png[root@Centos7 html]# rm -rf poweradmin/install/
最后:http://192.168.37.7/poweradmin
username:admin
password:magedu
编译安装xcache实现加速
#加速前的压力测试结果
[root@centos6 ~]$ ab -c 200 -n 2000 http://192.168.37.7/wordpress
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.37.7 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: Apache/2.4.6
Server Hostname: 192.168.37.7
Server Port: 80
Document Path: /wordpress
Document Length: 238 bytes
Concurrency Level: 200
Time taken for tests: 0.658 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Non-2xx responses: 2000
Total transferred: 956000 bytes
HTML transferred: 476000 bytes
Requests per second: 3038.48 [#/sec] (mean)
Time per request: 65.822 [ms] (mean)
Time per request: 0.329 [ms] (mean, across all concurrent requests)
Transfer rate: 1418.35 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 3.2 0 18
Processing: 8 54 103.7 33 634
Waiting: 1 53 103.8 33 633
Total: 20 55 104.4 34 639
Percentage of the requests served within a certain time (ms)
50% 34
66% 36
75% 37
80% 41
90% 51
95% 59
98% 626
99% 632
100% 639 (longest request)
#搭建加速
[root@Centos7 ~]# wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
[root@Centos7 ~]# tar xf xcache-3.2.0.tar.gz
[root@Centos7 ~]# cd xcache-3.2.0/
[root@Centos7 xcache-3.2.0]# phpize --clean && phpize
[root@Centos7 xcache-3.2.0]# ./configure --enable-xcache
[root@Centos7 xcache-3.2.0]# make && make install
[root@Centos7 xcache-3.2.0]# cp xcache.ini /etc/php.d/
[root@Centos7 xcache-3.2.0]# systemctl restart httpd
#客户端
http://192.168.37.7/info.php #查看xcache模块是否被加载
[root@centos6 ~]$ ab -c 200 -n 2000 http://192.168.37.7/wordpress #同样的压力测试
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.37.7 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: Apache/2.4.6
Server Hostname: 192.168.37.7
Server Port: 80
Document Path: /wordpress
Document Length: 238 bytes
Concurrency Level: 200
Time taken for tests: 0.860 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Non-2xx responses: 2000
Total transferred: 956000 bytes
HTML transferred: 476000 bytes
Requests per second: 2325.01 [#/sec] (mean) #速度快了30%
Time per request: 86.021 [ms] (mean)
Time per request: 0.430 [ms] (mean, across all concurrent requests)
Transfer rate: 1085.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 2.8 0 17
Processing: 10 52 92.8 33 623
Waiting: 1 52 92.8 33 623
Total: 18 54 93.5 35 628
Percentage of the requests served within a certain time (ms)
50% 35
66% 38
75% 40
80% 44
90% 51
95% 56
98% 617
99% 623
100% 628 (longest request)
基于端口号 php-fpm 的LAMP
#php-fpm与php冲突,只能二选一使用,所以先卸载php
[root@Centos7 ~]# yum remove php
[root@Centos7 ~]# yum install php-fpm
[root@Centos7 ~]# mkdir -p /var/lib/php/session
[root@Centos7 ~]# chown apache.apache /var/lib/php/session
[root@Centos7 ~]# vim /etc/httpd/conf.d/fcgi.conf #http配置支持php-fpm
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
[root@Centos7 ~]# vim /etc/php-fpm.d/www.conf #优化一下
user = apache
group = apache
pm = dynamic
pm.max_children = 500
pm.start_servers = 30
pm.min_spare_servers = 50
pm.max_spare_servers = 60
pm.max_requests = 500
pm.status_path = /status
ping.response = pong
[root@Centos7 ~]# mv /etc/php.d/xcache.ini /etc/php.d/xcache.ini.bak #把加速模块先卸载
[root@Centos7 ~]# systemctl restart httpd php-fpm
#客户端测试
[root@centos6 ~]$ ab -c 200 -n 2000 http://192.168.37.7/wordpress
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.37.7 (be patient)
Completed 200 requests
Completed 400 requests
Completed 600 requests
Completed 800 requests
Completed 1000 requests
Completed 1200 requests
Completed 1400 requests
Completed 1600 requests
Completed 1800 requests
Completed 2000 requests
Finished 2000 requests
Server Software: Apache/2.4.6
Server Hostname: 192.168.37.7
Server Port: 80
Document Path: /wordpress
Document Length: 238 bytes
Concurrency Level: 200
Time taken for tests: 0.859 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Non-2xx responses: 2000
Total transferred: 934000 bytes
HTML transferred: 476000 bytes
Requests per second: 2327.59 [#/sec] (mean) #速度跟php+xcache差不多
Time per request: 85.926 [ms] (mean)
Time per request: 0.430 [ms] (mean, across all concurrent requests)
Transfer rate: 1061.51 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 4.3 0 22
Processing: 9 53 94.5 34 615
Waiting: 1 53 94.6 34 615
Total: 22 56 95.9 35 625
Percentage of the requests served within a certain time (ms)
50% 35
66% 38
75% 44
80% 47
90% 54
95% 56
98% 621
99% 623
100% 625 (longest request)
基于UDS(unix domain socket)模式的php-fpm 的LAMP
1、socket套接字链接需要版本2.4.9以上,而centos7版本为2.4.6(真尴尬),故需要编译新版
[root@Centos7 ~]# yum remove httpd #先卸载原本的httpd
[root@Centos7 ~]# yum install gcc pcre-devel openssl-devel expat-devel #安装依赖
[root@Centos7 ~]# ls *.bz2 | xargs -n1 tar xf
[root@Centos7 ~]# cp -r apr-1.7.0 httpd-2.4.39/srclib/apr
[root@Centos7 ~]# cp -r apr-util-1.6.1 httpd-2.4.39/srclib/apr-util
[root@Centos7 ~]# cd httpd-2.4.39
2、编译安装
[root@Centos7 ~]# ./configure \
--prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@Centos7 httpd-2.4.39]# make && make install
3、配置环境变量
[root@Centos7 httpd-2.4.39]# echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh
[root@Centos7 httpd-2.4.39]# . /etc/profile.d/httpd24.sh
4、配置apache配置文件
[root@Centos7 httpd-2.4.39]# useradd -r -s /sbin/nologin apache
[root@Centos7 httpd-2.4.39]# vim /app/httpd24/conf/httpd.conf
User apache
Group apache
ServerName www.example.com:80
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
DirectoryIndex index.php index.html
#最后追加以下支持php文件
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5-fpm.sock|fcgi://localhost/app/httpd24/htdocs"
5、配置php-fpm文件
[root@Centos7 httpd-2.4.39]# vim /etc/php-fpm.d/www.conf
listen=/var/run/php5-fpm.sock
listen.owner=apache
listen.group=apache
listen.mode=0666
6、启动服务
[root@Centos7 httpd-2.4.39]# apachectl start
[root@Centos7 httpd-2.4.39]# systemctl restart php-fpm
#测试
http://192.168.37.7/info.php
编译安装LAMP,实现多虚拟主机,一个虚拟主机blog.magedu.com 一个虚拟主机 forum.magedu.com
#2台机器,server1:httpd+php-fpm(ip:7) server2:mariadb(ip:17)
1、http-server,上一步已把apache编译了,现在添加一个服务文件
[root@Centos7 ~]# vim /usr/lib/systemd/system/httpd24.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/app/httpd24/bin/apachectl start
ExecStop=/app/httpd24/bin/apachectl stop
ExecReload=/app/httpd24/bin/apachectl graceful
PrivateTmp=true
Restart=on-abort
[Install]
WantedBy=multi-user.target
2、配置apache
[root@Centos7 ~]# vim /app/httpd24/conf/httpd.conf
User apache
Group apache
ServerName www.magedu.com:80
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
Include conf/extra/web.conf
[root@Centos7 ~]# vim /app/httpd24/conf/extra/web.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
DirectoryIndex index.php index.html
<virtualhost *:80>
servername blog.magedu.com
documentroot /data/www/wordpress
ProxyPassMatch ^/(.*\.php)$ "unix:/var/run/php5-fpm.sock|fcgi://localhost/data/www/wordpress"
<directory /data/www/wordpress>
require all granted
</directory>
</virtualhost>
<virtualhost *:80>
servername fourm.magedu.com
documentroot /data/www/fourm
ProxyPassMatch ^/(.*\.php)$ "unix:/var/run/php5-fpm.sock|fcgi://localhost/data/www/fourm"
<directory /data/www/fourm>
require all granted
</directory>
</virtualhost>
3、创建目录和网页文件
[root@Centos7 ~]# tar -xf wordpress-5.1.1-zh_CN.tar.gz -C /data/www/
[root@Centos7 ~]# cd discuz/
[root@Centos7 discuz]# unzip Discuz_X3.3_SC_UTF8_0301.zip
[root@Centos7 discuz]# cp -r upload /data/www/fourm
[root@Centos7 discuz]# cd ../wordpress/
[root@Centos7 wordpress]# cp wp-config-sample.php wp-config.php
[root@Centos7 wordpress]# vim wp-config.php
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );
/** MySQL数据库用户名 */
/*define( 'DB_USER', 'wpuser' );*/
define( 'DB_USER', 'wordpress' );
/** MySQL数据库密码 */
define( 'DB_PASSWORD', 'centos' );
/** MySQL主机 */
define( 'DB_HOST', '192.168.37.17' );
[root@Centos7 ~]# setfacl -Rm u:apache:rwx /data/www/{wordpress,fourm}
4、安装php-fpm
[root@Centos7 ~]# yum install libxml2-devel bzip2-devel libmcrypt-devel gcc openssl-devel
[root@Centos7 ~]# tar xf php-7.3.15.tar.xz
[root@Centos7 ~]# cd php-7.3.15/
[root@Centos7 php-7.3.15]# ./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
[root@Centos7 php-7.3.15]# make && make install
5、配置文件
[root@Centos7 php-7.3.15]# cp php.ini-production /etc/php.ini -b
[root@Centos7 php-7.3.15]# cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
[root@Centos7 php-7.3.15]# cp /app/php/etc/php-fpm.d/www.conf.default /app/php/etc/php-fpm.d/www.conf
[root@Centos7 php-7.3.15]# vim /app/php/etc/php-fpm.d/www.conf
user = apache
group = apache
listen = /var/run/php5-fpm.sock
listen.owner = apache
listen.group = apache
listen.mode = 0660
6、启动文件
[root@Centos7 php-7.3.15]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@Centos7 php-7.3.15]# chmod +x /etc/init.d/php-fpm
[root@Centos7 php-7.3.15]# chkconfig --add php-fpm
7、启动服务
[root@Centos7 ~]# systemctl start httpd24
[root@Centos7 ~]# service php-fpm start
#mariadb-server
1、准备好用户和目录
[root@Centos7 ~]# useradd -r -s /sbin/nologin -d /data/mysql mysql
[root@Centos7 ~]# mkdir /data/mysql
[root@Centos7 ~]# chown mysql.mysql /data/mysql
[root@Centos7 ~]# tar xf mariadb-10.2.25-linux-x86_64.tar.gz -C /usr/local
[root@Centos7 ~]# ln -s /usr/local/mariadb-10.2.25-linux-x86_64/ /usr/local/mysql
[root@Centos7 ~]# cd /usr/local/mysql
2、数据库安装
[root@Centos7 mysql]# echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@Centos7 mysql]# . /etc/profile.d/mysql.sh
[root@Centos7 mysql]# scripts/mysql_install_db --datadir=/data/mysql --user=mysql
[root@Centos7 mysql]# cp support-files/my-huge.cnf /etc/my.cnf
3、修改数据库目录
[root@Centos7 mysql]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
4、准备启动文件
[root@Centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@Centos7 mysql]# chmod +x /etc/init.d/mysqld
[root@Centos7 mysql]# chkconfig --add mysqld
5、启动数据库并配置
[root@Centos7 mysql]# service mysqld start
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on discuz.* to discuz@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#客户端测试
http://blog.magedu.com
http://fourm.magedu.com
CentOS 7, lamp (module);
(1) 三者分离于两台主机
(2) 一个虚拟主机提供phpMyAdmin;另一个虚拟主机提供wordpress
(3) xcache
(4) 为phpMyAdmin提供https虚拟主机
#2台主机,http-server(37.7) mariadb-server(37.17)
#http-server
1、安装httpd,php
[root@Centos7 ~]# yum install httpd php php-mysql -y
2、编译xcache
[root@Centos7 ~]# tar xf xcache-3.2.0.tar.gz
[root@Centos7 ~]# cd xcache-3.2.0/
[root@Centos7 xcache-3.2.0]# phpize --clean && phpize
[root@Centos7 xcache-3.2.0]# ./configure --enable-xcache
[root@Centos7 xcache-3.2.0]# make && make install
[root@Centos7 xcache-3.2.0]# cp xcache.ini /etc/php.d/
3、配置虚拟主机
[root@Centos7 ~]# vim /etc/httpd/conf.d/web.conf
<virtualhost *:80>
documentroot "/data/www/phpmyadmin"
servername www.a.com
<directory "/data/www/phpmyadmin">
require all granted
</directory>
</virtualhost>
<virtualhost *:80>
documentroot "/data/www/wordpress"
servername www.b.com
<directory "/data/www/wordpress">
require all granted
</directory>
</virtualhost>
4、准备好phpmyadmin、wordpress网页文件
[root@Centos7 ~]# mkdir /data/www/
[root@Centos7 ~]# tar xf phpMyAdmin-4.4.15.10-all-languages.tar.xz -C /data/www/
[root@Centos7 ~]# tar xf wordpress-5.1.1-zh_CN.tar.gz -C /data/www/
[root@Centos7 ~]# cd /data/www
[root@Centos7 www]# mv phpMyAdmin-4.4.15.10-all-languages/ phpmyadmin
[root@Centos7 www]# chown -R apache.apache /data/www
[root@Centos7 www]# cp phpmyadmin/config.sample.inc.php phpmyadmin/config.inc.php
[root@Centos7 www]# vim phpmyadmin/config.inc.php
$cfg['Servers'][$i]['host'] = '192.168.37.17';
[root@Centos7 www]# cp wordpress/wp-config-sample.php wordpress/wp-config.php
[root@Centos7 www]# vim wordpress/wp-config.php
/** WordPress数据库的名称 */
define( 'DB_NAME', 'wordpress' );
/** MySQL数据库用户名 */
define( 'DB_USER', 'wpuser' );
/** MySQL数据库密码 */
define( 'DB_PASSWORD', 'centos' );
/** MySQL主机 */
define( 'DB_HOST', '192.168.37.17' );
[root@Centos7 www]# vim /etc/php.ini
date.timezone = Asia/Shanghai
5、为phpmyadmin配置https
[root@Centos7 www]# yum install mod_ssl
[root@Centos7 www]# vim /etc/httpd/conf.d/web.conf
<virtualhost *:443>
documentroot "/data/www/phpmyadmin"
servername www.a.com
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
<directory "/data/www/phpmyadmin">
require all granted
</directory>
</virtualhost>
6、启动服务
[root@Centos7 www]# systemctl start httpd
#mariadb-server
1、安装数据库
[root@Centos7 ~]# yum install mariadb-server -y
[root@Centos7 ~]# systemctl restart mariadb
2、配置数据库
[root@Centos7 ~]# mysql_secure_installation
[root@Centos7 ~]# mysql -uroot -p
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wpuser@'192.168.37.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#测试
https://www.a.com
http://www.b.com
CentOS 7, lamp (php-fpm)
(1) 三者分离于三台主机
(2) 一个虚拟主机提供phpMyAdmin;另一个虚拟主机提供wordpress
(3) xcache
#在前面的基础上作修改
#3台主机,http-server(37.7) mariadb-server(37.17) php-fpm(192.168.37.27)
#http-server
[root@Centos7 www]# yum remove php php-mysql
[root@Centos7 www]# rm /etc/php.d/xcache.ini
[root@Centos7 www]# httpd -M | grep proxy #保证以下模块已加载
proxy_module (shared)
proxy_fcgi_module (shared)
[root@Centos7 www]# vim /etc/httpd/conf.d/web.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests on
directoryindex index.php index.html
<virtualhost *:80>
documentroot "/data/www/phpmyadmin"
servername www.a.com
ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.37.27:9000/data/www/phpmyadmin"
<directory "/data/www/phpmyadmin">
require all granted
</directory>
</virtualhost>
<virtualhost *:443>
documentroot "/data/www/phpmyadmin"
servername www.a.com
ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.37.27:9000/data/www/phpmyadmin"
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
<directory "/data/www/phpmyadmin">
require all granted
</directory>
</virtualhost>
<virtualhost *:80>
documentroot "/data/www/wordpress"
servername www.b.com
ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.37.27:9000/data/www/wordpress"
<directory "/data/www/wordpress">
require all granted
</directory>
</virtualhost>
[root@Centos7 www]# scp -r /data/www 192.168.37.27:/data
[root@Centos7 www]# systemctl restart httpd
#mariadb-server保持不变
#php-fpm
[root@localhost ~]# yum install php-fpm php-mysql php-pear php-cli php-xmlrpc php-odbc php-gd php-ldap php-common php-mbstring php-process php-xml php-devel php-imap php-pdo php-mcrypt
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
listen = 9000
;listen.allowed_clients = 127.0.0.1
[root@localhost ~]# chown -R apache.apache /data/www
[root@localhost ~]# mkdir -p /var/lib/php/session/ #不加这两步phpmyadmin会报错
[root@localhost ~]# chown :apache /var/lib/php/session/
[root@localhost ~]# chmod 770 /var/lib/php/session/
[root@localhost ~]# systemctl restart php-fpm
#测试
http://www.a.com
http://www.b.com
网友评论