Docker部署redis单机版

cat <<END>Dockerfile
FROM alpine:latest
MAINTAINER [email protected]

RUN echo 'http://mirrors.ustc.edu.cn/alpine/edge/main' > /etc/apk/repositories && \
     echo '@community http://mirrors.ustc.edu.cn/alpine/edge/community' >> /etc/apk/repositories  && \
     echo '@testing http://mirrors.ustc.edu.cn/alpine/edge/testing' >> /etc/apk/repositories   && \
      apk update
ENV TIMEZONE Asia/Shanghai
RUN apk add tzdata bash-doc bash redis && \
    ln -snf /usr/share/zoneinfo/$TIMEZONE /etc/localtime && \
    echo $TIMEZONE > /etc/timezone 

EXPOSE 6379
COPY redis.conf /etc/redis.conf
CMD ["redis-server", "/etc/redis.conf"]
END
  • redis配置
cat <<END>redis.conf
protected-mode no
port 6379
tcp-backlog 511
unixsocket /run/redis/redis.sock
unixsocketperm 770
timeout 0
tcp-keepalive 300
supervised no
loglevel notice
logfile /var/log/redis/redis.log
databases 16
always-show-logo no
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
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-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 yes
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
END
  • redis 运行
docker run -d --name redis -p6379:6379 -v /xx/xx/:/var/lib/redis redis:xxx

K8S运行

kubectl create configmap redis --from-file=./redis.conf
cat <<END> redis.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  labels:
    app: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: ccr.ccs.tencentyun.com/libary/mylbary:redis6x
        ports:
          - containerPort: 6379
        resources:
          limits:
            cpu: 4000m
            memory: 4Gi
          requests:
            cpu: 500m
            memory: 0.5Gi

        livenessProbe:
          initialDelaySeconds: 15
          tcpSocket:
            port: 6379
          periodSeconds: 10
          timeoutSeconds: 10
          failureThreshold: 3
        volumeMounts:
          - mountPath: /var/lib/redis
            name: data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: redis

---
apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  clusterIP: None
  ports:
  - name: http
    port: 6379
    protocol: TCP
    targetPort: 6379
  type: ClusterIP
  selector:
    app: redis

---
apiVersion: v1
kind: Service
metadata:
  name: redis-s
spec:
  ports:
  - name: http
    port: 6379
    protocol: TCP
    targetPort: 6379
    nodePort: 30100
  type: NodePort
  selector:
    app: redis
END 
设置密码
config set requirepass 123456
通过以下指令查看密码
config get requirepass

猜你喜欢

转载自blog.csdn.net/weixin_42562106/article/details/115109948
今日推荐