Kubeadm 搭建K8s集群

前置操作 (每台机器上都需要操作) 使用系统 Centos 7 cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) 关闭防火墙 systemctl stop firewalld && systemctl disable firewalld 禁用SELINUX vim /etc/selinux/config # 或者修改/etc/sysconfig/selinux SELINUX=disabled [注意] 开启 IP 路由转发和 NAT # https://ccie.lol/knowledge-base/linux-centos-route-forwarding/ # 不开启会导致 Pod 无法链接外网以及 Pod 间无法通信的问题. [root@host ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf [root@host ~]# sysctl -p [root@host ~]# sysctl -a | grep "ip_forward" net.ipv4.ip_forward = 1 # 开启NAT [root@host ~]# iptables -P FORWARD ACCEPT # 缺省允许 IP 转发 # 利用 iptables 实现 NAT MASQUERADE 共享上网,此处 eth0 需要是能够访问外部网络的网卡接口 [root@host ~]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 修改 k8s....

2021-02-07 · 3 分钟 · 592 字

Kubernetes入门-基础

网络设置 # https://ccie.lol/knowledge-base/linux-centos-route-forwarding/ # 注意事项 开启 IP 路由转发和 NAT, 未开启会导致 Pod 无法访问外网以及 Pod 间无法通信. [root@host ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf [root@host ~]# sysctl -p [root@host ~]# sysctl -a | grep "ip_forward" net.ipv4.ip_forward = 1 # 开启NAT [root@host ~]# iptables -P FORWARD ACCEPT # 缺省允许 IP 转发 # 利用 iptables 实现 NAT MASQUERADE 共享上网,此处 eth0 需要是能够访问外部网络的网卡接口 [root@host ~]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE CPU...

2021-02-06 · 2 分钟 · 369 字

字符串拼接性能测试

// splicing_test.go package splicing import ( "strconv" "strings" "testing" ) func Str(str []string) string { var rst string for _, s := range str { rst += s } return rst } func BuilderStr(str []string) string { var builder strings.Builder for _, s := range str { builder.WriteString(s) } return builder.String() } func BenchmarkStr(b *testing.B) { srcStr := make([]string, 0, 100000) b.Run("Append-10000", func(b *testing.B) { for i := 0; i < 10000; i++ { srcStr = append(srcStr, strconv....

2021-01-28 · 3 分钟 · 431 字

time.After() 导致内存暴涨

select + time.After 导致内存暴涨 func Function(notRun notRun) { for { select { case <-notRun.notRun: // 大多数情况都是有notRun的输入 case <-time.After(time.Minute): notRun.Close() continue case <-notRun.run: notRun.Close() return } } } notRun 发送消息频率过快,而每次select都会调用到time.After,而time.After又会NewTimer,而每次NewTimer都必须在1分钟后才能释放。 当notRun的频率很高时,会在内存中堆积非常多的无用的Timer。导致内存暴涨。 解决方法 func Function(notRun notRun) { afterTime := time.Minute after := time.NewTimer(afterTime) defer after.Stop() for { after.Reset(afterTime) select { case <-notRun.notRun: case <-after.C: notRun.Close() continue case <-notRun.run: notRun.Close() return } } } 自己 NewTimer 在每次 select 之前 reset,使 timer 重新计时,从而避免每次都 new timer。

2019-10-31 · 1 分钟 · 71 字

Golang 编译

编译 编译其他系统 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build # 不能复制空格 set CGO_ENABLED=0 set GOOS=linux set GOARCH=amd64 go build 图标制作 第一步: Windows 下载MinGW 第二步: 新建一个.rc文件,加入文件名为 demo.rc 输入内容 IDI_ICON1 ICON "cefclient.ico" 其中 cefclient.ico 是你的ico的地址 第三步: MinGW 执行 windres -o demo.syso demo.rc 第四步: 将生成的demo.syso 放到项目目录下 go build 隐藏命令行 go build -i -ldflags="-H windowsgui"

2019-10-29 · 1 分钟 · 49 字

GORM 使用

MYSQL 悲观锁 tx := db.DB.Begin() if err := tx.Set("gorm:query_option", "FOR UPDATE"). Where("`xx` = ? and `xxx` = ?", xx, xxx). First(&xx).Error; err != nil { tx.Rollback() return } 在事务中使用 Set("gorm:query_option", "FOR UPDATE") + first 能将查询的这条记录锁住; 在事务 rollback 或 commit 后会 unlock。 创建复合主键(当主键涉及自增时) gorm:"primary_key;AUTO_INCREMENT:false" 连接数据库 步骤分析 引入mysql数据库驱动 引入gorm包 读取配置文件中的数据库信息 将读取的数据生成为Open()需要的字符串 代码示例 package base import ( _ "github.com/go-sql-driver/mysql" _ "github.com/jinzhu/gorm/dialects/mysql" "github.com/jinzhu/gorm" "fmt" "log" ) var ( DB *gorm.DB user = "user" password = "password" dbname = "dbname" address = "address" port = "port" ) func DBConnect() { dsn := fmt....

2019-08-10 · 1 分钟 · 115 字

Golang HTTP包传输文件

文件传输 Content-Type http://tool.oschina.net/commons?type=22013-05-17 multipart/form-data: 既可以提交普通键值对,也可以提交(多个)文件键值对。 application/octet-stream: 只能提交二进制,而且只能提交一个二进制,如果提交文件的话,只能提交一个文件,后台接收参数只能有一个,而且只能是流(或者字节数组) application/x-www-form-urlencoded 不属于http content-type规范,通常用于浏览器表单提交,数据组织格式:name1=value1&name2=value2,post时会放入http body,get时,显示在在地址栏。 // golang 实现 W.Header().Add("Content-Type","application/octet-stream") W.Header().Add("Content-Disposition",fmt.Sprintf("attachment; filename=\"%s\"", fileName))

2019-07-24 · 1 分钟 · 18 字

Nginx 反向代理

将静态文件交给nginx代理 配置文件位置 /etc/nginx/conf.d/default.conf server { listen 80; server_name www.moyrn.com; location / { root /usr/share/nginx/webmonitor; index index.html; } } 通过不同的域名,将80端口的消息转发到其他端口 server { listen 80; server_name go.moyrn.com; location / { proxy_pass http://127.0.0.1:8080; } } server { listen 80; server_name moyrn.com; location / { proxy_pass http://127.0.0.1:8086; } } server { listen 80; server_name www.moyrn.com; location / { proxy_pass http://127.0.0.1:8086; } }

2018-03-31 · 1 分钟 · 58 字