1. 程式人生 > 其它 >hj_伺服器操作記錄01_安裝單機redis

hj_伺服器操作記錄01_安裝單機redis

podman安裝redis

https://hub.docker.com/_/redis?tab=tags 查詢redis映象tag ,docker search redis也行,

docker pull redis:6.2.6 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 SELECT <dbid> where
# 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


# 預設值是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 <milliseconds>" 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

 啟動後 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目錄下的快取與容器相關的檔案.然後重新拉映象跑容器可以解決.