我的本地主机在 ubuntu 上,装有 nginx + php-fpm 8.1
server {
server_name "~^({[a-z]}2\.)*(?<project>\w+)\.(.*)localhost$";
root /home/fw/public_html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
我在 docker 中运行 redis-stack
docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 -v /home/fw/redis/data:/data -v /home/fw/redis/redis.conf:/redis-stack.conf redis/redis-stack:latest
# in redis.conf
unixsocket /run/redis.sock
unixsocketperm 770
# Server
redis_version:7.2.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:3a23a5ac67fe7008
redis_mode:standalone
os:Linux 6.5.0-27-generic x86_64
arch_bits:64
monotonic_clock:POSIX clock_gettime
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:11.4.0
process_id:9
process_supervised:no
run_id:ac8418a9548435ac2a3cad2c5d483b7e578e1420
tcp_port:6379
server_time_usec:1713180070510705
uptime_in_seconds:1238
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:1904038
executable:/opt/redis-stack/bin/redis-server
config_file:/redis-stack.conf
io_threads_active:0
listener0:name=tcp,bind=127.0.0.1,port=6379
listener1:name=unix,bind=/run/redis.sock
# Clients
connected_clients:3
cluster_connections:0
maxclients:10000
client_recent_max_input_buffer:8
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0
total_blocking_keys:0
total_blocking_keys_on_nokey:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0
total_blocking_keys:0
total_blocking_keys_on_nokey:0
# Memory
used_memory:1372880
used_memory_human:1.31M
used_memory_rss:22020096
used_memory_rss_human:21.00M
used_memory_peak:1426480
used_memory_peak_human:1.36M
used_memory_peak_perc:96.24%
used_memory_overhead:1200296
used_memory_startup:1194056
used_memory_dataset:172584
used_memory_dataset_perc:96.51%
allocator_allocated:1485408
allocator_active:8323072
allocator_resident:10420224
total_system_memory:15646117888
total_system_memory_human:14.57G
used_memory_lua:31744
used_memory_vm_eval:31744
used_memory_lua_human:31.00K
used_memory_scripts_eval:0
number_of_cached_scripts:0
number_of_functions:0
number_of_libraries:0
used_memory_vm_functions:32768
used_memory_vm_total:64512
used_memory_vm_total_human:63.00K
used_memory_functions:184
used_memory_scripts:184
used_memory_scripts_human:184B
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:5.60
allocator_frag_bytes:6837664
allocator_rss_ratio:1.25
allocator_rss_bytes:2097152
rss_overhead_ratio:2.11
rss_overhead_bytes:11599872
mem_fragmentation_ratio:16.30
mem_fragmentation_bytes:20669512
mem_not_counted_for_evict:8
mem_replication_backlog:0
mem_total_replication_buffers:0
mem_clients_slaves:0
mem_clients_normal:5784
mem_cluster_links:0
mem_aof_buffer:8
mem_allocator:jemalloc-5.3.0
active_defrag_running:0
lazyfree_pending_objects:0
lazyfreed_objects:0
# Persistence
loading:0
async_loading:0
current_cow_peak:0
current_cow_size:0
current_cow_size_age:0
current_fork_perc:0.00
current_save_keys_processed:0
current_save_keys_total:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1713178893
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
rdb_saves:1
rdb_last_cow_size:282624
rdb_last_load_keys_expired:0
rdb_last_load_keys_loaded:0
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_rewrites:0
aof_rewrites_consecutive_failures:0
aof_last_write_status:ok
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0
aof_current_size:483
aof_base_size:131
aof_pending_rewrite:0
aof_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0
total_connections_received:4
total_commands_processed:260
instantaneous_ops_per_sec:0
total_net_input_bytes:4569
total_net_output_bytes:1237771
total_net_repl_input_bytes:0
total_net_repl_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:27
evicted_keys:0
evicted_clients:0
total_eviction_exceeded_time:0
current_eviction_exceeded_time:0
keyspace_hits:22
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
pubsubshard_channels:0
latest_fork_usec:816
total_forks:1
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
total_active_defrag_time:0
current_active_defrag_time:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_error_replies:0
dump_payload_sanitizations:0
total_reads_processed:234
total_writes_processed:232
io_threaded_reads_processed:0
io_threaded_writes_processed:0
reply_buffer_shrinks:201
reply_buffer_expands:198
eventloop_cycles:12579
eventloop_duration_sum:2400062
eventloop_duration_cmd_sum:28832
instantaneous_eventloop_cycles_per_sec:9
instantaneous_eventloop_duration_usec:267
acl_access_denied_auth:0
acl_access_denied_cmd:0
acl_access_denied_key:0
acl_access_denied_channel:0
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:1363e4c8fc50c52fcb9833536e1a66fcc7ddfcfa
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:1.362032
used_cpu_user:1.445511
used_cpu_sys_children:0.000000
used_cpu_user_children:0.005820
used_cpu_sys_main_thread:1.360941
used_cpu_user_main_thread:1.445472
# Modules
module:name=timeseries,ver=11012,api=1,filters=0,usedby=[],using=[],options=[]
module:name=RedisCompat,ver=1,api=1,filters=0,usedby=[],using=[],options=[]
module:name=search,ver=20813,api=1,filters=0,usedby=[],using=[ReJSON],options=[handle-io-errors]
module:name=ReJSON,ver=20610,api=1,filters=0,usedby=[search],using=[],options=[handle-io-errors]
module:name=bf,ver=20612,api=1,filters=0,usedby=[],using=[],options=[]
module:name=redisgears_2,ver=20020,api=1,filters=0,usedby=[],using=[],options=[]
# Errorstats
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=5,expires=0,avg_ttl=0
我已经安装了 phpredis (带有 pecl)
$ php -i
Redis Support => enabled
Redis Version => 6.0.2
Redis Sentinel Version => 1.0
Available serializers => php, json
Directive => Local Value => Master Value
redis.arrays.algorithm => no value => no value
redis.arrays.auth => no value => no value
redis.arrays.autorehash => 0 => 0
redis.arrays.connecttimeout => 0 => 0
redis.arrays.consistent => 0 => 0
redis.arrays.distributor => no value => no value
redis.arrays.functions => no value => no value
redis.arrays.hosts => no value => no value
redis.arrays.index => 0 => 0
redis.arrays.lazyconnect => 0 => 0
redis.arrays.names => no value => no value
redis.arrays.pconnect => 0 => 0
redis.arrays.previous => no value => no value
redis.arrays.readtimeout => 0 => 0
redis.arrays.retryinterval => 0 => 0
redis.clusters.auth => no value => no value
redis.clusters.cache_slots => 0 => 0
redis.clusters.persistent => 0 => 0
redis.clusters.read_timeout => 0 => 0
redis.clusters.seeds => no value => no value
redis.clusters.timeout => 0 => 0
redis.pconnect.connection_limit => 0 => 0
redis.pconnect.echo_check_liveness => 1 => 1
redis.pconnect.pool_detect_dirty => 0 => 0
redis.pconnect.pool_pattern => no value => no value
redis.pconnect.pool_poll_timeout => 0 => 0
redis.pconnect.pooling_enabled => 1 => 1
redis.session.early_refresh => 0 => 0
redis.session.lock_expire => 0 => 0
redis.session.lock_retries => 100 => 100
redis.session.lock_wait_time => 20000 => 20000
redis.session.locking_enabled => 0 => 0
现在运行 php 脚本,我可以连接但无法使用连接:
$redis = new Redis();
try {
$redis->connect('127.0.0.1', 6379); // => true (it is connecting to redis ?)
// $redis->auth(''); // => string(42) "read error on connection to 127.0.0.1:6379"
// $pong = $redis->ping(); // => string(27) "socket error on read socket"
} catch (\Exception $e) {
var_dump($e->getMessage()) ;
die;
}
套接字配置在某处?连接持久性?(感谢帮助)
答案1
好的,解决了,感谢维护 phpredis 的 Michael Grunder (https://github.com/phpredis/phpredis)
指定的 redis.conf 文件有bind
指令不允许从容器外部进行访问
添加bind * -::*
到 redis.conf 可以修复它(虽然听起来不是超级安全并且我认为最好精确地指向每个允许的接口)。