標籤: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伺服器提供負載平衡(轉載)