Linux负载均衡实现(靠谱)

配置之前清空所有服务器防火墙规则

iptables -F
关闭selinux:
1、/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态
SELinux status:                 enabled
2、getenforce                 ##也可以用这个命令检查
关闭SELinux:
1、临时关闭(不用重启机器):
setenforce 0                  ##设置SELinux 成为permissive模式
                              ##setenforce 1 设置SELinux 成为enforcing模式
2、修改配置文件需要重启机器:
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可
reboot
 
 
一、nginx服务器分发配置
yum安装nginx分发器:
1 配置yum源:
第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo:
vim /etc/yum.repos.d/nginx.repo
 
填写以下内容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
 
保存,则会产生一个/etc/yum.repos.d/nginx.repo文件。
 
2 安装:
yum install nginx -y
 
配置nginx反向代理:
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    #tcp_nopush on;

    keepalive_timeout 65;

    #gzip on;

    # include /etc/nginx/conf.d/*.conf;
    upstream myserver {
      ip_hash;
      server 192.168.75.133;
      server 192.168.75.134;
    }
    server{
      listen 80;
      server_name 192.168.75.132;
      location / {
        proxy_pass http://myserver;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
}

 

二、配置两台后端服务器:
1 、配置好两台apache环境
2 、配置两台服务器目录共享
一号机、二号机 相同操作安装NFS:
yum -y install rpcbind 
yum  -y install nfs-utils
 
一号机挂载共享磁盘:
fdisk -l查看磁盘
挂载前格式化磁盘:mkfs.ext4 /dev/xvdb1
设置开机自动挂载:
echo '/dev/xvdb1       /mnt         ext4        defaults        0 0' >> /etc/fstab
挂载:mount -a
配置NFS配置文件:
vim /etc/exports
写入:
/mnt     *(rw,sync,no_root_squash) ##保存退出
 
启动nfs服务:
/etc/init.d/rpcbind start
/etc/init.d/nfs start
加入系统服务:
chkconfig rpcbind on
chkconfig nfs on
 
二号机测试共享并挂载:
showmount -e 10.129.14.52 #查看NFS服务器共享出来的目录
mount -t nfs 10.129.14.52:/www/web /www/web      #挂载NFS服务器上共享出来的目录
自动挂载:
echo '10.25.212.98:/www/web /www/web nfs defaults 0 0'>> /etc/fstab
df -h 查看挂载情况
posted @ 2019-08-29 17:42  hcfinal  阅读(963)  评论(0编辑  收藏  举报