chookie和session

  • 你们公司的会话保持怎么做的?

    1、开发做的:记录用户登陆的状态,将用户登陆状态保存到,redis服务器中,nfs,mysql。

    ​ 记录用户的登陆状态。

    ​ 通过登陆用户对应的userid和cookie结合,记录用户的状态;如果是保存在本地,那么在其它用户使用该机器的时候去更改cookie的userid就能登陆其它用户的登陆状态,这样很不安全。

    ​ 这样就引入了session。

    2、运维:因为开发没有写会话保持功能,我们公司使用的是nginx的upstream模块的ip_hash调度算法。

  • 什么是session

    session保存在服务端

  • 什么是cookie?

    保存在客户端

源码安装nginx

# 1、下载源码包
[root@lb01 ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz # 2、解压
[root@lb01 ~]# tar -xf nginx-1.14.2.tar.gz # 3、查看yum安装时所需要的模块
[root@lb01 ~/nginx-1.14.2]# nginx -V
--with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' # 4、安装依耐
[root@lb01 ~/nginx-1.14.2]# yum -y install openssl-devel # 5、生成
[root@lb01 ~/nginx-1.14.2]# ./configure --prefix=/app/nginx-1.14.2 --user=www --group=www --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' # 6、编译安装
[root@lb01 ~/nginx-1.14.2]# make && make install # 7、创建软链接
[root@lb01 ~]# ln -s /app/nginx-1.14.2/ /app/nginx # 8、添加环境变量并生效
[root@lb01 ~]# vi /etc/profile.d/nginx.sh
export PATH="/app/nginx/sbin:$PATH" [root@lb01 ~]# source /etc/profile # 9、编辑配置文件
[root@lb01 /app/nginx/conf]# vi nginx.conf
...
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; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65;
# 10、放网站配置文件的地方
include conf.d/*.conf;
} ## 11、创建一个配置文件的目录。
[root@lb01 /app/nginx/conf]# mkdir conf.d # 12、配置一个负载均衡
[root@lb01 /app/nginx/conf/conf.d]# vi upstream.conf
upstream phpadmin {
server 172.16.1.7;
server 172.16.1.8;
} server {
listen 80;
server_name php.gong.com;
location / {
proxy_pass http://phpadmin;
include proxy_params;
}
} # ----------------------------#
[root@lb01 /app/nginx/conf]# vi proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504; proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60; proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k; # 11、启动nginx;访问测试,目前是1.14.2的版本

版本升级

在不影响用户体验的情况下把nginx的版本升级到nginx-1.16.1的版本,并添加nginx负载均衡的健康检查模块。

# 1、下载1.16.1版本的额包
[root@lb01 ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz # 2、下载补丁包
[root@lb01 ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip # 3、解压nginx
[root@lb01 ~]# tar -xf nginx-1.16.1.tar.gz # 4、解压master扩展包
[root@lb01 ~]# unzip master.zip # 5、安装打补丁的命令
[root@lb01 ~]# yum -y install patch # 6、打补丁
[root@lb01 ~/nginx-1.16.1]# patch -p1 < ../nginx_upstream_check_module-master/check_1.16.1+.patch # 7、生成,指定安装模块
[root@lb01 ~/nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --user=www --group=www --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/root/nginx_upstream_check_module-master # 8、编译安装
[root@lb01 ~/nginx-1.16.1]# make && make install # 9、安装好的目录下生成的文件
[root@lb01 /app]# ll
total 0
lrwxrwxrwx 1 root root 18 May 28 22:02 nginx -> /app/nginx-1.14.2/
drwxr-xr-x 11 root root 151 May 28 22:10 nginx-1.14.2
drwxr-xr-x 6 root root 54 May 28 22:31 nginx-1.16.1 # 10、复制必要的文件
## 主配置文件
[root@lb01 /app]# \cp nginx-1.14.2/conf/nginx.conf nginx-1.16.1/conf/nginx.conf
## 添加的配置文件
[root@lb01 /app]# \cp nginx-1.14.2/conf/conf.d/upstream.conf nginx-1.16.1/conf/conf.d/upstream.conf
## 配置文件里面指定的优化参数
[root@lb01 /app]# \cp nginx-1.14.2/conf/proxy_params nginx-1.16.1/conf/proxy_params
## 复制pid
[root@lb01 /app]# \cp nginx-1.14.2/logs/nginx.pid nginx-1.16.1/logs/ # 11、创建新的链接文件
[root@lb01 /app]# rm -fr nginx && ln -s /app/nginx-1.16.1/ nginx # 12、秒级重启nginx;现在使用nginx的命令走的是/app/nginx-1.16.1/sbin/下的nginx;但是stop结束的是原来版本下的pid文件,从老版本复制过来的,所以实现了对原来版本的进程结束;通过&&在瞬间进行nginx新版本的启动,添加新的进程和pid
[root@lb01 /app]# nginx -s stop && nginx

访问测试的脚本

[root@db01 ~]# cat test.sh
#!/bin/bash
while true;do
status=$(curl -I -m 10 -o /dev/null -s -w %{http_code} php.gong.com)
if [ $status -eq 200 ];then
echo "$(date +%F-%T)_访问成功"
else
echo "$(date +%F-%T)_访问失败"
fi
sleep 2
done

健康检查的配置

[root@lb01 /app]# vi /app/nginx/conf/conf.d/upstream.conf
upstream phpadmin {
server 172.16.1.7;
server 172.16.1.8;
check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
#interval 检测间隔时间,单位为毫秒
#rise 表示请求2次正常,标记此后端的状态为up
#fall 表示请求3次失败,标记此后端的状态为down
#type 类型为tcp
#timeout 超时时间,单位为毫秒
} server {
listen 80;
server_name php.gong.com;
location / {
proxy_pass http://phpadmin;
include proxy_params;
}
location /uc {
check_status;
}
}

nginx版本无缝升级与回滚的更多相关文章

  1. 022.掌握Pod-Pod升级和回滚

    一 deploymentPod升级和回滚 1.1 deployment升级 若Pod是通过Deployment创建的,可以在运行时修改Deployment的Pod定义(spec.template)或镜 ...

  2. Hadoop HDFS概念学习系列之HDFS升级和回滚机制(十二)

    不多说,直接上干货! HDFS升级和回滚机制 作为一个大型的分布式系统,Hadoop内部实现了一套升级机制,当在一个集群上升级Hadoop时,像其他的软件升级一样,可能会有新的bug或一些会影响现有应 ...

  3. Java项目多版本部署及快速回滚(含完整命令)

    1. 场景描述 java项目linux环境下快速部署,以前介绍过,今天主要结合linux的软连接,实现版本的快速切换(回滚),包含完整的start.sh与stop.sh,只需修改包名和路径即可运行,有 ...

  4. 原创|1分钟搞定 Nginx 版本的平滑升级与回滚

    Nginx无论是对于运维.开发.还是测试来说,都是日常工作需要掌握的一个知识点,之前也写过不少关于Nginx相关的文章: Nginx服务介绍与安装 Nginx服务配置文件介绍 Nginx配置虚拟主机 ...

  5. kubernetes Pod的升级与回滚

    一:Deployment的升级 1.通过kubectl set image命令为Deployment设置新的镜像名称kubectl set image deployment/nginx-deploym ...

  6. Docker & Kubenetes 系列四:集群,扩容,升级,回滚

    本篇将会讲解应用部署到Kubenetes集群,集群副本集查看,集群自愈能力演示,集群扩容,滚动升级,以及回滚. 本篇是Docker&Kubenetes系列的第四篇,在前面的篇幅中,我们向Kub ...

  7. 9.1 k8s pod版本更新流程及命令行实现升级与回滚

    1.创建 Deployment root@k8-deploy:~/k8s-yaml/controllers/deployments# vim nginx-deployment.yaml apiVers ...

  8. Kubernetes:Pod 升级、回滚

    本篇主要讨论如何实现滚动更新和回滚,任意更换版本并且回滚以前的版本(版本更新),而下一章会讨论到 Pod 缩放,根据机器资源自动拓展和收缩应用(自动扩容实例). 本文为作者的 Kubernetes 系 ...

  9. kubernetes deployment升级和回滚

    a.创建deployment pod kubectl run mynginx --image=docker.io/nginx: --record 准备svc文件 apiVersion: v1 kind ...

随机推荐

  1. 9. VUE 常用正则表达式

    1. 判断输入是否是数字 var numReg = /^[0-9]+$/ var numRe = new RegExp(numReg) if (!numRe.test(number)) { this. ...

  2. 在Bootstrap开发框架基础上增加WebApi+Vue&Element的前端

    基于Metronic的Bootstrap开发框架是我们稍早一点的框架产品,界面部分采用较新的Bootstrap技术,框架后台数据库支持Oracle.SqlServer.MySql.PostgreSQL ...

  3. JDK8新特性(一) Lambda表达式及相关特性

    函数式接口 函数式接口是1.8中的新特性,他不属于新语法,更像是一种规范 面向对象接口复习 在这里先回顾一下面向对象的接口,创建接口的关键字为interface,这里创建一个日志接口: public ...

  4. 866. Prime Palindrome

    Find the smallest prime palindrome greater than or equal to N. Recall that a number is prime if it's ...

  5. MSSQL数据库清理Log 压缩数据库日志文件

    dump transaction 数据库名 with no_log go dbcc shrinkdatabase(数据库名)

  6. RF-日期时间拼接(20191024_195355)

    *** Test Cases *** testGetTime @{time}= Get Time year month day hour min sec ${sDate}= Catenate SEPA ...

  7. 【Java】Java中的四种对象引用

    从JDK1.2开始,Java中的引用类型分为四种,分别是: 1.强引用(StrongReference) 这种引用是平时开发中最常用的,例如 String strong = new String(&q ...

  8. 最新版Theos.2016.08的安装方法

    http://bbs.pediy.com/showthread.php?t=212425 标题: [翻译]手把手安装最新版Theos.2016.08作者: roysue时间: 2016-08-26,1 ...

  9. 如何以最简单的方式安装 KALI 渗透测试框架系统

    0x01 第一步下载 KALI 百度搜索 KALI 官网,找到下载区,我选的是 64 位标准版,但是推荐下载 32 位(功能貌似更全) 这个为下载后的 iso 镜像文件 0x02 第二步打开虚拟机,配 ...

  10. UVA11389巴士司机问题

    题意:       有n个巴士司机,然后有2n个活,其中有n个是上午,n个是下午,每个自己都要选择一个上午的和一个下午的,每个活都有驾驶距离,如果一个司机每天的驾驶距离大于d,那么超出的部分就要每个单 ...