博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
keepalived+nginx+tomcat
阅读量:5812 次
发布时间:2019-06-18

本文共 13758 字,大约阅读时间需要 45 分钟。

//软件连接百度云

在80.100虚拟机下

systemctl stop firewalld      //关闭防火墙setenforce 0         //关闭监控
yum install lrz* -y //可以直接把软件包拖到xshell当前目录里面的命令
tar xf nginx-1.13.9.tar.gz -C /opt/      //解压压缩包到/opt/下cd /opt/ls

keepalived+nginx+tomcat

cd /opt/nginx-1.13.9/    //进入文件

keepalived+nginx+tomcat

useradd -s /sbin/nologin -M nginx    //创建一个无法登陆系统的用户
yum install -y \        //安装编译工具及插件 gcc \ gcc-c++ \ make \ openssl-devel \ zlib-devel \ pcre-devel
./configure \               //个性化配置--user=nginx \--group=nginx \--with-file-aio \--with-http_flv_module \--with-http_stub_status_module \--with-http_ssl_module \--with-http_gzip_static_module \--with-http_realip_module
make && make install     //编译且安装
cd     //到root根目录下
vi /usr/local/nginx/conf/nginx.conf    user nginx nginx;    worker_processes  1;    #error_log  logs/error.log;    #error_log  logs/error.log  notice;    error_log  logs/error.log  info;    pid        logs/nginx.pid;    events {            worker_connections  1024;    }    http {            include       mime.types;            default_type  application/octet-stream;            log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                                                '$status $body_bytes_sent "$http_referer" '                                                '"$http_user_agent" "$http_x_forwarded_for"';            access_log  logs/access.log  main;                    add_header X-Server $hostname;                    server_names_hash_bucket_size 128;                    server_name_in_redirect off;            sendfile        on;            tcp_nopush     on;            tcp_nodelay on;            #keepalive_timeout  0;            keepalive_timeout  60;                    client_header_buffer_size 32k;                    large_client_header_buffers 4 128k;                    client_max_body_size 512m;                    open_file_cache max=65535 inactive=20s;                    open_file_cache_valid 30s;                    open_file_cache_min_uses 1;            gzip  on;                    gzip_static on;                    gzip_http_version 1.1;                    gzip_comp_level 2;                    gzip_min_length 1024;                    gzip_vary on;                    gzip_types text/plain text/javascript application/x-javascript text/css text/xml application/xml application/xml+rss;    server_tokens off;                    fastcgi_connect_timeout 300;                    fastcgi_send_timeout 300;                    fastcgi_read_timeout 300;                    fastcgi_buffer_size 512k;                    fastcgi_buffers 6 512k;                    fastcgi_busy_buffers_size 512k;                    fastcgi_temp_file_write_size 512k;                    fastcgi_intercept_errors on;                    client_body_buffer_size 128k;                    proxy_connect_timeout 600;                    proxy_read_timeout 600;                    proxy_send_timeout 600;                    proxy_buffer_size 32k;                    proxy_buffers 4 32k;                    proxy_busy_buffers_size 64k;                    proxy_temp_file_write_size 2m;                    proxy_ignore_client_abort on;                    proxy_cache_path /usr/local/nginx/cache_temp levels=2:2    keys_zone=cache_temp:128m inactive=30m max_size=2g;                    proxy_cache_valid 200 302 10m;                    include /usr/local/nginx/conf/conf.d/*.conf;            server {                    listen       80;                    server_name  localhost;                    charset UTF-8;                    #access_log  logs/host.access.log  main;                    location / {                            root   html;                            index  index.html index.htm;                    }                    #error_page  404              /404.html;                        # redirect server error pages to the static page /50x.html                        #                    error_page   500 502 503 504  /50x.html;                        location = /50x.html {                            root   html;                        }                            # proxy the PHP scripts to Apache listening on 127.0.0.1:80                            #                    #location ~ \.php$ {                        #    proxy_pass   http://127.0.0.1;        #}                        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000                    #        #location ~ \.php$ {                    #    root           html;                    #    fastcgi_pass   127.0.0.1:9000;                    #    fastcgi_index  index.php;                        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;                            #    include        fastcgi_params;        #}                    # deny access to .htaccess files, if Apache's document root                    # concurs with nginx's one                    #        #location ~ /\.ht {                    #    deny  all;        #}    }            # another virtual host using mix of IP-, name-, and port-based configuration            #    #server {            #    listen       8000;            #    listen       somename:8080;                #    server_name  somename  alias  another.alias;                    #    location / {                    #        root   html;                    #        index  index.html index.htm;                    #    }    #}            # HTTPS server            #    #server {            #    listen       443 ssl;            #    server_name  localhost;                #    ssl_certificate      cert.pem;                #    ssl_certificate_key  cert.key;                #    ssl_session_cache    shared:SSL:1m;                #    ssl_session_timeout  5m;                #    ssl_ciphers  HIGH:!aNULL:!MD5;                #    ssl_prefer_server_ciphers  on;                #    location / {                #        root   html;                #        index  index.html index.htm;                #    }    #}    }    :wq   //保存退出
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/       //软链接
nginx -t    //检查nginx有没有错误

