Linux CentOS builds Jdk+mysql+tomcat+nginx load balancing environment

Source: Internet
Author: User
Tags nginx load balancing

This article uses the TOMCAT+NGINX environment, the main role of load balancing, using Tomcat processing JSP daemon, using nginx processing static pages.

Prepare to work (download software version, please baidu download)

Install package drop to:/USR/LOCAL/SRC
Installation Address:/usr/local/software name
1, apache-tomcat-6.0.48
2, mysql-5.5.54
3, nginx-1.6.3
4, cmake-2.8.8
5, pcre-8.40
6, Jdk-8u11-linux-x64
7, openssl-1.1.0d (HTTPS use)

Start installation

Install compile tools and library files, CMAK, MySQL, pcre, Nginx, please refer to "Linux CentOS compiler installation LNMP environment"

JDK Installation

Unzip the JDK to/USR/LOCAL/JDK

TAR-ZXVF jdk-8u11-linux-x64.tar.gz-c/USR/LOCAL/JDK

Adding environment variables

Vi/etc/profile

Added under Export PATH USER LOGNAME MAIL HOSTNAME histsize Histcontrol

Export Java_home=/usr/local/jdkexport path= $JAVA _home/bin: $PATHexport classpath=.: $JAVA _home/lib/dt.jar: $JAVA _ Home/lib/tools.jar:wq #保存

Execute the order to take effect

Source/etc/profile

Enter the following command to detect success

Java-version
Tomcat installation
# Create user Groupadd tomcatuseradd-s/bin/bash-g tomcat tomcat# extract: TAR-ZXVF apache-tomcat-7.0.68.tar.gz-c/usr/local/tomcat# Modify permissions: Chown-r tomcat:tomcat tomcat# start: Sh./bin/startup.sh

Add Tomcat port 8080 to the exception firewall

Firewall-cmd--zone=public--add-port=8080/tcp--permanentfirewall-cmd--reload

Enter in the browser: Http://IP address: 8080
The Tomcat welcome page appears as normal

Enable Tomcat and nginx to coexist for load balancing

New Web site root directory

Mkdir-p/data/www/root

New index.html under/data/www/root

Vi/data/www/root/index.html

Press I into edit mode in the window to enter the following content

<! Doctype html>

New hello.jsp file under/data/www/root

vi/data/www/root/hello.jsp

Press I into edit mode in the window to enter the following

New proxy.conf proxy file

Vi/usr/local/nginx/conf/proxy.conf

Press I into edit mode in the window to enter the following

# cat /usr/local/nginx/confg/proxy.confproxy_ redirect          off;proxy_set_header         Host  $host;p roxy_set_header         x-real-ip  $remote _addr;  #获取真实IP #proxy_set_header        x-forwarded-for    $proxy _add_x_forwarded_for;  #获取代理者的真实ipclient_max_body_size      10m;client_body_buffer_size 128k;proxy_connect_timeout   90;proxy_send_timeout       90;proxy_read_timeout      90;proxy_buffer_ size       4k;proxy_buffers            4 32k;proxy_busy_buffers_size 64k;proxy_temp_file_write_size 64k;:wq      #保存退出 

The edit nginx.conf file is configured as follows

Vi/usr/local/nginx/conf/nginx.conf
# cat /usr/local/nginx/confg/nginx.confuser  www www;    # User-level and user worker_processes  1;pid     /usr/local/nginx/logs/nginx.pid when installing Nginx ; events {use epoll;worker_connections  1024;} http {include       mime.types;default_type  application/ octet-stream;include     /usr/local/nginx/conf/proxy.conf;  # Be sure to point to the proxy file sendfile        on;tcp_nopush       on;keepalive_timeout  65;server {    listen        80;    server_name  localhost;    charset  gb2312;    location / {          root /data/www/ROOT;   #网站根目录 &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;  index  index.html index.htm;    }     location ~ .*.jsp$ {      #匹配以jsp结尾的, Tomcat's web file ends with a JSP              index   index.jsp;             proxy_pass      http ://127.0.0.1:8080;  #主要在这里, set up a proxy     }    location / nginxstatus {            stub_status on;             access_log on;             auth_basic  "Nginxstatus";             auth_basic_user_file /usr/local/nagois/etc/htpasswd.users ;     } &Nbsp;  # redirect server error pages to the static page  /50x.html    error_page   500 502 503 504  / 50x.html;    location = /50x.html {         root   html;    }}}

The configuration is now complete, and the following test begins in the browser
1, enter in the browser: HTTP://IP address (Display nginx welcome page)
2, enter in the browser: HTTP://IP Address: 8080 (Display tomcat welcome page)
3, enter in the browser: HTTP://IP address/hello.jsp (show Hello world! that is successful)


Linux CentOS builds Jdk+mysql+tomcat+nginx load balancing environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.