标签:local b16 httpd php emc mys 使用 cto failure pre
前言<> 非常感谢Kason老师,您是我们成功的蜡烛,燃烧着自己,照亮我们前进的道路。
varnish配置动静分离时,这些问题困扰了两周:
- 环境:varnish做为反代,你们都知道的:varnish,nginx, haproxy都可以做为反代服务器,varnish比较擅长缓存。后端主机一个提供动态资源及变化的资源(php, css, js),一个提供静态资源(images)
- 每次访问varnish的6081端口,phpinfo.php和php-mysql.php都可以正常访问,肯定没有问题,但访问wodpress时,要么是NOT FOUND要么是直接将目录索引显示出来。
> 总结:
> 对中小型站点的整个架构没有一个完整、清晰的认识。
> 我只是将老师的配置粘贴进去,从不去想真正的含义。
> * 学到puppet时,越觉得前面的东西是多么重要,了解一个个架构,才能更好的驾驶运维工具本身。
所有节点时间同步。
关闭防火墙、SELinux。
yum源:EPEL、Base。~]# ntpdate 0.centos.pool.ntp.org ~]# iptables -F ~]# setenforce 0
~]# yum -y install httpd
~]# systemctl start httpd.service
http://172.16.0.68/
Testing 123..
~]# yum -y install httpd php php-mysql mariadb-server php-mbstring php-mcrypt
~]# systemctl start httpd.service
http://172.16.0.69/
Testing 123..
~]# vim /etc/my.cnf.d/server.cnf
[mysqld]
skip_name_resolve = ON
innodb_file_per_table = ON
~]# systemctl start mariadb.service
~]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
[root@localhost ~]# mysql
MariaDB [(none)]> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wordpress.* TO ‘wpuser‘@‘172.16.0.%‘ IDENTIFIED BY ‘wppass‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
~]# mysql -uwpuser -pwppass -h172.16.0.69
~]# cp wordpress-4.9.1-zh_CN.tar.gz /var/www/html/
~]# tar xf wordpress-4.9.1-zh_CN.tar.gz
~]# ln -sv wordpress wp
~]# ll
total 9912
-rw-------. 1 root root 1637 Dec 6 02:45 anaconda-ks.cfg
-rw-r--r--. 1 root root 1556 Jan 14 14:58 genaral_test.sh
drwxr-xr-x. 1 nobody nfsnobody 498 Nov 30 20:20 wordpress
-rw-r--r--. 1 root root 10130710 Dec 1 18:57 wordpress-4.9.1-zh_CN.tar.gz
lrwxrwxrwx. 1 root root 9 Jan 14 15:41 wp -> wordpress
-rw-r--r--. 1 root root 832 Jan 14 14:58 yum.sh
/** WordPress数据库的名称 */
define(‘DB_NAME‘, ‘wordpress‘);
/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘wpuser‘);
/** MySQL数据库密码 */
define(‘DB_PASSWORD‘, ‘wppass‘);
/** MySQL主机 */
define(‘DB_HOST‘, ‘172.16.0.69‘);
~]# cat /var/www/html/index.html
<h1>172.16.0.69</h1>
~]# cat /var/www/html/phpinfo.php
<html>
<title>Test Page</title>
<body>
<h1>172.16.0.69</h1>
<?php
phpinfo();
?>
</body>
</html>
~]# cat /var/www/html/php-mysql.php
<?php
$conn = mysql_connect(‘172.16.0.69‘,‘wpuser‘,‘wppass‘);
if ($conn)
echo "connect 172.16.0.69 success";
else
echo "connect 172.16.0.69 failure";
?>
~]# scp -r /var/www/html/{wordpress,wp} 172.16.0.68:/var/www/html
~]# yum -y install varnish
~]# vim /etc/varnish/varnish.params
‘VARNISH_LISTEN_PORT=80
VARNISH_STORAGE="file,/data/varnish/cache,1g"
~]# vim /etc/varnish/default.vcl
backend default {
.host = "172.16.0.68";
.port = "80";
}
backend appsrv {
.host = "172.16.0.69";
.port = "80";
}
sub vcl_recv {
if (req.url ~ "(?i)\.(php|jsp|do)$") {
set req.backend_hint = appsrv;
}
if (req.url ~ "(?i)\.(css|js)$") {
set req.backend_hint = appsrv;
}
if (req.url ~ "(?i)\.(jpg|jpeg|png|gif)$") {
set req.backend_hint = default;
} else {
set req.backend_hint = appsrv;
}
}
~]# install -d -v -o varnish -g varnish /data/varnish/cache
~]# systemctl start varnish.service
~]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
CentOS 7.1.1503 varnish动静分离反代用户请求
标签:local b16 httpd php emc mys 使用 cto failure pre
原文地址:http://blog.51cto.com/sonlich/2060785