Single-node Nginx provides load balancing for two Apache servers
Requirements: This experiment provides load balancing for two Apache servers for single-node Nginx, all configured as the simplest
1. Initialize 3 test server, the off
123456789 |
[[email protected] ~] # vim/etc/hosts Code class= "Bash plain" >192.168.1.101 ng-master 192.168.1.161 WEB1 192.168.1.162 web2 [ [email protected] ~] # yum clean all [[email protected] ~] # systemctl stop Firewalld.service [[email protected] ~] # systemctl disable Firewalld.service [[email protected] ~] # sed-i "s/selinux=enforcing/selinux=disabled/g"/etc/selinux/config |
2. Configure Apache Services for WEB1,WEB2
123456 |
[[email protected] ~] # yum -y install httpd [[email protected] ~] # systemctl start httpd [[email protected] ~] # systemctl enable httpd ln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multiuser.target.wants/httpd.service‘ [[email protected] ~] # cat /var/www/html/index.html hello this lvs-web1 |
3. Configuring Nginx nodes with Yum installation
12345678910111213141516171819202122232425262728 |
[[email protected] ~]
# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http:
//nginx
.org
/packages/centos/7/x86_64/
gpgcheck=0
enabled=1
[[email protected] ~]
# yum clean all
[[email protected] ~]
# yum -y install nginx
[[email protected] ~]
# vim /usr/share/nginx/html/index.html
/h1
>
[[email protected] ~]
# cd /etc/nginx/conf.d/
[[email protected] conf.d]
# mv default.conf default.conf.1
[[email protected] ~]
# vim /etc/nginx/conf.d/web.conf
upstream myapp1 {
server web1;
server web2;
}
server {
listen 80;
location / {
proxy_pass http:
//myapp1
;
}
}
[[email protected] ~]
# systemctl restart nginx.service
|
4. View Nginx related logs
123 |
[[email protected] conf.d] # tail -f /var/log/messages [[email protected] conf.d] # tail -f /var/log/nginx/access.log [[email protected] conf.d] # tail -f /var/log/nginx/error.log |
5. Access test http://192.168.1.101/via browser or http://myapp1/to discover traffic between Web1 and WEB2 jumps
Reference:
Http://www.linuxdiyf.com/linux/12955.html
Http://nginx.org/en/linux_packages.html
http://blog.csdn.net/e421083458/article/details/30086413
Single-node Nginx provides load balancing for two Apache servers (reprint)