金沙国际app-金沙国际手机app下载

金沙国际app包括教育和科研机构建设、学科共建等,欢迎来到金沙国际手机app下载这里有多种线上娱乐游戏,金沙国际app获颁“创意中国榜”中国文化创意产业领军企业,是一家专业从事网络休闲平台游戏开发、运营的服务性企业。

当前位置:金沙国际app > 网络世界 > Nginx+Tomcat金沙国际app+Https 服务器负载均衡配置

Nginx+Tomcat金沙国际app+Https 服务器负载均衡配置

文章作者:网络世界 上传时间:2019-11-01

1、功能描述

由于需要,得搭建个Nginx+Tomcat+Https的负载均衡服务器,搜了搜网上的发现总是有错,现在整理了些有用的,备忘。

  1. 安装支持包,从软件源下载自定义的NGINX包,创建NGINX用户和用户组。

环境:CentOS6.5、JDK1.8、Tomcat8、Nginx1.10.1
准备材料:
1.JDK1.8安装包jdk-8u102-linux-x64.tar.gz

  2. 安装并初始化NGINX配置。

2.Tomcat8安装包apache-tomcat-8.0.37.tar.gz

  3. 运行NGINX并检测运行状态。

3.Nginx1.10安装包nginx-1.10.1.tar.gz

2、实现

1、JDK安装配置
解压并安装到/usr/local/jdk

  源码如下:

[root@localhost ~]# tar zxvf jdk-8u102-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.8.0_102 /usr/local/jdk
#!/bin/bash
# eastmoney public tools
# version: v1.0.1
# create by XuHoo, 2016-9-28
#

function environment() {
    if [[ "$USER" != "root" ]]; then
        echo "Current user is not root"
        return 1
    fi
    yum -y install wget curl pcre pcre-devel zlib zlib-devel gcc gcc-c++ &> /tmp/nginx_install.log
    # getUrl: Input download source address
    # getUrl='http://172.16.1.1nginx-1.8.1.tar.gz'
    wget -P /tmp/ $getUrl/nginx.tar.gz
    grep "nginx" /etc/passwd > /dev/null
    if [[ $? -ne 0 ]]; then  # check user and group
        groupadd nginx
        useradd -M -g nginx -s /sbin/nologin nginx
    fi
    cd /tmp; tar -zxf nginx.tar.gz; cd nginx
    return 0
}; environment; [ $? -ne 0 ] && exit 1

function install() {
    # Compile before installation configuration
    ./configure --prefix=/usr/local/nginx 
                --user=nginx --group=nginx 
                --with-http_stub_status_module 
                &> /tmp/nginx_install.log
    if [[ $? -ne 0 ]]; then
        return 1
    else
        # make && make install
        make &> /tmp/nginx_install.log
        make install &> /tmp/nginx_install.log
        if [[ $? -ne 0 ]]; then
            return 1
        fi
        return 0
    fi
}; install; [ $? -ne 0 ] && exit 1

function optimize() {
    ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ > /dev/null
    cp -f /tmp/nginx_control.sh /etc/init.d/nginx
    cp -f /tmp/nginx.conf /usr/local/nginx/conf/nginx.conf
    # The number of CPU cores current server,
    # Amend the "worker_processes" field to the value of the processor
    processor=`cat /proc/cpuinfo | grep "processor" | wc -l`
    sed -i "s/^w.*;$/worker_processes  ${processor};/g" /usr/local/nginx/conf/nginx.conf
    chmod +x /etc/init.d/nginx
    chkconfig --add nginx
    retval=`chkconfig --level 3 nginx on`  # Configure nginx open start service
    return $retval
}; optimize; [ $? -ne 0 ] && exit 1

function run() {
    # Test nginx.conf file syntax is correct
    /etc/init.d/nginx test &> /tmp/nginx_run.log
    if [[ $? -ne 0 ]]; then
        retval=$?
    else  # Start nginx server
        /etc/init.d/nginx start &> /tmp/nginx_run.log
        if [[ $? -ne 0 ]]; then
            retval=$?
        fi
    fi
    return 0
}; run; [ $? -ne 0 ] && exit 1

function check() {
    # Modified index.html page content
    content=$"deployment on $(date "+%Y-%m-%d %H:%M:%S")"
    echo $content > /usr/local/nginx/html/index.html
    # View the index.html, and the output of the modified index.html page
    /etc/init.d/nginx status
    echo -n "Index.html: "; curl http://localhost
}; check

配置JDK环境变量

更多Nginx负载均衡配置相关教程见以下内容

[root@localhost ~]# vi /etc/profile

Nginx负载均衡配置说明 http://www.linuxidc.com/Linux/2016-03/129424.htm

在底部加入以下内容

Linux下Nginx+Tomcat负载均衡和动静分离配置要点  http://www.linuxidc.com/Linux/2016-01/127255.htm

JAVA_HOME=/usr/local/jdk
JRE_HOME=$JAVA_HOME/jre
CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export JAVA_HOME JRE_HOME PATH CLASSPATH

Docker+Nginx+Tomcat7配置简单的负载均衡  http://www.linuxidc.com/Linux/2015-12/125907.htm

应用环境变量

Nginx负载均衡(主备)+Keepalived  http://www.linuxidc.com/Linux/2015-12/126865.htm

[root@localhost ~]# source /etc/profile

使用Nginx作为负载均衡器 http://www.linuxidc.com/Linux/2015-12/125789.htm

检测是否成功,显示版本说明成功

使用Nginx简单实现负载均衡  http://www.linuxidc.com/Linux/2016-08/134443.htm

[root@localhost ~]# java -version

Nginx负载均衡与高可用的实现 http://www.linuxidc.com/Linux/2016-04/130350.htm

2、Tomcat安装配置
解压并安装到/usr/local/tomcat

Nginx 的详细介绍请点这里
Nginx 的下载地址请点这里

[root@localhost ~]# tar zxvf apache-tomcat-8.0.37.tar.gz
[root@localhost ~]# mv apache-tomcat-8.0.37 /usr/local/tomcat

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-09/135619.htm

默认tomcat是root身份运行的,这样不安全,这里设置普通用户运行

金沙国际app 1

[root@localhost ~]# groupadd tomcat
[root@localhost ~]# useradd -g tomcat tomcat
[root@localhost ~]# passwd tomcat
[root@localhost ~]# chown tomcat.tomcat -R /usr/local/tomcat

运行tomcat

[root@localhost ~]# su - tomcat /usr/local/tomcat/bin/startup.sh

设置开机启动

[root@localhost ~]# echo "su - tomcat /usr/local/tomcat/bin/startup.sh" >> /etc/rc.local

3、Nginx安装配置
配置Nginx用户

[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -g nginx -s /sbin/nologin nginx

安装依赖包

本文由金沙国际app发布于网络世界,转载请注明出处:Nginx+Tomcat金沙国际app+Https 服务器负载均衡配置

关键词: