In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you how Nginx Cloud Virtual Machine realizes Load Balancer and static and dynamic separation. I hope it can bring some help to you in practical application. Load Balancer involves many things, but there are not many theories. There are many books on the Internet. Today, we will use the accumulated experience in the industry to make an answer.
Experiment Environment Nginx Cloud Virtual Machine (192.168.13.177) Tomcat1 Server (192.168.13.151) Tomcat2 Server (192.168.13.178) Client Tester 1, Load Balancer 1, Install Tomcat Service on Tomcat1, Tomcat2 [root@tomcat1 ~]# systemctl stop firewall.service ##Close firewall [root@tomcat1 ~]# mkdir /abc[root@tomcat1 ~]# mount.cifs //192.168.100.3/LNMP-C7 www.example.com/tomcat abc/[root@tomcat1 ~]# cd /abc/tomcat/[root@tomcat1 tomcat]# tar zxvf jdk-8u91-linux-x64.tar.gz -C /usr/local/ ##Decompress JDK[root@tomcat1 tomcat]# vim /etc/profile ##Configure environment variables ##Big G last line Add export JAVA_HOME=/usr/local/jdk1.8.0_91export JRE_HOME=${JAVA_HOME}/jreexport CLASSPATH=.:$ {JAVA_HOME}/lib:${JRE_HOME}/libexport PATH=${JAVA_HOME}/bin:$PATH[root@tomcat1 tomcat]# source /etc/profile ##Brush new configuration file [root@tomcat1 tomcat]# tar zxvf apache-tomcat-8.5.16.tar.gz -C /usr/local/ ##Decompress [root@tomcat1 tomcat]# cd /usr/local/[root@tomcat1 local]# mv apache-tomcat-8.5.16/ tomcat[root@tomcat1 local]# ln -s /usr/local/tomcat/bin/www.example.com/usr/local/bin/startup.sh ##Start and close scripts for system recognition [root@tomcat1 local]# ln -s /usr/local/tomcat/bin/shutdown.sh[root@tomcat1 local]# mkdir -p /web/webapp1 ##Create site [root@tomcat1 local]#vim/web/webapp1/index.jsp ##Write jsp web content ##jsp web content JSP test1 page ##Output information [root@tomcat1 local]#vim/usr/local/tomcat/conf/server.xml ##Modify Tomcat configuration file ##Add site information [root@tomcat1 ~]# startup.sh ##Start the service ##Tomcat web page content is accp and other configurations are the same 2. Install Nginx on Nginx server [root@nginx ~]# systemctl stop firewalld.service ##Turn off firewall [root@nginx ~]# setenforce 0[root@nginx ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y ##Install environment essentials [root@nginx ~]# mkdir /abc[root@nginx ~]# mount.cifs www.example.com/abc///192.168.100.3/LNMP-C7 ##mount Password for //192.168.100.3/LNMP-C7: [root@nginx ~]# cd /abc/[root@nginx abc]# tar zxvf nginx-1.12.2.tar.gz-C /usr/local/ ##decompress [root@nginx abc]# useradd -M -s /sbin/nologin nginx ##Create system user [root@nginx abc]# cd /usr/local/nginx-1.12.2/[root@nginx nginx-1.12.2]# ./ configure \ ##Configuration> --prefix=/usr/local/nginx \> --user=nginx \> --group=nginx\> --with-http_stub_status_module \> --with-http_gzip_static_module \> --with-http_flv_module [root@nginx nginx-1.12.2]# make & make install ##Compile and install 3, Modify Nginx configuration file [root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.conf #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream tomcat-server { #Add address pool server 192.168.13.151:8080 weight=1; server 192.168.13.178:8080 weight=1; } server { listen 80;..... Omit location / { root html; index index.html index.htm; proxy_pass http://tomcat-server; #Add proxy, invoke server address pool }[root@nginx nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ ##for system recognition [root@nginx nginx-1.12.2]# nginx ##Enable service 4, use client tester to access nginx proxy server
Second, static separation 1, modify the configuration file on Nginx [root@nginx nginx-1.12.2]# vim /etc/init.d/nginx ##Write a service startup script #!/ bin/bash# chkconfig: - 99 20# description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1esacexit 0[root@nginx nginx-1.12.2]# chmod +x /etc/init.d/nginx [root@nginx nginx-1.12.2]# chkconfig --add nginx[root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx.confserver {... Omit... location ~.*. jsp$ { ##Match jsp page jump proxy server pool proxy_pass http://tomcat-server; proxy_set_header Host $host; } location / { root html/test; ##Modify Site index index.html index.htm; proxy_pass http://tomcat-server; }[root@nginx nginx-1.12.2]# vim /usr/local/nginx/html/index.html ##Write a static web page Static page body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif;} static page
This is a static page.
[root@nginx nginx-1.12.2]# service nginx stop ##Close start service [root@nginx nginx-1.12.2]# service nginx start2, Create jsp dynamic page on Tomcat1, Tomcat2 [root@tomcat1 ~]# mkdir /usr/local/tomcat/webapps/test[root@tomcat1 ~]#vim/usr/local/tomcat/webapps/test/index.jsp ##Start with dynamic page dynamic page1 ##Modify to dynamic page22 on Tomcat2//Visit static http://www.example.com//Visit dynamic http://192.168.13.177/test/index.jspNginx handles static images, Tomcat handles dynamic page1, add images to Tomcat1, Tomcat2 pages [root@tomcat1 ~]#vim/usr/local/tomcat/webapps/test/index.jsp 192.168.13.177/ dynamic page
//Add page image [root@tomcat01 local]#vim/usr/local/tomcat/conf/server.xml #Add the following entry under line 149,[root@tomcat1 test]#shutdown.sh ##Close Restart [root@tomcat1 test]# startup.sh2, modify configuration file on Nginx [root@nginx nginx-1.12.2]# vim /usr/local/nginx/conf/nginx. conflict ~.*\. (gif|jpg|jpeg|png|bmp|swf|css)$ { root html/test; expires 30d;}[root@nginx nginx-1.12.2]# mkdir /usr/local/nginx/html/test[root@nginx nginx-1.12.2]# cp/abc/11.jpg/usr/local/nginx/html/test/#Restart service [root@nginx html]# service nginx restart3, use client test
After reading the above about how Nginx Cloud Virtual Machine realizes Load Balancer and static separation, if you still have anything to know, you can find what you are interested in the industry information or find our professional technical engineers to answer. Technical engineers have more than ten years of experience in the industry.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.