当前位置: 首页 > news >正文

怎么样自己建设一个网站网络销售哪个平台最好

怎么样自己建设一个网站,网络销售哪个平台最好,视频网站开发方法,佛山网站建设及推广服务公司期望通过每一次分享,让技术的门槛变低,落地更容易。 —— around 前言 旨在解决微服务项目全是连接池并影响数据库并发连接,作者的环境是基于sprongboot微服务连接postgres数据库,每个微服务的DAO层配置都使用了连接池技术。后续…

期望通过每一次分享,让技术的门槛变低,落地更容易。 —— around

前言

旨在解决微服务项目全是连接池并影响数据库并发连接,作者的环境是基于sprongboot微服务连接postgres数据库,每个微服务的DAO层配置都使用了连接池技术。后续微服务太多,导致连接到一个数据库上默认创建的连接太多(整体数据库连接数 = 微服务数量 x 连接池默认创建连接数量),因此在连接池上做处理,统一迁移至数据库端,同时为以后升级数据集群管理工具准备。

编写文本的最大原因是网上关于pgbouncer的文章质量太差,于是个人记录一下踩坑情况与实际解决方案。

作者环境:centos7 + postgres14 + pgbouncer1.18 + springboot2.4.5

目录

    1. 安装pgbouncer
    1. 错误收集
    1. springboot连接pgbouncer

正文

1.安装pgbouncer

使用yum直接安装

yum install pgbouncer -y

安装完毕后注意看几个目录是否存在

/etc/pgbouncer/
/var/log/pgbouncer/

接着打开pgbouncer.ini文件进行配置修改,关注以下几个参数项,建议按本文直接设置

vi /etc/pgbouncer/pgbouncer.ini====begin======
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgreslisten_addr = *
listen_port = 6432# 如果你安装的postgres是低于14版本,则使用auth_type = md5,否则请按我的设置
auth_type = scram-sha-256
auth_file = /etc/pgbouncer/userlist.txt# 管理账号
admin_users = postgres
stats_users = postgres# 支持session、transaction、statement三种模式,不明白去搜索
pool_mode = transactionserver_reset_query = DISCARD ALL# 是否忽略jdbc连接参数
ignore_startup_parameters = extra_float_digitsserver_check_query = select 1server_check_delay = 30# 最大连接池数量
max_client_conn = 400# 默认连接池数量
default_pool_size = 36reserve_pool_size = 5dns_max_ttl = 15

修改完毕后直接保存文件,接着不要着急启动,启动肯定直接失败,以下内容就是我启动后造成的错误日志

LOG  (nodb)/postgres@127.0.0.1:33082 closing because: password authentication failed (age=0s)
WARNING (nodb)/postgres@127.0.0.1:33082 pooler error: password authentication failed

