nginx代理tomcat导致css或js加载失败

Web服务器经常会使用nginx作前置路由,在使用nginx配置Web服务器负载均衡、动静分离,会碰到设置反向代理后导致前端资源无法加载的问题

nginx反向代理的tomcat服务器导致前端资源css或js加载失败大概可以分为:端口丢失、真实ip或端口获取错误、js或者css太大加载失败等情形

端口丢失


反向代理获取真实ip(域名)、端口、协议

nginx反向代理后,servlet应用通过request.getRemoteAddr()取到的IP是nginx的IP,并非客户端的真实IP;通过request.getRequestUrl()获取的ip(域名)、端口、协议都是nginx对应的参数。

  • 比如nginx的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
http {
upstream backend {
server 127.0.0.1:8080;
#server backend1.example.com wight=5;
#server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;

#server backup1.example.com backup;
}

server {
listen 80;
server_name your.domain.com;

location /test {
proxy_pass http://backend/test;
}
...
}
}

在浏览器打开http://your.domain.com/test访问servlet应用,获取客户端IP和URL:

1
2
3
log.info("RemoteAddr:{}, URL:{}", request.getRemoteAddr(), request.getRequestURL());
//输出结果
RemoteAddr:127.0.0.1, URL:http://127.0.0.1:8080/test
  • 针对tomcat+nginx的解决方案:

    nginx添加如下配置,:

    1
    2
    3
    4
    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_set_header X-Forwarded-Proto $scheme;

    如果不知道如何添加,可参考nginx转发丢失端口的问题。添加完后,输出结果如下:

    1
    2
    //输出结果
    RemoteAddr:127.0.0.1, URL:http://浏览器的ip地址/test

    发现RemoteAddr仍然获取不正确,解决方案如下:

    • 方案一:通过request.getHeader("X-Forwrad-For")request.getHeader("X-Real-IP")获取到nginx配置的Header。

    • 方案二: 配置tomcat,通过Servlet API的request.getRemoteAddr()方法获取客户端的IP。Tomcat的server.xml,在Host元素内最后加入:

      1
      <Valve className="org.apache.catalina.valves.RemoteIpValve" />

    JS或css无法完全加载

    nginx的代理缓存区,默认较小导致部分文件出现加载不全的问题,比较典型的如jQuery框架,可以通过配置调整nginx的缓存区即可。

    最终完整配置如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    http {
    # http_proxy
    proxy_buffer_size 128k;
    proxy_buffers 32 128k;
    proxy_busy_buffers_size 128k;

    upstream backend {
    server 127.0.0.1:8080;
    }

    server {
    listen 80;
    server_name your.domain.com;

    location /test {
    proxy_pass http://backend/test;
    # 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_set_header X-Forwarded-Proto $scheme;
    }
    ...
    }
    ...
    }

    关于nginxhttp_proxy模块参数含义:

    http_proxy模块

分享到

ag安装

Installing ag on CentOS

  • Prerequistes

    • libpcre
    • liblzma

    Download, build and install

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    sudo yum install -y pcre-devel
    sudo yum install xz-devel

    cd /usr/local/src && sudo git clone https://github.com/ggreer/the_silver_searcher.git

    cd the_silver_searcher
    sudo ./build.sh
    sudo make install

    which ag
分享到

web常见漏洞

项目采用springboot作为web框架,涉及到常见的漏洞,特此记录