keepalived+nginx+tomcat

cd /usr/local/nginx/conf/ mkdir conf.dcd conf.d/
vi lvs01.conf          //新建子配置文件    server {                    listen 80;                    server_name lvs01 192.168.80.100;       //服务器名称与IP地址                    index index.html index.jsp;                    root /usr/local/nginx/html;                    access_log /usr/local/nginx/logs/tomcat.aa.com_access.log main;                    location ~ .*\.jsp$ {                    index index.jsp;                    proxy_set_header HOST $host;                    proxy_set_header X-Real-IP $remote_addr;                    proxy_set_header Client-IP $remote_addr;                    proxy_set_header X-For $proxy_add_x_forwarded_for;                    proxy_pass http://center_pool;                    }                    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {                    expires 30d;            proxy_pass http://center_pool;                    }                    location ~ .*\.(js|css)?$ {                    expires 1h;            proxy_pass http://center_pool;                    }    }    :wq     //保存退出
vi pool.conf       //创建服务器池    #添加以下内容    upstream center_pool {               //默认轮询                    server 192.168.80.102:8080;                    server 192.168.80.103:8080;    }    :wq    //保存退出
nginx -t

keepalived+nginx+tomcat

vi /etc/init.d/nginx    #!/bin/bash        # chkconfig: 35 99 20            # description: Nginx Service Control Script    PROG="/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 1    esac    exit 0    :wq   //保存退出
chmod +x /etc/init.d/nginx        //增加执行权限chkconfig --add nginx             //加入系统管理服务service nginx start               //启动nginx服务 netstat -anpt | grep 80         //查看80端口有哪些服务在开启状态

keepalived+nginx+tomcat
在浏览器地址栏中输入192.168.80.100

keepalived+nginx+tomcat
在浏览器地址栏中输入192.168.80.100/index.jsp

keepalived+nginx+tomcat

在浏览器地址栏中输入192.168.80.100/index.jsp
keepalived+nginx+tomcat
keepalived+nginx+tomcat

scp /usr/local/nginx/conf/nginx.conf root@192.168.80.101:/usr/local/nginx/conf/nginx.conf      //把本机上的nginx.conf传送到80.101虚拟机上yes自己设置的root密码scp * root@192.168.80.101:/usr/local/nginx/conf/conf.d/ //传送到80.101虚拟机上自己设置的root密码

keepalived+nginx+tomcat