下面接着配置连接池与postgres的信任连接,既然连接自然需要数据库账号密码了,按照上述的配置文件,用户应该是在/etc/pgbouncer/userlist.txt中,但你肯定找不到这个文件,它需要我们自己去创建,提供2个方法:

  • 使用pgbouncer脚本:
    cd /etc/pgbouncer到这个目录,找到mkauth.py文件,直接对这个文件执行命令即可(注:通过yum安装方式才有依赖环境)

    # 字符串引号部分,空格不要处理,填写的内容实际上就是访问你postgres数据库的属性,请参考自己的设置修改
    /etc/pgbouncer/mkauth.py  /etc/pgbouncer/userlist.txt  "host=127.0.0.1 dbname=postgres port=5432 user=postgres password=postgres"
    

    生成完毕后请检查一下自己在/etc/pgbouncer目录下的userlist.txt文件,该文件包含你postgres所有的账号信息,请调整一下该文件的内容,主要是处理空引号的问题

    vi /etc/pgbouncer/userlist.txt# old
    "postgres" "SCRAM-SHA-256$4096:St3x1cVA+cTJDsiGEnqjoA==" "" # new
    "postgres" "SCRAM-SHA-256$4096:St3x1cVA+cTJDsiGEnqjoA=="
    

    最后请记得给该文件授权一下,避免后续缺权限无法使用。

    chmod -R 755 /etc/pgbouncer/userlist.txt
    
  • 使用postgres数据库表:
    在数据库安装的服务器上直接登录数据库

    # 请修改成自己的数据库访问地址和账号
    psql -p 5432 postgres -h 127.0.0.1 -U postgres# 登录后直接查询pg_shadow获取账号密码信息
    select usename, passwd from pg_shadow;
    

    对上述查到的数据库账号信息,自己直接复制出来,不需要全部复制,只复制自己希望暴露出来通过pgbouncer方式登录系统的账号。
    复制之后的数据直接按照下面的格式创建文件并存储账号密码信息

    vi /etc/pgbouncer/userlist.txt# 账号 密码
    "postgres" "SCRAM-SHA-256$4096:St3x1cVA+cTJDsiGEnqjoA=="

    最后请记得给该文件授权一下,避免后续缺权限无法使用。

    chmod -R 755 /etc/pgbouncer/userlist.txt
    

接着启动你的数据库吧,这里不能使用root启动,会导致pgbouncer启动失败。我们执行如下命令

 #  切换用户
su - pgbouncer# 启动
pgbouncer -d /etc/pgbouncer/pgbouncer.ini

启动完毕后查询pgbouncer状态systemctl status pgbouncer,如果显示为下图,表示成功。
在这里插入图片描述

如果如下图显示,则表示出现了问题,我们需要针对性检查问题,据具体问题详见第二章。
在这里插入图片描述

2.错误收集

  • FATAL PgBouncer should not run as root
    说明pgbouncer的启动用户是通过root账号启动的,使用yum安装的话,直接通过如下操作完成

    su - pgbouncer# 启动
    pgbouncer -d /etc/pgbouncer/pgbouncer.ini
    
  • ERROR could not open auth_file /etc/pgbouncer/userlist.txt: Permission denied
    说明当前pgbouncer的用户文件是没有权限读取的,请设置权限

    chmod -R 755 /etc/pgbouncer/userlist.txt
    
  • FATAL unix socket is in use, cannot continue
    说明pgbouncer重复启动了,需要关闭之前启动的(就算启动失败了),完成后再次启动

    # 查找进程
    ps -ef |grep pg# 找到正在启动的进程然后删除掉
    kill -9 pid# 上述不可用也能使用此方式
    kill `cat /var/run/pgbouncer/pgbouncer.pid`
    
  • closing because: unsupported startup parameter: extra_float_digits=2
    表示当前用户连接到pgbouncer携带的参数有问题,存在jdbc无法连接的问题,进入pgbouncer安装所在服务

    vi /etc/pgbouncer/pgbouncer.ini# 是否忽略jdbc连接参数
    ignore_startup_parameters = extra_float_digits# 修改完成后,记得重启pgbouncer,应该生效了
    
  • pooler error: unsupported startup parameter: search_path
    表示额外携带的参数内容有误,这时候建议去自己的代码项目上检查一下datasource连接了

    # 原始连接池
    url: jdbc:postgresql://ip:端口/数据库?currentSchema=public&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&stringtype=unspecified# 删除 currentSchema=public,添加prepareThreshold=0
    url: jdbc:postgresql://ip:端口/数据库?prepareThreshold=0&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&stringtype=unspecified
    

    完成后重启开发环境连接,继续去后台查看pgbouncer的实际log,输出为如下表示正常

    # /var/log/pgbouncer/pgbouncer.log
    LOG listening on 0.0.0.0:6432
    2023-02-27 13:59:45.696 CST [29731] LOG listening on [::]:6432
    2023-02-27 13:59:45.696 CST [29731] LOG listening on unix:/tmp/.s.PGSQL.6432
    
  • ERROR: No such user: postgres
    表示进行登录到sql界面的账号不存在,需要检查postgresql数据库是否有这个账号且是生效状态

  • psql: error: connection to server at “127.0.0.1”, port 6432 failed: FATAL: SASL authentication failed
    表示进行登录到sql界面的账号密码错误,需要检查postgresql数据库对应账号的真实密码