启用了不安全的HTTP 方法

  • 描述:启用了不安全的 HTTP 方法, 可能会在 Web 服务器上上载、修改或删除 Web 页面、脚本和文件

  • 原因:Web 服务器或应用程序服务器是以不安全的方式配置的

  • 解决方案:

    • 方案一:

      如果采用springboot内嵌的tomcat容器,可以在application.yml或application.properties增加如下配置:

      1
      2
      #解决不安全的HTTP方法漏洞  
      server.tomcat.port-header=HEAD,PUT,DELETE,OPTIONS,TRACE,COPY,SEARCH,PROPFIND
    • 方案二:

      代码增加对tomcat的配置,代码如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      @Configuration  
      public class TomcatConfig {

      @Bean
      public EmbeddedServletContainerFactory servletContainer() {
      TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {// 1
      protected void postProcessContext(Context context) {
      SecurityConstraint securityConstraint = new SecurityConstraint();
      securityConstraint.setUserConstraint("CONFIDENTIAL");
      SecurityCollection collection = new SecurityCollection();
      collection.addPattern("/*");
      collection.addMethod("HEAD");
      collection.addMethod("PUT");
      collection.addMethod("DELETE");
      collection.addMethod("OPTIONS");
      collection.addMethod("TRACE");
      collection.addMethod("COPY");
      collection.addMethod("SEARCH");
      collection.addMethod("PROPFIND");
      securityConstraint.addCollection(collection);
      context.addConstraint(securityConstraint);
      }
      };
      return tomcat;
      }
      }
  • 测试:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    #使用curl测试:
    curl -v -X OPTIONS http://www.example.com/test/
    查看响应的 Allow: GET, HEAD, POST, PUT, DELETE, OPTIONS

    # 看是否能上载来判断攻击是否生效。
    curl -v -T test.html http://www.example.com/test/test.html

    # 找一个存在的页面,如test2.html,如果删除成功,则攻击有效。
    curl -X DELETE http://www.example.com/test/test2.html
  • 参考链接:


Apache JServ protocol service

  • 描述:Apache JServ协议(AJP)是一种二进制协议,可以从web服务器代理入站请求。位于web服务器后的应用服务器,不建议将AJP服务公开访问。如果AJP被错误配置,它可能允许攻击者访问内部资源。

Host header attack

  • 描述:在许多情况下,开发人员信任HTTP主机头值并使用它来生成链接、导入脚本,甚至生成密码重置与它的值的链接。这是一个非常糟糕的想法,因为HTTP主机头可以由攻击者控制,可以利用网络缓存中毒和滥用替代渠道的密码重置邮件。

  • 解决方案:

    • 使用getServerName()代替getHeader(“host”);
    • 在Apache和nginx通过设置一个虚拟机来记录所有的非法Host header,或者在Apache和nginx里指定一个ServerName名单;
    • 同时,Apache开启UseCanonicalName选项
    1
    2
    3
    4
    # Apache在extra下的httpd-default.conf文件或者虚拟主机加入如下配置
    UseCanonicalName On
    # Nginx配置
    server_name example.com;
  • 参考链接:


Slow HTTP Denial of Service Attack

  • 描述:web服务器容易受到HTTP DoS(拒绝服务)攻击的影响,HTTP POST DoS攻击依赖于HTTP协议的设计要求。在处理之前完全接收到服务器,如果HTTP请求没有完成,或者传输速率非常低,服务器保持它的资源忙着等待其余的数据。如果服务器保存了太多的资源,这会造成拒绝服务。

  • 解决方案:

    配置防火墙 iptables -A INPUT -p tcp --syn --dport 端口号 -m connlimit --connlimit-above 50 -j REJECT

  • 参考链接

分享到

nginx转发丢失端口问题

nginx对于redirect location的处理,会造成端口丢失的现象。针对nginx处理非80标准端口进行redirect时导致端口丢失的问题,本文主要介绍nginx的反向代理和访问目录缺失/这两种情形

