單節點nginx為兩台apache伺服器提供負載平衡(轉載)

來源:互聯網
上載者:User

標籤:emctl   之間   sed   top   bsp   nbsp   跳轉   number   ber   

單節點nginx為兩台apache伺服器提供負載平衡

需求:本實驗為單節點nginx為兩台apache伺服器提供負載平衡,所有配置為最簡單

1.初始化3台測試server,該關的關了

123456789 [[email protected] ~]# vim /etc/hosts192.168.1.101   ng-master192.168.1.161   web1192.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.配置web1,web2的apache服務

123456 [[email protected] ~]# yum -y install httpd[[email protected] ~]# systemctl start httpd[[email protected] ~]# systemctl enable httpdln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multiuser.target.wants/httpd.service‘[[email protected] ~]# cat /var/www/html/index.htmlhello this lvs-web1

3.通過yum安裝配置nginx節點

12345678910111213141516171819202122232425262728 [[email protected] ~]# vim /etc/yum.repos.d/nginx.repo[nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/7/x86_64/gpgcheck=0enabled=1 [[email protected] ~]# yum clean all[[email protected] ~]# yum -y install nginx[[email protected] ~]# vim /usr/share/nginx/html/index.html<h1>Welcome to ng-master!</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.查看nginx相關日誌

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.通過瀏覽器訪問測試http://192.168.1.101/ 或者 http://myapp1/ 可發現流量在web1和web2之間跳轉

參考:

http://www.linuxdiyf.com/linux/12955.html
http://nginx.org/en/linux_packages.html
http://blog.csdn.net/e421083458/article/details/30086413

單節點nginx為兩台apache伺服器提供負載平衡(轉載)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.