scp /etc/init.d/nginx root@192.168.80.101:/etc/init.d自己设置的root密码
cd /etc/yum.repos.d/      //进入目录cp back/* ./         //把back里面所有内容提取到上一个目录下ifconfig ens34 down        //关闭网卡ifconfig ens34 up        //开启网卡yum install -y epel-release       //安装yum install keepalived -y      //安装cd      //到root根目录下
vi /etc/keepalived/keepalived.conf    #把里面内容都删了添加以下内容    ! Configuration File for keepalived    global_defs {                    route_id NGINX-01         }    vrrp_script nginx {                    script "/opt/nginx.sh"                    interval 2                    weight -10    }    vrrp_instance VI_1 {            state MASTER            interface ens32            virtual_router_id 51            priority 150            advert_int 1            authentication {                    auth_type PASS                    auth_pass 1111            }            track_script {                    nginx                    }                virtual_ipaddress {                    192.168.80.188            }    }    :wq    //保存退出
scp /etc/keepalived/keepalived.conf root@192.168.80.101:/etc/keepalived/自己设置root的密码cd /opt/
vi nginx.sh    #!/bin/bash    #Filename:nginx.sh    A=$(ps -ef | grep keepalived | grep -v grep | wc -l)    if [ $A -gt 0 ]; then                    /etc/init.d/nginx start    else                    /etc/init.d/nginx stop    fi    :wq    //保存退出
chmod +x nginx.sh      //给这个文件权限./nginx.sh        //执行这个脚本systemctl start keepalived     //重启keepalived服务systemctl stop firewalld         //关闭firewalld服务chkconfig --add nginx           service nginx start            //重启nginx服务./nginx.sh        //在执行脚本

在浏览器地址栏中输入192.168.80.188

keepalived+nginx+tomcat
在浏览器地址栏中输入192.168.80.188/index.jsp

keepalived+nginx+tomcat
keepalived+nginx+tomcat

在80.101虚拟机下

systemctl stop firewalld      //关闭防火墙setenforce 0           //关闭监控
yum install lrz* -y //可以直接把软件包拖到xshell当前目录里面的命令
yum install -y \        //安装编译工具及插件 gcc \ gcc-c++ \ make \ openssl-devel \ zlib-devel \ pcre-devel
./configure \               //个性化配置--user=nginx \--group=nginx \--with-file-aio \--with-http_flv_module \--with-http_stub_status_module \--with-http_ssl_module \--with-http_gzip_static_module \--with-http_realip_module
make && make install        //编译且安装
cd /usr/local/nginx/conf/       //进入文件夹
mkdir conf.d       //创建这个文件
vi conf.d/lvs01.conf把80.100改成80.101

keepalived+nginx+tomcat

chkconfig --add nginx
useradd -s /sbin/nologin -M nginx       //创建一个无法登陆系统的用户
service nginx start         //重启nginx

在浏览器地址栏中输入192.168.80.101/index.jsp

keepalived+nginx+tomcat

keepalived+nginx+tomcat

cd /etc/yum.repos.d/       //进入这个目录cp back/* ./                        //把back这个目录里面的内容转到上一个目录下
ifconfig ens34 down       //关闭网卡ifconfig ens34 up        //开启网卡
yum install -y epel-release      //安装
yum install keepalived -y     //安装
vi /etc/keepalived/keepalived.conf      //进入文件

keepalived+nginx+tomcat

cd /opt/     //到/opt/下
vi nginx.sh    #!/bin/bash    #Filename:nginx.sh    A=$(ip addr | grep 192.168.80.188/32 | grep -v grep | wc -l)    if [ $A -gt 0 ]; then                    /etc/init.d/nginx start    else                    /etc/init.d/nginx stop    fi    :wq     //保存退出
chmod +x nginx.sh     //给这个脚本执行权限
./nginx.sh     //启动这个脚本

keepalived+nginx+tomcat

systemctl start keepalived     //重启服务

在80.102虚拟机下

systemctl stop firewalld     //关闭防火墙setenforce 0       //关闭监控
yum install lrz* -y //可以直接把软件包拖到xshell当前目录里面的命令
tar xf apache-tomcat-8.5.23-embed.tar.gz //压缩apache-tomcat-8.5.23-embed.tar.gz到当前目录上tar xf jdk-8u144-linux-x64.tar.gz //压缩jdk-8u144-linux-x64.tar.gz到当前目录上

