hj_服务器操作记录01_安装单机redis
podman安装redis alias docker=podman
https://hub.docker.com/_/redis?tab=tags 查找redis镜像tag ,docker search redis也行,
docker pull redis:6.2.6 , 选择dockers.io这个版本选项. docker images
[hj@iZc3hwg7f2i7mfZ ~]$ docker pull redis:6.2.6 ? docker.io/library/redis:6.2.6 Trying to pull docker.io/library/redis:6.2.6... Getting image source signatures Copying blob 6333f8baaf7c done Copying blob f9772c8a44e7 done Copying blob e5ae68f74026 done Copying blob 37c4354629da done Copying blob 6954d19bb2e5 done Copying blob b065b1b1fa0f done Copying config aea9b698d7 done Writing manifest to image destination Storing signatures aea9b698d7d1d2fb22fe74868e27e767334b2cc629a8c6f9db8cc1747ba299fd [hj@iZc3hwg7f2i7mfZ ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/redis 6.2.6 aea9b698d7d1 5 days ago 116 MB
mkdir -p /etc/hj_redis_6.2.6/conf /etc/hj_redis_6.2.6/data # 创建2个目录文件,保存redis的数据和配置文件
touch /etc/hj_redis_6.2.6/conf/redis.conf # 创建redis的配置文件
https://redis.io/下载 ,然后上传解压获取redis.conf配置文件示例. tar -zxvf redis-6.2.6.tar.gz
redis文件改动:
################################## NETWORK ##################################### # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # bind 127.0.0.1 # By default protected mode is enabled. You should disable it only if # you are sure you want clients from other hosts to connect to Redis # even if no authentication is configured, nor a specific set of interfaces # are explicitly listed using the "bind" directive. # protected-mode no # Accept connections on the specified port, default is 6379 (IANA #815344). # If port 0 is specified Redis will not listen on a TCP socket. # port 6380 # TCP listen() backlog. # # In high requests-per-second environments you need an high backlog in order # to avoid slow clients connections issues. Note that the Linux kernel # will silently truncate it to the value of /proc/sys/net/core/somaxconn so # make sure to raise both the value of somaxconn and tcp_max_syn_backlog # in order to get the desired effect. # tcp-backlog 511 # Close the connection after a client is idle for N seconds (0 to disable) # timeout 0 # A reasonable value for this option is 300 seconds, which is the new # Redis default starting with Redis 3.2.1. # tcp-keepalive 300 ################################# GENERAL ##################################### # By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. # daemonize no # If you run Redis from upstart or systemd, Redis can interact with your # supervision tree. Options: # supervised no - no supervision interaction # supervised upstart - signal upstart by putting Redis into SIGSTOP mode # supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET # supervised auto - detect upstart or systemd method based on # UPSTART_JOB or NOTIFY_SOCKET environment variables # Note: these supervision methods only signal "process is ready." # They do not enable continuous liveness pings back to your supervisor. # supervised no # If a pid file is specified, Redis writes it where specified at startup # and removes it at exit. # # When the server runs non daemonized, no pid file is created if none is # specified in the configuration. When the server is daemonized, the pid file # is used even if not specified, defaulting to "/var/run/redis.pid". # # Creating a pid file is best effort: if Redis is not able to create it # nothing bad happens, the server will start and run normally. # pidfile /var/run/redis_6380.pid # Specify the server verbosity level. # This can be one of: # debug (a lot of information, useful for development/testing) # verbose (many rarely useful info, but not a mess like the debug level) # notice (moderately verbose, what you want in production probably) # warning (only very important / critical messages are logged) # loglevel notice # Specify the log file name. Also the empty string can be used to force # Redis to log on the standard output. Note that if you use standard # output for logging but daemonize, logs will be sent to /dev/null # logfile "" # Set the number of databases. The default database is DB 0, you can select # a different one on a per-connection basis using SELECTwhere # dbid is a number between 0 and 'databases'-1 # databases 16 # However it is possible to force the pre-4.0 behavior and always show a # ASCII art logo in startup logs by setting the following option to yes. # always-show-logo yes ################################ SNAPSHOTTING ################################ # # Save the DB on disk: # # 这里是用来配置触发 Redis的 RDB 持久化条件,也就是什么时候将内存中的数据保存到硬盘. # 比如“save m n”.表示m秒内数据集存在n次修改时,自动触发bgsave # 当然如果你只是用Redis的缓存功能,不需要持久化: # save "" # save 900 1 save 300 10 save 60 10000 # 默认值为yes.当启用了RDB且最后一次后台保存数据失败,Redis是否停止接收数据. # 这会让用户意识到数据没有正确持久化到磁盘上,否则没有人会注意到灾难(disaster)发生了. # 如果Redis重启了,那么又可以重新开始接收数据了 # stop-writes-on-bgsave-error yes # 建议设置为 no 否则程序可能就报这个错.
# MISCONF Redis is configured to save RDB snapshots,
# but it is currently not able to persist on disk.
# Commands that may modify the data set are disabled,
# because this instance is configured to report errors
# during writes if RDB snapshotting fails
# (stop-writes-on-bgsave-error option).
# Please check the Redis logs for details about the RDB error. # 默认值是yes.对于存储到磁盘中的快照,可以设置是否进行压缩存储. # 如果是的话,redis会采用LZF算法进行压缩. # 如果你不想消耗CPU来进行压缩的话,可以设置为关闭此功能,但是存储在磁盘上的快照会比较大. # rdbcompression yes # 默认值是yes.在存储快照后,我们还可以让redis使用CRC64算法来进行数据校验, # 但是这样做会增加大约10%的性能消耗,如果希望获取到最大的性能提升,可以关闭此功能. # rdbchecksum yes # 设置快照的文件名,默认是 dump.rdb # dbfilename dump.rdb # 设置快照文件的存放路径,这个配置项一定是个目录,而不能是文件名.默认是和当前配置文件保存在同一目录. # dir ./ ################################# REPLICATION ################################# # When a slave loses its connection with the master, or when the replication # is still in progress, the slave can act in two different ways: # # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will # still reply to client requests, possibly with out of date data, or the # data set may just be empty if this is the first synchronization. # # 2) if slave-serve-stale-data is set to 'no' the slave will reply with # an error "SYNC with master in progress" to all the kind of commands # but to INFO and SLAVEOF. # slave-serve-stale-data yes # Note: read only slaves are not designed to be exposed to untrusted clients # on the internet. It's just a protection layer against misuse of the instance. # Still a read only slave exports by default all the administrative commands # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve # security of read only slaves using 'rename-command' to shadow all the # administrative / dangerous commands. # slave-read-only yes # With slow disks and fast (large bandwidth) networks, diskless replication # works better. # repl-diskless-sync no # The delay is specified in seconds, and by default is 5 seconds. To disable # it entirely just set it to 0 seconds and the transfer will start ASAP. # repl-diskless-sync-delay 5 # By default we optimize for low latency, but in very high traffic conditions # or when the master and slaves are many hops away, turning this to "yes" may # be a good idea. # repl-disable-tcp-nodelay no # By default the priority is 100. # slave-priority 100 ################################## SECURITY ################################### # Warning: since Redis is pretty fast an outside user can try up to # 150k passwords per second against a good box. This means that you should # use a very strong password otherwise it will be very easy to break. # requirepass 123456 ############################# LAZY FREEING #################################### # In all the above cases the default is to delete objects in a blocking way, # like if DEL was called. However you can configure each case specifically # in order to instead release memory in a non-blocking way like if UNLINK # was called, using the following configuration directives: # lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no ############################## APPEND ONLY MODE ############################### # 默认值为no,也就是说redis 默认使用的是rdb方式持久化, # 如果想要开启 AOF 持久化方式,需要将 appendonly 修改为 yes. # appendonly no # aof文件名,默认是"appendonly.aof" # appendfilename "appendonly.aof" # aof持久化策略的配置; # # no表示不执行fsync,由操作系统保证数据同步到磁盘,速度最快,但是不太安全; # # always表示每次写入都执行fsync,以保证数据同步到磁盘,效率很低; # # everysec表示每秒执行一次fsync,可能会导致丢失这1s数据.通常选择 everysec ,兼顾安全性和效率 # appendfsync everysec # 在aof重写或者写入rdb文件的时候,会执行大量IO,此时对于everysec和always的aof模式来说, # 执行fsync会造成阻塞过长时间,no-appendfsync-on-rewrite字段设置为默认设置为no. # 如果对延迟要求很高的应用,这个字段可以设置为yes,否则还是设置为no, # 这样对持久化特性来说这是更安全的选择. # 设置为yes表示rewrite期间对新写操作不fsync,暂时存在内存中,等rewrite完成后再写入,默认为no,建议yes. # Linux的默认fsync策略是30秒.可能丢失30秒数据.默认值为no. # no-appendfsync-on-rewrite no # 默认值为100.aof自动重写配置,当目前aof文件大小超过上一次重写的aof文件大小的百分之多少进行重写, # 即当aof文件增长到一定大小的时候,Redis能够调用bgrewriteaof对日志文件进行重写. # 当前AOF文件大小是上次日志重写得到AOF文件大小的二倍(设置为100)时,自动启动新的日志重写过程. # auto-aof-rewrite-percentage 100 # 设置允许重写的最小aof文件大小,避免了达到约定百分比但尺寸仍然很小的情况还要重写. # auto-aof-rewrite-min-size 64mb # aof文件可能在尾部是不完整的,当redis启动的时候,aof文件的数据被载入内存. # 重启可能发生在redis所在的主机操作系统宕机后,尤其在ext4文件系统没有加上data=ordered选项, # 出现这种现象 redis宕机或者异常终止不会造成尾部不完整现象,可以选择让redis退出, # 或者导入尽可能多的数据.如果选择的是yes,当截断的aof文件被导入的时候, # 会自动发布一个log给客户端然后load.如果是no,用户必须手动redis-check-aof修复AOF文件才可以. # 默认值为 yes # aof-load-truncated yes # This is currently turned off by default in order to avoid the surprise # of a format change, but will at some point be used as the default. # aof-use-rdb-preamble no # Set it to 0 or a negative value for unlimited execution without warnings. # lua-time-limit 5000 ################################## SLOW LOG ################################### # The following time is expressed in microseconds, so 1000000 is equivalent # to one second. Note that a negative number disables the slow log, while # a value of zero forces the logging of every command. # slowlog-log-slower-than 10000 # There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET. # slowlog-max-len 128 ################################ LATENCY MONITOR ############################## # By default latency monitoring is disabled since it is mostly not needed # if you don't have latency issues, and collecting data has a performance # impact, that while very small, can be measured under big load. Latency # monitoring can easily be enabled at runtime using the command # "CONFIG SET latency-monitor-threshold" if needed. # latency-monitor-threshold 0 ############################# EVENT NOTIFICATION ############################## # By default all notifications are disabled because most users don't need # this feature and the feature has some overhead. Note that if you don't # specify at least one of K or E, no events will be delivered. # notify-keyspace-events "" ############################### ADVANCED CONFIG ############################### # Hashes are encoded using a memory efficient data structure when they have a # small number of entries, and the biggest entry does not exceed a given # threshold. These thresholds can be configured using the following directives. # hash-max-ziplist-entries 512 hash-max-ziplist-value 64 # Positive numbers mean store up to _exactly_ that number of elements # per list node. # The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size), # but if your use case is unique, adjust the settings as necessary. # list-max-ziplist-size -2 # 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail] # etc. # list-compress-depth 0 # Sets have a special encoding in just one case: when a set is composed # of just strings that happen to be integers in radix 10 in the range # of 64 bit signed integers. # The following configuration setting sets the limit in the size of the # set in order to use this special memory saving encoding. # set-max-intset-entries 512 # Similarly to hashes and lists, sorted sets are also specially encoded in # order to save a lot of space. This encoding is only used when the length and # elements of a sorted set are below the following limits: # zset-max-ziplist-entries 128 zset-max-ziplist-value 64 # The suggested value is ~ 3000 in order to have the benefits of # the space efficient encoding without slowing down too much PFADD, # which is O(N) with the sparse encoding. The value can be raised to # ~ 10000 when CPU is not a concern, but space is, and the data set is # composed of many HyperLogLogs with cardinality in the 0 - 15000 range. # hll-sparse-max-bytes 3000 # use "activerehashing yes" if you don't have such hard requirements but # want to free memory asap when possible. # activerehashing yes # Both the hard or the soft limit can be disabled by setting them to zero. # client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 # The range is between 1 and 500, however a value over 100 is usually not # a good idea. Most users should use the default of 10 and raise this up to # 100 only in environments where very low latency is required. # hz 10 # When a child rewrites the AOF file, if the following option is enabled # the file will be fsync-ed every 32 MB of data generated. This is useful # in order to commit the file to the disk more incrementally and avoid # big latency spikes. # aof-rewrite-incremental-fsync yes
podman run -d --privileged=true -p 6380:6380 -v /etc/hj_redis_6.2.6/conf/redis.conf:/etc/redis/redis.conf
-v /etc/hj_redis_6.2.6/data:/data --name hj_redis_6.2.6 redis:6.2.6 redis-server /etc/redis/redis.conf --appendonly yes
或者 aea9b698d7d1 这个是images id.
podman run -d --privileged=true -p 6380:6380 -v /etc/hj_redis_6.2.6/conf/redis.conf:/etc/redis/redis.conf -v /etc/hj_redis_6.2.6/data:/data
--name hj_redis_6.2.6 aea9b698d7d1 /etc/redis/redis.conf --appendonly yes
Ps: -d后台运行 --privileged 容器赋权 -p端口映射 -v 配置文件映射 -v data文件映射 --name 取名 镜像ID 或者 镜像名:tag 去远程pull再安装 --appendonly持久化
启动后 podman ps -a 可能没那么快加载出来.再次执行会报如下错->
Error: error creating container storage: the container name "hj_redis" is already in use by "0be1e12c633be7c92c6e703ae489dd58eeb76d8ae14915132085493df8dc1445". You have to remove that container to be able to reuse that name.: that name is already in use 这个报错.可能是启动快了 podman ps -a 暂时加载不出来.缓下再去查就有了~
或者可能是运行时由于服务器性能有问题.出了问题.这种可清除 var目录下的缓存与容器相关的文件.然后重新拉镜像跑容器可以解决.