使用Docker启动的Redis容器使用的配置文件路径等问题以及Python使用clickho ...

打印 上一主题 下一主题

主题 1042|帖子 1042|积分 3126

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

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

        使用docker搭建redis服务,自己redis启动的时候可以指定配置文件的, redis-server /指定配置文件路径/redis.conf。 但手上也没有一个redis配置文件。
        在使用非docker安装时,redis的安装包里到是有redis.conf默认文件,但使用docker安装时,欠好直接找到啊。没法使用redis自己自带的redis.conf。于是直接启动一个redis服务(不指定配置文件)
  1. docker run -itd \
  2. --name redis7 \
  3. --privileged=true \
  4. --restart=always \
  5. -p 6379:6379 \
  6. -v /opt/redis/data:/data \
  7. -v /opt/redis7/conf/redis.conf:/etc/redis/redis.conf \
  8. redis:latest redis-server /etc/redis/redis.conf --appendonly yes
复制代码
        启动之后,使用info server查察,config_file为空,没有使用任何配置文件。
  1. executable:/data/redis-server
  2. config_file:
复制代码
        以是整理一个精简的redis配置文件放在这里吧。docker搭建redis7.2时可使用的精简redis.conf配置文件
  1. [#root] cat /opt/redis7/conf/redis.conf
  2. port 6379
  3. daemonize no
  4. databases 1
  5. tcp-backlog 128
  6. tcp-keepalive 300
  7. logfile "/data/redis.log"
  8. syslog-enabled yes
  9. crash-log-enabled yes
  10. timeout 0
  11. maxmemory 4gb
  12. maxmemory-policy volatile-lru
  13. save 3600 1 300 100 60 10000
  14. stop-writes-on-bgsave-error yes
  15. rdbcompression yes
  16. rdbchecksum yes
  17. dbfilename dump.rdb
  18. # syslog-ident redis
  19. # requirepass foobared
  20. # 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博客中搜索我的文章内容。
  1. from clickhouse_driver import Client
  2. #可以再加个连接超时时间send_receive_timeout=send_receive_timeout
  3. client = Client(host=host, port=port, user=user, password=password,database=database)
  4. result = client.execute("select * from 数据库.表 limit 10")
  5. 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)
  
 


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

我可以不吃啊

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表