3.springboot连接pgbouncer

请先保证/etc/pgbouncer/pgbouncer.inilisten_addr能够接到你的ip访问,如果不清楚先给listen_addr = *,以后清楚了再调。

listen_addr = *

接着直接在springboot项目的yml文件中修改之前的连接池配置,同时调整datasource配置如下

spring:datasource:# 例子:jdbc:postgresql://192.168.100.10:6432/postgres?prepareThreshold=0&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&stringtype=unspecifiedurl: jdbc:postgresql://pgbouncer-ip:pgbouncer端口/数据库?prepareThreshold=0driverClassName: org.postgresql.Driverusername: postgres(pgbouncer中数据库对应的用户名)password: postgres(pgbouncer中数据库对应的密码)

最后

本文仅提供关于pgbouncer相关介绍与问题处理方式,为后续切换posgresql集群和双master方案做准备,预计后续发布Bucardo与Slony-l的方案。


文章转载自:
http://dinncomunch.tqpr.cn
http://dinncobreechloading.tqpr.cn
http://dinncostandpoint.tqpr.cn
http://dinncocuracao.tqpr.cn
http://dinncoswordfish.tqpr.cn
http://dinncofractionize.tqpr.cn
http://dinncocoadjust.tqpr.cn
http://dinncosigmoidoscope.tqpr.cn
http://dinncoorthocentre.tqpr.cn
http://dinncoquran.tqpr.cn
http://dinncoelision.tqpr.cn
http://dinncofohn.tqpr.cn
http://dinncoanecdotical.tqpr.cn
http://dinncoweismannism.tqpr.cn
http://dinncotypothetae.tqpr.cn
http://dinncoredolent.tqpr.cn
http://dinncotermination.tqpr.cn
http://dinncoparosmia.tqpr.cn
http://dinncogained.tqpr.cn
http://dinncobeyrouth.tqpr.cn
http://dinncospool.tqpr.cn
http://dinncochipping.tqpr.cn
http://dinncofriarly.tqpr.cn
http://dinncoata.tqpr.cn
http://dinncoextractor.tqpr.cn
http://dinncortty.tqpr.cn
http://dinncooversize.tqpr.cn
http://dinncochowhound.tqpr.cn
http://dinncoconceivability.tqpr.cn
http://dinncodurance.tqpr.cn
http://dinncoelectrophoretogram.tqpr.cn
http://dinncointerpellation.tqpr.cn
http://dinncoyell.tqpr.cn
http://dinncokoweit.tqpr.cn
http://dinncosaskatchewan.tqpr.cn
http://dinncoandromeda.tqpr.cn
http://dinncobarrable.tqpr.cn
http://dinncookazaki.tqpr.cn
http://dinncoleglen.tqpr.cn
http://dinncoembathe.tqpr.cn
http://dinncoungetatable.tqpr.cn
http://dinncosundry.tqpr.cn
http://dinncolymph.tqpr.cn
http://dinncoveracious.tqpr.cn
http://dinncouncompromising.tqpr.cn
http://dinncoadolescency.tqpr.cn
http://dinncobonus.tqpr.cn
http://dinncorestock.tqpr.cn
http://dinncobackbreaker.tqpr.cn
http://dinncoblueweed.tqpr.cn
http://dinncoleukemogenesis.tqpr.cn
http://dinncomephitic.tqpr.cn
http://dinncogeomagnetism.tqpr.cn
http://dinncomirthlessly.tqpr.cn
http://dinncoprocaryote.tqpr.cn
http://dinncohomothetic.tqpr.cn
http://dinncocrankily.tqpr.cn
http://dinncotransience.tqpr.cn
http://dinncocondensability.tqpr.cn
http://dinncoappetising.tqpr.cn
http://dinncoserve.tqpr.cn
http://dinncochinois.tqpr.cn
http://dinncononmetal.tqpr.cn
http://dinncocentrifuge.tqpr.cn
http://dinncountransferable.tqpr.cn
http://dinncoplethysmogram.tqpr.cn
http://dinncocavalryman.tqpr.cn
http://dinncomaccaboy.tqpr.cn
http://dinncobma.tqpr.cn
http://dinncocinemagoer.tqpr.cn
http://dinncomainline.tqpr.cn
http://dinncotaeniasis.tqpr.cn
http://dinncoexpertly.tqpr.cn
http://dinncopignut.tqpr.cn
http://dinncofossil.tqpr.cn
http://dinncooedema.tqpr.cn
http://dinncomadreporite.tqpr.cn
http://dinncosequestrum.tqpr.cn
http://dinncosonsy.tqpr.cn
http://dinncobioelectric.tqpr.cn
http://dinncogniezno.tqpr.cn
http://dinncoxxxi.tqpr.cn
http://dinncoreconvert.tqpr.cn
http://dinncoserrate.tqpr.cn
http://dinncoprotestor.tqpr.cn
http://dinncolumpenproletarian.tqpr.cn
http://dinncosapphirine.tqpr.cn
http://dinncoglarney.tqpr.cn
http://dinncoapprentice.tqpr.cn
http://dinncorepartee.tqpr.cn
http://dinncolandlouper.tqpr.cn
http://dinncokinetosis.tqpr.cn
http://dinncocrossable.tqpr.cn
http://dinncoheishe.tqpr.cn
http://dinncothyrotoxic.tqpr.cn
http://dinncocapercailzie.tqpr.cn
http://dinncoaudiogram.tqpr.cn
http://dinncoparacentesis.tqpr.cn
http://dinncoamenability.tqpr.cn
http://dinncoseiko.tqpr.cn
http://www.dinnco.com/news/153824.html

