scripts/ff

143 lines
5.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 安装consul
mkdir /data/consul
cd /data/consul
wget https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_amd64.zip
** 注意解压后只有一个consul执行文件
unzip consul_1.18.1_linux_amd64.zip
# 启动consul
nohup /data/consul/consul agent -server -data-dir=/tmp/consul -bootstrap -ui -advertise=172.31.37.68 -client=172.31.37.68 > /dev/null 2>&1 &
# 安装nginx
mkdir /data
mkdir /data/nginx
cd /data/nginx
wget http://nginx.org/download/nginx-1.26.0.tar.gz
tar -zxvf nginx-1.26.0.tar.gz
yum -y install pcre-devel
yum install -y zlib-devel
cd /data/nginx/nginx-1.26.0
./configure --prefix=/data/nginx
安装make
第一次安装make install
日志:/data/nginx/logs
# 通过nginx-upsync-module和nginx_upstream_check_module模块进行编译
mkdir /data/nginx/modules
cd /data/nginx/modules
# 这里是Github的资源不能用wget下载具体是
nginx-upsync-module需要下载release里面的最新版本v2.1.3 【wget https://github.com/weibocom/nginx-upsync-module/archive/refs/tags/v2.1.3.tar.gz】
nginx_upstream_check_module需要下载整个项目的源码主要用到靠近当前版本的补丁使用patch命令进行补丁升级
cd /data/nginx/nginx-1.26.0
patch -p1 < /data/nginx/modules/nginx_upstream_check_module-master/check_1.20.1+.patch
./configure --prefix=/data/nginx --add-module=/data/nginx/modules/nginx_upstream_check_module-master --add-module=/data/nginx/modules/nginx-upsync-module-2.1.3
make
make install
# 下载upsync模块并且将其解压
wget -c https://github.com/weibocom/nginx-upsync-module/archive/master.zip
unzip nginx-upsync-module-master.zip
# 下载nginx
wget -c http://nginx.org/download/nginx-1.9.9.tar.gz
# 解压到当前目录
tar -zxvf nginx-1.9.9.tar.gz
# 配置一个nginx的用户以及用户组-s /sbin/nologin nginx代表该用户是无法登录到主机的
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
# 这两个文件夹会在编译nginx时指定
mkdir -p /var/tmp/nginx/client/
mkdir -p /usr/local/nginx
# 进入到nginx的解压后文件夹的目录下
cd nginx-1.9.9
# 编译 nginx --prefix 代表nginx安装的目录。其中指定了用户和用户组以及上面创建的文件夹并且添加了upsync模块由于upsync解压在nginx同级目录下所以这里使用..来指定到它
./configure --prefix=/data/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --add-module=/data/nginx/modules/nginx-upsync-module-2.1.3
make && make install
## 进入到刚刚nginx安装的目录也就是/data/nginx目录中进入conf目录中编辑conf目录的文件内容
upstream myserver {
server 127.0.0.1:11111;# 这个固定的,不用理
# springbootserver key的值upsync_timeout 超时时间3秒upsync_interval 间隔时间 upsync_type 类型consulstrong_dependency 增强依赖
upsync 192.168.254.134:8500/v1/kv/upstreams/springbootserver upsync_timeout=3000ms upsync_interval=500ms upsync_type=consul strong_dependency=off;
# 将拉取下来的配置文件放在以下配置的目录中
upsync_dump_path /usr/local/nginx-1.9.9/conf/upsync_dump.conf;
}
# 将server中的location指定为刚刚创建的upstream(上游服务器)
location / {
proxy_pass http://myserver;
index index.html index.htm;
}
# /data/nginx/conf/nginx.conf部分片段
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream mixtest {
# 这里是consul的leader节点的HTTP端点
upsync 172.31.37.68:8500/v1/kv/upstreams/mixtest upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off;
# consul访问不了的时候的备用配置
upsync_dump_path /data/nginx/app.conf;
# 这里是为了兼容Nginx的语法检查
include /data/nginx/app.conf;
# 下面三个配置是健康检查的配置
check interval=1000 rise=2 fall=2 timeout=3000 type=http default_down=false;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://app;
}
# 健康检查 - 查看负载均衡的列表
location /upstream_list {
upstream_show;
}
# 健康检查 - 查看负载均衡的状态
location /upstream_status {
check_status;
access_log off;
}
}
}
# /data/nginx/app.conf
server 127.0.0.1:9000 weight=1 fail_timeout=10 max_fails=3;
server 127.0.0.1:9001 weight=1 fail_timeout=10 max_fails=3;
# 进入到sbin目录下启动nginx
./nginx
nohup ./app -p 10300 >/dev/null 2>&1 &
nohup ./app -p 10301 >/dev/null 2>&1 &
10301
curl -X PUT -d '{"weight":1, "max_fails":2, "fail_timeout":10}' http://172.31.37.68:8500/v1/kv/upstreams/app/127.0.0.1:10300
curl -X PUT -d '{"weight":1, "max_fails":2, "fail_timeout":10}' http://172.31.37.68:8500/v1/kv/upstreams/app/127.0.0.1:10301