nginx负载均衡搭建wordpress网站_php

 以上是拓扑图。

前面三台都是nginx服务器。通过第一台nginx做负债均衡。要写一个upstream 。

upstream blog_pools {
    server 192.168.19.39:80;
    server 192.168.19.40:80;





}

server {
    listen 80;
    server_name blog.oldboylinux.cn;
    error_log /var/log/nginx/blog-error.log notice;
    access_log /var/log/nginx/blog-access.log main;

    location / {
       proxy_pass http://blog_pools;
       proxy_set_header Host $http_host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


}




}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.

  然后在web01和web02上搭建好同一个网站。可以先在web01上把网站搭建好,数据库和NFS客户端都连接好,然后把web01的网站代码拷贝到web02就可以了。

搭建web01就是先安装nginx和php-fpm .

先安装建立yum源

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

 

vim /etc/yum.repos.d/php.repo

[webtatic-php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64
enabled = 1
gpgcheck = 0
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

 

安装nginx

yum install -y nginx

systemctl enable nginx

systemctl start nginx

安装php

yum install -y php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mcrypt php72w-mbstring php72w-pdo php72w-fpm php72w-mysqlnd php72w-opcache php72w-pecl-memcached php72w-pecl-redis php72w-pecl-mongodb

systemctl enable php-fpm

systemctl start php-fpm

web01下的  cat /etc/nginx/conf.d/blog.oldboylinux.cn.conf

server {
   listen 80;
   server_name blog.oldboylinux.cn;
   root /app/code/blog;
   
   error_log /var/log/nginx/blog-error.log notice ;
   access_log /var/log/nginx/blog-access.log main ;
   
   location / {
      index index.php ;
   

}
   location ~* \.php$ {
    #传递给php
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_buffering on;
      fastcgi_buffers 64 64k;
     # 下面内容需要修改
     # fastcgi_param  SCRIPT_FILENAME /app/coapp/code/blog$fastcgi_script_name;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      
      include       fastcgi_params ;




   }


}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.

web02下的 cat /etc/nginx/conf.d/blog.oldboylinux.cn.conf

server {
   listen 80;
   server_name blog.oldboylinux.cn;
   root /app/code/blog;
   
   error_log /var/log/nginx/blog-error.log notice ;
   access_log /var/log/nginx/blog-access.log main ;
   
   location / {
      index index.php ;
   

}
   location ~* \.php$ {
    #传递给php
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_buffering on;
      fastcgi_buffers 64 64k;
     # 下面内容需要修改
     # fastcgi_param  SCRIPT_FILENAME /app/coapp/code/blog$fastcgi_script_name;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      
      include       fastcgi_params ;




   }


}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.

建立一个网站的访问用户

groupadd -g 1999 www

useradd -u 1999 -g www -s /sbin/nologin -M www

建立这个用户是为了网站的安全

nginx负载均衡搭建wordpress网站_linux_02

 

nginx负载均衡搭建wordpress网站_php_03

还有php配置文件的用户

nginx负载均衡搭建wordpress网站_nginx_04

 vim /etc/php-fpm.d/www.conf

nginx负载均衡搭建wordpress网站_php_05

 

 搭建NFS .

yum install -y rpcbind nfs-utils

nginx负载均衡搭建wordpress网站_nginx_06

 

这个1999 的就是我建立的www用户,写入到nfs配置文件里

客户端挂载nfs

nginx负载均衡搭建wordpress网站_linux_07

 如果没有相应的文件夹,就先建立。

最后安装mysql

yum install -y mariadb-server

systemctl enable mariadb

systemctl start mariadb

配置

mysql_secure_installation

创建数据库

create database wordpress;

grant all PRIVILEGES on wordpress.* to 'wp'@'%' identified by 'iso9001';

表示建立一个wp的用户,设置密码iso9001 ,然后允许所有网络可以连接