keepalived+nginx+tomcat

cp -rv jdk1.8.0_144/ /usr/local/java //把jdk1.8.0_144拷贝到 /usr/local/java 目录下
vi /etc/profile //在文件末尾新增export JAVA_HOME=/usr/local/javaexport JRE_HOME=/usr/local/java/jreexport PATH=$PATH:/usr/local/java/binexport CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib

keepalived+nginx+tomcat

source /etc/profile
java -version  //查看版本显示下面内容java version "1.8.0_144"

……

……
--------------以上是搭建JAVA环境---------

cp -r apache-tomcat-8.5.23 /usr/local/tomcat8 //把apache-tomcat-8.5.23拷贝到/usr/local/tomcat8
ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup //把/usr/local/tomcat8/bin/startup.sh软链接到 /usr/bin/tomcatup
ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown //把/usr/local/tomcat8/bin/shutdown.sh软链接到/usr/bin/tomcatdown
vi /usr/local/tomcat8/webapps/ROOT/index.jsp在第一行加server aatomcatupnetstat -anpt | grep 8080 //查看当前8080端口有哪些程序在运行

在80.103虚拟机下

systemctl stop firewalld     //关闭防火墙setenforce 0                //关闭监控
yum install lrz* -y //可以直接把软件包拖到xshell当前目录里面的命令
tar xf apache-tomcat-8.5.23-embed.tar.gz //压缩apache-tomcat-8.5.23-embed.tar.gz到当前目录上tar xf jdk-8u144-linux-x64.tar.gz //压缩jdk-8u144-linux-x64.tar.gz到当前目录上

keepalived+nginx+tomcat

cp -rv jdk1.8.0_144/ /usr/local/java //把jdk1.8.0_144拷贝到 /usr/local/java 目录下
vi /etc/profile //在文件末尾新增export JAVA_HOME=/usr/local/javaexport JRE_HOME=/usr/local/java/jreexport PATH=$PATH:/usr/local/java/binexport CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib

keepalived+nginx+tomcat

source /etc/profile
java -version  //查看版本显示下面内容java version "1.8.0_144"

……

……
--------------以上是搭建JAVA环境---------

cp -r apache-tomcat-8.5.23 /usr/local/tomcat8 //把apache-tomcat-8.5.23拷贝到/usr/local/tomcat8
ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup //把/usr/local/tomcat8/bin/startup.sh软链接到 /usr/bin/tomcatup
ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown //把/usr/local/tomcat8/bin/shutdown.sh软链接到/usr/bin/tomcatdown
vi /usr/local/tomcat8/webapps/ROOT/index.jsp在第一行加server bbtomcatupnetstat -anpt | grep 8080 //查看当前8080端口有哪些程序在运行

转载于:https://blog.51cto.com/14158288/2340296

你可能感兴趣的文章
nginx的lua api
查看>>
考研太苦逼没坚持下来!看苑老师视频有点上头
查看>>
HCNA——RIP的路由汇总
查看>>
zabbix监控php状态(四)
查看>>
定时任务的创建
查看>>
实战Django:小型CMS Part2
查看>>
原创]windows server 2012 AD架构试验系列 – 16更改DC计算机名
查看>>
统治世界的十大算法
查看>>
linux svn安装和配置
查看>>
SSH中调用另一action的方法(chain,redirect)
查看>>
数据库基础
查看>>
表格排序
查看>>
关于Android四大组件的学习总结
查看>>
java只能的round,ceil,floor方法的使用
查看>>
由于无法创建应用程序域,因此未能执行请求。错误: 0x80070002 系统找不到指定的文件...
查看>>
新开的博客,为自己祝贺一下
查看>>
puppet任务计划
查看>>
【CQOI2011】放棋子
查看>>
采用JXL包进行EXCEL数据写入操作
查看>>
一周总结
查看>>