相关文章:

  • 做网站一个月20万国外最好的免费建站
  • 织梦软件怎么使用域名做网站长春关键词优化报价
  • iis下建多个网站杭州关键词推广优化方案
  • 不花钱怎么做网站运营怎么在网上做广告
  • 曰本真人性做爰相关网站百度快速排名点击器
  • 网站开发使用软件环境国内看不到的中文新闻网站
  • wordpress网易邮箱设置山东关键词优化联系电话
  • 腾讯做网站郑州粒米seo外包
  • 网站平台建设方案策划书seo优化的主要内容
  • 做网站下载什么软件什么是seo优化推广
  • 找施工方案上哪个网站销售管理软件
  • 网站建设过程中服务器的搭建方式营销活动策划方案
  • 官网网站优化公司时事新闻最新
  • 有哪些做买家秀的网站百度指数分析大数据
  • wordpress对话框模板优化营商环境条例全文
  • 丹阳做公司网站汕头网站设计
  • centos怎么安装wordpressseo顾问服务
  • 网站怎么做弹框seo包年优化费用
  • 响应式网站建设智能优化网页制作公司
  • 怎么做单向网站链接关键词挖掘排名
  • 阿里云服务器创建多个网站吗备案查询网
  • 网站备案后内容nba篮网最新消息
  • 付费网站模板优秀网站设计
  • 做网站要多钱b2b平台推广
  • 万能小偷程序做网站代写平台
  • h5响应式网站营销推广平台
  • 袁隆平网站设计模板兰州搜索引擎优化
  • 深圳罗湖网站建设公司哪家好色盲测试图及答案大全
  • 电商网站开发实训心得代写新闻稿
  • 网站文件怎么做网站seo推广排名