使用Docker启动的Redis容器使用的配置文件路径等问题以及Python使用clickhouse_driver操作clickhouse数据库

embedded/2024/10/19 17:41:13/

一、使用Docker启动的Redis容器使用的配置文件路径等问题

1.docker启动的redis使用的配置文件路径是什么

        使用docker搭建redis服务,本身redis启动的时候可以指定配置文件的, redis-server /指定配置文件路径/redis.conf。 但手上也没有一个redis配置文件。

        在使用非docker安装时,redis的安装包里到是有redis.conf默认文件,但使用docker安装时,不好直接找到啊。没法使用redis本身自带的redis.conf。于是直接启动一个redis服务(不指定配置文件)

docker run -itd \
--name redis7 \
--privileged=true \
--restart=always \
-p 6379:6379 \
-v /opt/redis/data:/data \
-v /opt/redis7/conf/redis.conf:/etc/redis/redis.conf \
redis:latest redis-server /etc/redis/redis.conf --appendonly yes

        启动之后,使用info server查看,config_file为空,没有使用任何配置文件。

executable:/data/redis-server
config_file:

        所以整理一个精简的redis配置文件放在这里吧。docker搭建redis7.2时可使用的精简redis.conf配置文件

[#root] cat /opt/redis7/conf/redis.conf
port 6379
daemonize no
databases 1
tcp-backlog 128
tcp-keepalive 300
logfile "/data/redis.log"
syslog-enabled yes
crash-log-enabled yes
timeout 0
maxmemory 4gb
maxmemory-policy volatile-lru
save 3600 1 300 100 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
# syslog-ident redis
# requirepass foobared
# maxclients 10000

2.Redis启动时警告:Memory overcommit must be enabled

WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

docker exec redis7.2 sysctl vm.overcommit_memory=1

3.docker搭建redis服务时daemonize设置为no

        docker搭建redis服务时daemonize设置为no,为YES的时候redis启动不了。默认值为no 为不守护进程模式,如果是直接在宿主机启动.

4.发现python项目里多了个venv文件夹

        python3.3之后,可以用模块 venv 代替 virtualenv 工具创建、删除虚拟环境。venv就是一个虚拟python环境的文件夹。可以实现多个项目使用不同的python环境。

二、Python使用clickhouse_driver操作clickhouse数据库

    Python要实现使用clickhouse_driver操作clickhouse数据库,首先需要安装clickhouse_driver模块:pip install clickhouse_driver PIP安装的时候有时会遇到报警:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fd06b379a90>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/clickhouse-driver/。

        如果不是在DOCKER容器中一般可以通过指定PIP源的方法解决,如果是在docker容器中一般要修改docker中的DNS地址,可在本CSDN博客中搜索我的文章内容。

python">from clickhouse_driver import Client
#可以再加个连接超时时间send_receive_timeout=send_receive_timeout
client = Client(host=host, port=port, user=user, password=password,database=database)
result = client.execute("select * from 数据库.表 limit 10")
print(result)

    连接的时候可能碰到报错:

File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/connection.py", line 437, in receive_hello raise errors.UnexpectedPacketFromServerError(message)
clickhouse_driver.errors.UnexpectedPacketFromServerError: Code: 102. Unexpected packet from server None:None (expected Hello or Exception, got Unknown packet)

        这是因为端口使用错误导致,clickhouse有两个端口,8123和9000。分别用于接收 http协议和tcp协议请求,管理后台登录用的8123(jdbc连接),而程序连接clickhouse(driver连接)则需要使用9000端口。如果在程序中使用8123端口连接就会报错:

clickhouse_driver.errors.UnexpectedPacketFromServerError: Code: 102. Unexpected packet from server None:None (expected Hello or Exception, got Unknown packet)

 


http://www.ppmy.cn/embedded/128791.html

相关文章

springboot033小徐影城管理系统(论文+源码)_kaic

毕业论文 题目 小徐影城管理系统 院 系&#xff1a; 专 业&#xff1a; 学 号&#xff1a; 姓 名&#xff1a; 指导老师&#xff1a; 2021年 月 日 目 录…

maven工程怎么将除工程源码外的三方依赖一起打包到jar中

前言 现在&#xff0c;大家都在使用springboot来创建工程&#xff0c;基本很少关注打包的问题&#xff0c;springboot的spring boot maven plugin可以很方便的创建一个可执行的jar文件&#xff0c;并且包含项目的所有依赖。最近改一个老项目&#xff0c;纯maven项目&#xff0…

进程信号大总结(整理)

目录 信号入门 1. 生活角度的信号 2. 技术应用角度的信号 3. 注意 4. 信号概念 5. 用kill -l命令可以察看系统定义的信号列表 6. 信号处理常见方式概览 产生信号 1. 通过终端按键产生信号 Core Dump 2. 调用系统函数向进程发信号 3. 由软件条件产生信号 4. 硬件异…

基于SSM服装定制系统的设计

管理员账户功能包括&#xff1a;系统首页&#xff0c;个人中心&#xff0c;用户管理&#xff0c;服装类型管理&#xff0c;服装信息管理&#xff0c;服装定制管理&#xff0c;留言反馈&#xff0c;系统管理 前台账号功能包括&#xff1a;系统首页&#xff0c;个人中心&#xf…

2024 复健记

2024 复健记 OI生涯结束两年了&#xff08;六年OI一场空&#xff0c;梦里花落知多少&#xff09; 这两天闲着无事翻了翻自己的CSDN&#xff0c;发现上一篇文章已经是两年之前了。那时候退役&#xff0c;虽然不知道梦应归于何处&#xff0c;但依旧梦里栩然蝴蝶、一身轻。如今忆…

024 elasticsearch集群

文章目录 搭建集群 cp elasticsearch-7.10.2 escloud -Rcd escloud/rm -rf datacd logs/rm -rf *tar zcf escloud.tar.gz escloudtar zxf escloud.tar.gzmv escloud amv escloud bmv escloud ccd configvim elasticsearch.ymlcurl ifconfig.menetstat -tulnp | grep 9300Test-N…

新版(考拉版)Android Studio2024.1.2版 如何用无线(WiFi)连接Android手机

之前我写过一篇Android Studio如何用无线&#xff08;WiFi&#xff09;连接手机进行调试&#xff0c;那是之前版本的studio用的方法。新版的Android Studio连接手机更简单&#xff0c;无需任何设置。下面直接上干货。 第一步&#xff0c;打开Android Studio&#xff0c;点击右…

数据结构~AVL树

文章目录 一、AVL树的概念二、AVL树的定义三、AVL树的插入四、AVL树的平衡五、AVL树的验证六、AVL树的删除七、完整代码八、总结 一、AVL树的概念 AVL树是最先发明的自平衡二叉查找树&#xff0c;AVL是⼀颗空树&#xff0c;或者具备下列性质的二叉搜索树&#xff1a;它的左右子…