以下为两种情形的参考范例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 反向代理
listen 26479 default_server;
location / {
root /var/www/html;
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# 访问/gitlab的时候会自动加上/成为/gitlab/
listen 26479 default_server;
location /gitlab {
root /var/www/html;
}

反向代理

查看nginx官方文档提及的说明:

1
2
3
An unchanged “Host” request header field can be passed like this:

proxy_set_header Host $http_host;

同时参考gitlab-ce使用非标准端口访问的方案,查看gitlab-ce的nginx配置如下:

proxy_set_header Host $http_host;

通过查看nginx软件包,发现nginx已提供参考文件/etc/nginx/proxy_params

1
2
3
4
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_set_header X-Forwarded-Proto $scheme;

由于我使用的centos下面手动编译的nginx并未找到proxy_params,我的nginx位于/usr/local/nginx,于是通过vim /usr/local/nginx/conf/proxy_params输入以上内容,配置nginx的location如下:

1
2
3
4
location /gitlab {
proxy_pass http://127.0.0.1:9090/gitlab;
include proxy_params;
}

也可以手工输入proxy_params的内容到location配置段下

访问目录缺失/

比如$document_root存在data/index.html文件,但是访问的时候最后没加/,nginx会自动给你带上/,返回一个301重定向(这个行为和apache一致),但是当nginx监听的是非标准端口,这个301返回的Location没有端口号,导致浏览器请求出错。用curl可以很明显的看到这一点:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[~]# curl -v 127.0.0.1:9090/data
* About to connect() to 127.0.0.1 port 9090 (#0)
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 9090 (#0)
> GET /data HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 127.0.0.1:9090
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
* Server nginx is not blacklisted
< Server: nginx
< Date: Mon, 26 Feb 2018 02:20:49 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 178
< Connection: keep-alive
< Cache-Control: no-cache
< Location: http://127.0.0.1/data/
<
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact

可以看到Location端口号丢失了,这个和反向代理不一样。通过google搜索,在stackoverflow的question找到了解决方案:

1
2
3
if (-d $request_filename) {
rewrite [^/]$ $scheme://$http_host$uri/ permanent;
}

通过对URL进行重写带上端口

分享到

cdh5.12.0安装

安装Cloudera Manager

本文采用离线安装cdh5.12.0,所有安装包的版本均为5.12.0,安装所需的离线包均需提前下载,下文将给出对应下载链接地址和配置。安装的操作系统为centos 7及以上系统,其他系统和版本可以需自行下载对应的rpm

下载cloudera-manager.repo(所有节点均需配置)
  • 下载链接

  • cloudera-manage.repo配置(所有节点均需配置,仅仅展示主节点的配置如下)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [root@n171 cdh] cat /etc/yum.repos.d/cloudera-manager.repo
    [cloudera-manager]
    name = Cloudera Manager, Version 5.12.0
    baseurl = https://archive.cloudera.com/cm5/redhat/7/x86_64/cm/5.12.0/
    gpgkey = https://archive.cloudera.com/redhat/cdh/RPM-GPG-KEY-cloudera
    gpgcheck = 1

    # 验证生效
    yum clean all
    yum list | grep cloudera
    # 确认显示的版本是否正确(我这里显示5.12.0-1.cm5120.p0.120.el7)
下载cloudera-manager-installer.bin(主节点需配置,从节点无须配置)
  • 下载链接

  • 放置在/opt目录,并添加执行权限

    1
    chmod +x /opt/cloudera-manager-installer.bin
  • 配置完毕后验证[root@n171 cdh] ll /opt/cloudera-manager-installer.bin

    -rwxr-xr-x 1 root root 519670 6月 21 02:43 /opt/cloudera-manager-installer.bin

下载RPMS
  • 下载链接(下载目录下所有文件)

  • 新建放置目录 mkdir -p /opt/cloudera-RPMS/

  • 下载完毕后:

    • master节点,目录结构如下
    1
    2
    3
    4
    5
    6
    7
    [root@n171 cdh]# ls /opt/cloudera-RPMS/
    cloudera-manager-agent-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
    cloudera-manager-daemons-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
    cloudera-manager-server-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
    cloudera-manager-server-db-2-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
    enterprise-debuginfo-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
    oracle-j2sdk1.7-1.7.0+update67-1.x86_64.rpm
    • slave节点(不需要server相关的rpm,只需要agent相关rpm),目录结构如下
      1
      2
      3
      [root@n172 parcel-repo]# ls /opt/cloudera-RPMS/
      cloudera-manager-agent-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
      cloudera-manager-daemons-5.12.0-1.cm5120.p0.120.el7.x86_64.rpm
下载CDH-Parcel
  • 下载链接

  • 新建放置目录 mkdir -p /opt/cloudera/parcel-repo/

  • 下载完毕后(所有节点),目录结构如下

    1
    2
    3
    4
    5
    [root@n171 cdh]# ls /opt/cloudera/parcel-repo/
    CDH-5.12.0-1.cdh5.12.0.p0.29-el7.parcel
    CDH-5.12.0-1.cdh5.12.0.p0.29-el7.parcel.sha
    manifest.json
    注意:下载后将.sha1文件后缀更改为.sha
执行安装
  • 所有节点执行
1
2
cd /opt/cloudera-RPMS  
yum -y localinstall --nogpgcheck *.rpm
  • master节点执行
1
2
3
4
# 拷贝cloudera-manage-installer.bin到/opt/
# +x 权限
sudo chmod +x /opt/cloudera-manager-installer.bin
/opt/cloudera-manager-installer.bin
访问安装界面
1
2
http://Master主机的IP:7180/ 
如果不能访问,稍等刷新再试,服务启动需要一定时间
参考链接:
分享到

cdh5.12.0安装准备

简介

CDH是cloudera公司开发的一个快速部署、高效管理Hadoop和其各种组件的一个商业化产品。

主要分为两部分,分别为Cloudera Manager和CDH软件包。其中Cloudera Manager负责集群的部署与管理。
CDH软件包囊括了hdaoop各类的组件的安装包,例如hive、hdfs、spark等等。

系统要求

摘自官网文档:
The four hosts in the cluster must satisfy the following requirements:

  • The hosts must have at least 10 GB RAM.
  • You must have root or password-less sudo access to the hosts.
  • If using root, the hosts must accept the same root password.
  • The hosts must have Internet access to allow the wizard to install software from archive.cloudera.com
  • Run a supported OS:

HADOOP版本

目前Hadoop比较流行的主要有2个版本,Apache和Cloudera版本。

  • Apache Hadoop:维护人员比较多,更新频率比较快,但是稳定性比较差。
  • Cloudera Hadoop(CDH):CDH:Cloudera公司的发行版本,基于ApacheHadoop的二次开发,优化了组件兼容和交互接口、简化安装配置、增加Cloudera兼容特性。

CDH安装准备(本文操作系统为centos7及以上系统)

jdk 配置 vim /etc/profile

1
2
3
4
5
6
7
8
9
10
11
12
13
# JAVA
JAVA_HOME=/usr/local/jdk1.8.0_151
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

# PATH
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

# export
export PATH JAVA_HOME JRE_HOME CLASS_PATH

# 环境变量生效
. /etc/profile

hosts修改(每一个节点都需要修改)

1
2
3
4
5
6
7
8
9
[root@n171 cloudera-RPMS] cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.30.171 n171
192.168.30.172 n172
192.168.30.173 n173
192.168.30.174 n174

hostname配置(所有节点都需要修改需要重启)

1
2
[root@n171] cat /etc/hostname
n171

防火墙配置(cdh端口过多先关闭防火墙)

1
2
3
4
5
# 关闭防火墙
sudo systemctl stop firewalld.service

# 关闭开机启动
sudo systemctl disable firewalld.service

selinux

1
2
3
4
5
6
7
8
9
# 查看SELinux状态
getenforce # 如果不是Disabled,修改 SELinux=disabled ,需要重启机器

# 修改配置
vim /etc/selinux/config

# 查看配置内容 grep -v "#" /etc/selinux/config | grep -v '^$'
SELINUX=disabled
SELINUXTYPE=targeted

ntp配置(分布式系统时间同步工具)

参考linux鸟哥私房菜ntp

  • master(本文以n171为主节点)
1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看主节点n171的配置
[root@n171 ~]grep -v "#" /etc/ntp.conf | grep -v "^$"
# /etc/ntp.conf 配置
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
restrict 192.168.30.0 mask 255.255.255.0 nomodify notrap
server ntp1.aliyun.com prefer
server time1.aliyun.com
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
  • slave(所有从节点ntp客户端配置)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    # 查看从节点配置
    [root@n172 ~]grep -v "#" /etc/ntp.conf | grep -v "^$"
    # /etc/ntp.conf配置
    driftfile /var/lib/ntp/drift
    restrict default nomodify notrap nopeer noquery
    restrict 127.0.0.1
    restrict ::1
    restrict namenode01
    server namenode01
    includefile /etc/ntp/crypto/pw
    keys /etc/ntp/keys
    disable monitor
参考链接:
分享到

minidlna配置

ubuntu配置minidlna

  • 删除minidlna依赖:
1
2
3
sudo apt-get purge minidlna
sudo apt-get remove minidlna 
sudo apt-get autoremove
  • 安装: sudo apt-get install minidlna

  • 修改配置

1
2
3
4
5
6
7
8
9
10
sudo vim /etc/default/minidlna
# User and group the daemon should run as
USER="root"
#GROUP="minidlna"

sudo vim /etc/minidlna.conf
# Specify the user name or uid to run as.
user=root

sudo service minidlna restart

参考链接

分享到

homebrew配置

安装

参考链接

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

homebrew替换为清华的源

  • 替换formula 索引的镜像(即 brew update 时所更新内容)
1
2
3
4
5
6
7
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update
  • 替换Homebrew 二进制预编译包的镜像
1
2
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

homebrew清华大学开源使用帮助

分享到

gogs配置

什么是 Gogs?

Gogs 是一款极易搭建的自助 Git 服务。

Gogs目的

Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自助 Git 服务。使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语言支持的 所有平台,包括 Linux、Mac OS X、Windows 以及 ARM 平台。

gogs配置

gogs安装配置文档

gogs配置mysql数据库:

  • gogs要求Mysql版本为5.7以上,配置如下:
    • 升级MySQL到5.7

      树莓派中安装MySQL 5.7
      Install Mysql 5.7 on respbian jesse -pi 3

    • 配置innodb和字符集为utf8mb4
      1
      2
      3
      4
      5
      6
      7
      8
      9
      [client]
      default-character-set=utf8mb4
      [mysqld]
      character-set-server = utf8mb4
      collation-server = utf8mb4_unicode_ci
      init_connect='SET NAMES utf8mb4'
      skip-character-set-client-handshake = true
      [mysql]
      default-character-set = utf8mb4
分享到

redis配置

Prerequistes

  • Centos

    1
    yum -y install tcl
  • Ubuntu

    1
    apt-get -y install build-essential tcl

redis源码编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
REDIS_VERSION=4.0.1
wget http://download.redis.io/releases/redis-$REDIS_VERSION.tar.gz
tar -zxvf redis-$REDIS_VERSION.tar.gz
cd redis-$REDIS_VERSION
make
make test
sudo make install
# Once the program has been installed
# Redis comes with a built in script that sets up Redis to run as a background daemon.
cd utils
sudo ./install_server.sh
# Start and stop
sudo service redis_6379 start
sudo service redis_6379 stop
# To set Redis to automatically start at boot, run:
sudo update-rc.d redis_6379 defaults

/etc/redis/6379.conf 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
➜  ~ grep -v "#" /etc/redis/6379.conf | grep -v "^$"
bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis_6379.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis/6379
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

设置redis密码

1
2
3
4
5
6
7
8
9
10
# 搜索requirepass 即可查看密码,并且设置密码
vim /etc/redis/redis.conf
# 如果之前没有设置过密码可以通过密码命令行设置密码
CONFIG get requirepass;
# 设置密码
127.0.0.1:6379> CONFIG set requirepass "tutorialspoint"
OK
127.0.0.1:6379> CONFIG get requirepass
1) "requirepass"
2) "tutorialspoint
分享到