首页
关于
Search
1
联想510s mini 安装 Ventura
732 阅读
2
基于K8s + Jenkins+Docker + Gitee 自动部署 - 配置 Jenkins Item + Gitee Webhook (二)
506 阅读
3
Spring Boot Schedule疑问及线程池配置
403 阅读
4
Server Send Events With Spring Boot
345 阅读
5
Ngrok使用自有服务器服务器及域名 - 解决Mac client问题
328 阅读
默认分类
SSH
typecho
Spring boot
其他
mysql
k8s
jenkins
docker
Java
mqtt
MongoDB
登录
/
注册
Search
标签搜索
k8s
docker
ssh
mysql
db
gitee
jenkins
ngrok
黑苹果
MQTT
CC
累计撰写
19
篇文章
累计收到
0
条评论
首页
栏目
默认分类
SSH
typecho
Spring boot
其他
mysql
k8s
jenkins
docker
Java
mqtt
MongoDB
页面
关于
搜索到
19
篇与
cc
的结果
2022-06-24
Ngrok使用自有服务器服务器及域名 - 解决Mac client问题
环境服务端:Linux客户端:Linux、Mac要求:服务器有公网ip+自有域名编译服务端参考:https://www.jianshu.com/p/1fafa10af189完成后,可得到Linux、Windows对应的Server、Client域名解析可以使用子域名,如: ngrok.xx.com; 具体tunnel: xx.ngrok.xx.com这里需要配置两个域名解析ngrok.xx.com ip *.ngrok.xx.com ip (泛域名解析)问题编译Mac os client:GOOS=linux GOARCH=amd64 make release-client该命令能正常编译通过,但在Mac os中不能正常运行:chen@cc darwin_amd64 % ngrok fatal error: runtime: bsdthread_register error runtime stack: runtime.throw(0x14e8431, 0x21) /usr/local/go/src/runtime/panic.go:596 +0x95 fp=0x7ff7bfeff7d0 sp=0x7ff7bfeff7b0 runtime.goenvs() /usr/local/go/src/runtime/os_darwin.go:108 +0xa0 fp=0x7ff7bfeff800 sp=0x7ff7bfeff7d0 runtime.schedinit() /usr/local/go/src/runtime/proc.go:486 +0xa1 fp=0x7ff7bfeff840 sp=0x7ff7bfeff800 runtime.rt0_go(0x7ff7bfeff870, 0x1, 0x7ff7bfeff870, 0x1000000, 0x1, 0x7ff7bfeff9d0, 0x0, 0x7ff7bfeff9d6, 0x7ff7bfeff9f2, 0x7ff7bfeffa01, ...) /usr/local/go/src/runtime/asm_amd64.s:158 +0x183 fp=0x7ff7bfeff848 sp=0x7ff7bfeff840 编译Mac客户端要求:Macbook1、将编译服务端的代码拷贝到Mac # client 需要使用与服务端一样的证书chen@cc ngrok % ls CONTRIBUTORS LICENSE Makefile README.md assets bin contrib docs pkg src2、删除源码中 bin 目录 # 服务端编译产生的文件rm -rf bin/*3、安装1.14.1 版本Gohttps://dl.google.com/go/go1.14.1.darwin-amd64.pkg4、编译客户端GOOS=darwin GOARCH=amd64 make release-client5、验证chen@cc ngrok % bin/ngrok Error: Specify a local port to tunnel to, or an ngrok command. Example: To expose port 80, run 'ngrok 80' 提示ngrok可执行,增加配置即可使用遇到的问题:1、ngrok客户端在Mac运行无法创建链接,日志提示:ngrok certificate relies on legacy Common Name field, use SANs instead 使用Go 1.14.1版本进行重编编译2、编译出现错误:malformed module path "ngrok": missing dot in first path elementchen@cc ngrok % GOOS=darwin GOARCH=amd64 make release-server GOOS="" GOARCH="" go get github.com/jteeuwen/go-bindata/go-bindata go: downloading github.com/jteeuwen/go-bindata v3.0.7+incompatible go get: installing executables with 'go get' in module mode is deprecated. Use 'go install pkg@version' instead. For more information, see https://golang.org/doc/go-get-install-deprecation or run 'go help get' or 'go help install'. bin/go-bindata -nomemcopy -pkg=assets -tags=release \ -debug=false \ -o=src/ngrok/client/assets/assets_release.go \ assets/client/... bin/go-bindata -nomemcopy -pkg=assets -tags=release \ -debug=false \ -o=src/ngrok/server/assets/assets_release.go \ assets/server/... go get -tags 'release' -d -v ngrok/... go get ngrok/...: malformed module path "ngrok": missing dot in first path element make: *** [deps] Error 1配置环境变量: export GO111MODULE=off引用:https://zhuanlan.zhihu.com/p/374372749https://github.com/golang/go/issues/350483、编译出现错误:...proxy.golang.org..... i/o timeout切换代理:go env -w GOPROXY=https://goproxy.cn\n引用:https://blog.csdn.net/wei11556/article/details/109526797
2022年06月24日
328 阅读
0 评论
0 点赞
2022-05-31
基于K8s + Jenkins+Docker + Gitee 自动部署 - 配置 Jenkins Item + Gitee Webhook (二)
继续上一篇我们在k8s中搭建了Jenkins环境,接下来我们分别在Jenkins和Gitee中完善配置Gitee 引导配置:https://gitee.com/help/articles/4193Jenkins一、安装Gitee插件这里已经安装好了,具体步骤可参考:https://gitee.com/help/articles/4193#article-header3接下来,需要配置插件:https://gitee.com/help/articles/4193#article-header4这里出现成功即可二、创建构建任务这里我们期望push到develop分支时,能触发后端自动打包部署。1)、在Jenkins首页左上角,点击"New Item",输入名称2)、这里我们选择"Freestyle project"3)、"General"部分"Gitee 链接"默认配置好了4)、"Source Code Management" 配置源码管理:仓库地址、用户登录凭证仓库地址可以在仓库的“克隆”中找到 :如https://gitee.com/xx/xx.git在"Credentials"处点击"Add"配置Gitee账号用户名/密码5)、配置需要打包的分支,这里我们填写develop6)、配置"Build Triggers",即在什么情况可触发打包部署。这里我们勾选"Gitee webhook 触发构建.."展开后,继续勾选"推送代码"这里记录下"需要在 Gitee webhook 中填写 URL:...",这里需要配置公网可访问的ip或域名7)、接下来配置"构建指令过滤":这里我们只允许develop才能触发8)、生产一个固定的密码,用于Webhook请求鉴权9)、"Build Environment"配置收Webhook时执行的操作,这里我们选择执行脚本点击"Add build step"选择"Execnte shell"运行脚本"sh restarxx.sh"这里的 restarxx.sh 在仓库的根目录中该脚本执行:打包jar、build docker image 、重启container9)、点击"save"进行保存Gitee1)、进入到仓库配置,新增WebhookUrl:参考Jenkins步骤6给出的URL,这里需要转换公网可访问的ip+portWebHook 密码/签名密钥:参考 Jenkins步骤8生成的密码2)、验证Webhook配置好后可进行"测试",提示返回200即可push 到develop分支在Jenkins中可看到构建情况
2022年05月31日
506 阅读
0 评论
0 点赞
2022-05-31
基于K8s + Jenkins+Docker + Gitee 自动部署 - 在K8s中安装Jenkins (一)
背景目前在开发过程中,每次更新测试环境需要手动执行一个脚本:pull最新的代码、build jar、build docker image最后再基于最新的docker image启动容器。于是想“偷个懒”,将这些步骤自动化起来:当指定分支收到push后,触发打包、重启docker container.环境服务器: k8s集群,有N个node仓库: Gitee部署: 部署在集群中的某个node中一、创建namespacekubectl create ns jenkins二、创建Jenkins Deployment & Service准备配置文件:jenkins.yamlapiVersion: apps/v1 kind: Deployment metadata: namespace: jenkins name: jenkins-deployment spec: replicas: 1 selector: matchLabels: app: jenkins template: metadata: labels: app: jenkins spec: nodeName: Your_node_name # 可选,如果不挂载到本地目录,参考文末引用文章 containers: - name: jenkins image: jenkinsci/blueocean:latest ports: - containerPort: 8080 volumeMounts: - name: jenkins-home mountPath: /var/jenkins_home - name: docker-sock mountPath: /var/run/docker.sock volumes: - name: jenkins-home hostPath: path: /your/local/file/path # update me type: Directory - name: docker-sock # 声明挂载docker hostPath: path: /var/run/docker.sock type: Socket --- apiVersion: v1 kind: Service metadata: namespace: jenkins name: jenkins spec: type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 30005 # 在本机上暴露Jenkins对外服务端口 selector: app: jenkins 创建 Deployment & Service:kubectl create -f jenkins.yaml 注:这里准备把Jenkins的数据映射到host目录,所以使用hostPath挂载/var/jenkins_home,于是在指定的node上运行pod由于项目需要打包用到docker,所以将/var/run/docker.sock通过Socket方式挂载到容器(docker in docker)在Jenkins的pod中执行docker ps -a遇到/var/run/docker.sock: connect: permission denied错误,此时回到host执行:chmod 0777 /var/run/docker.sock赋予权限三、登录配置使用浏览器打开:http://your_k8s_node_ip:port 如:http://127.0.0.1:30005这里要求输入初始密码:登录pod的容器,查看对应的密码。图片中告知的路径:/var/lib/jenkins/secrets/initialAdminPassword # 获取node 名称 [root@cc jenkins]# kubectl get po -n jenkins NAME READY STATUS RESTARTS AGE jenkins-deployment-5db55f9db-7mrk2 1/1 Running 4 4d23h # 进入pod [root@cc jenkins]# kubectl exec -it jenkins-deployment-5db55f9db-7mrk2 -c jenkins /bin/bash -n jenkins # cat 密码 [root@cc jenkins]# cat /var/lib/jenkins/secrets/initialAdminPassword ****** 最后,按照推荐进行安装插件即可。参考:1、基于k8s安装Jenkinshttps://blog.csdn.net/qq_38942551/article/details/107769120
2022年05月31日
303 阅读
0 评论
0 点赞
2022-05-13
记一次Mysql优化
优化一:批量插入 (实际业务中,耗时从400s左右降到7s左右)伪代码 @Cleanup Connection conn = DaoUtils.getConnection(false); String sql = "INSERT INTO xx (column1, column2) VALUES (?, ?)"; PreparedStatement ps = conn.prepareStatement(sql); for (int i = 0; i < 1000000; i++) { ps.setString(1,"column1"); ps.setString(2,"column2"); ps.addBatch(); // 每1000条记录插入一次 if (i % 1000 == 0) { ps.executeBatch(); conn.commit(); ps.clearBatch(); } } // 剩余数量不足1000 ps.executeBatch(); conn.commit(); ps.clearBatch();默认情况下,有多少条数据,就会执行多少条sql。可以在mysql链接加上rewriteBatchedStatements=true,将多条插入sql重写为1条,可以有效减少sql执行次数。按照上面的代码,执行sql条数为执行executeBatch的次数。jdbc:mysql://127.0.0.1:3306?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true 官方文档:rewriteBatchedStatements Should the driver use multi-queries (regardless of the setting of "allowMultiQueries") as well as rewriting of prepared statements for INSERT into multi-value inserts when executeBatch() is called? Notice that this has the potential for SQL injection if using plain java.sql.Statements and your code doesn't sanitize input correctly. Notice that for prepared statements, server-side prepared statements can not currently take advantage of this rewrite option, and that if you don't specify stream lengths when using PreparedStatement.set*Stream(), the driver won't be able to determine the optimum number of parameters per batch and you might receive an error from the driver that the resultant packet is too large. Statement.getGeneratedKeys() for these rewritten statements only works when the entire batch includes INSERT statements. Please be aware using rewriteBatchedStatements=true with INSERT .. ON DUPLICATE KEY UPDATE that for rewritten statement server returns only one value as sum of all affected (or found) rows in batch and it isn't possible to map it correctly to initial statements; in this case driver returns 0 as a result of each batch statement if total count was 0, and the Statement.SUCCESS_NO_INFO as a result of each batch statement if total count was > 0. Default Value false Since Version 3.1.13 https://dev.mysql.com/doc/connectors/en/connector-j-connp-props-performance-extensions.html优化二:添加索引(分析sql,扫描数量、索引命中情况)表结构mysql> desc detection_plains; +-------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+--------------+------+-----+---------+----------------+ | id | bigint(20) | NO | PRI | NULL | auto_increment | | .. | ....... | NO | | NULL | | | peopleId | bigint(20) | NO | | NULL | | | plainType | int(2) | NO | | 0 | | +-------------------+--------------+------+-----+---------+----------------+ xx rows in set (0.02 sec)已有索引 mysql> show index from t_name; +------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | +------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ | t_name | 0 | PRIMARY | 1 | id | A | 169267 | NULL | NULL | | BTREE | | | +------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 1 row in set (0.00 sec)这张表目前仅有主键 查询sql mysql> select no from t_name where peopleId=9379 and plainType=1 order by schedule DESC limit 1; +----+ | no | +----+ | 10 | +----+ 1 row in set (2.23 sec)这里花了2s+,不太符合预期explain:查询执行sql情况,扫了多少条数据、有没有使用索引mysql> explain select no from t_name where peopleId=9379 and plainType=1 order by schedule DESC limit 1; +----+-------------+------------------+------------+------+---------------+------+---------+------+--------+----------+-----------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------------+------------+------+---------------+------+---------+------+--------+----------+-----------------------------+ | 1 | SIMPLE | detection_plains | NULL | ALL | NULL | NULL | NULL | NULL | 169301 | 1.00 | Using where; Using filesort | +----+-------------+------------------+------------+------+---------------+------+---------+------+--------+----------+-----------------------------+ 1 row in set, 1 warning (0.00 sec) 目前表数据量 mysql> select count(id) from t_name; +-----------+ | count(id) | +-----------+ | 175575 | +-----------+ 1 row in set (5.45 sec) 通过explain结果看,目前查询sql并未使用索引,几乎扫了整张表的数据。我们在peopleId,plainType列添加索引mysql> alter table t_name add index peopleIdPlainType(`peopleId`,`plainType`); Query OK, 0 rows affected (8.29 sec) Records: 0 Duplicates: 0 Warnings: 0 再次explain可知,扫描数据下降到10条,命中了创建的peopleIdPlainType的索引。 mysql> explain select no from t_name where peopleId=9379 and plainType=1 order by schedule DESC limit 1; +----+-------------+------------------+------------+------+-------------------+-------------------+---------+-------------+------+----------+---------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------------+------------+------+-------------------+-------------------+---------+-------------+------+----------+---------------------------------------+ | 1 | SIMPLE | detection_plains | NULL | ref | peopleIdPlainType | peopleIdPlainType | 12 | const,const | 10 | 100.00 | Using index condition; Using filesort | +----+-------------+------------------+------------+------+-------------------+-------------------+---------+-------------+------+----------+---------------------------------------+ 1 row in set, 1 warning (0.01 sec) mysql> select no from t_name where peopleId=9379 and plainType=1 order by schedule DESC limit 1; +----+ | no | +----+ | 10 | +----+ 1 row in set (0.00 sec) mysql> show profiles; +----------+------------+------------------------------------------------------------------------------------------------------------------+ | Query_ID | Duration | Query | +----------+------------+------------------------------------------------------------------------------------------------------------------+ | 3 | 0.00723975 | select no from t_name where peopleId=9379 and plainType=1 order by schedule DESC limit 1 | +----------+------------+------------------------------------------------------------------------------------------------------------------+ 3 rows in set, 1 warning (0.00 sec) 查询时间从2s+降到了7ms左右其他不使用“大事务":如果执行操作耗时高且开启了事务,容易导致Lock wait timeout exceeded; try restarting transaction 异常使用SELECT * FROM information_schema.INNODB_TRX;可查询当前事务数量、执行状态和执行的sql等信息尽量不并行操作db,会增加单个事务耗时
2022年05月13日
108 阅读
0 评论
0 点赞
2022-04-25
生活
为什么就这样了?
2022年04月25日
131 阅读
0 评论
0 点赞
1
2
3
4