Quantcast
Channel: network - 一个伪linux粉丝的blog
Viewing all 82 articles
Browse latest View live

change container time

$
0
0

某客户程序调试需要,希望将容器系统时间固定为某个日期 ,如 2020-09-16

我这边做了复现,默认是无法修改时间的,会提示

/ # date -s 2010-10-19
date: can't set date: Operation not permitted

经过查找资料,为 Container 设置权能才行  https://kubernetes.io/zh/docs/tasks/configure-pod-container/security-context/#set-capabilities-for-a-container

可以单独开设一些权限给容器,因此,需要修改depolyment,添加如下2个参数

securityContext:
capabilities:
add:

  • NET_ADMIN
  • SYS_TIME

添加后,重新部署的容器就可以修改时间了

/ # date -s 2020-09-16
Wed Sep 16 00:00:00 UTC 2020


npm-group 500 with

$
0
0

客户反馈,nexus仓库下npm拖包,当使用npm-group时,报错500,无法下载,直接使用npm-proxy时,反而顺利拖包。

这简直不符合常理,一般group含的源要多于单独的proxy。

检查发现npm-proxy实际仅有 官网地址http://registry.npmjs.org/。

一边开启nexus日志详细模式,

  • 更改 nexus 日志级别,org.sonatype.nexus.repository 从 info 设置为 debug

一边拖包时加上详情参数,然后做了几组实验。

先说第一个结论, registry.npm.taobao.org这边的问题,当npm-group含了 registry.npm.taobao.org ,拖包会报错。

客户新疑问来了,npm-group里面含了 私有库地址 abc、官网 http://registry.npmjs.org/,  最后才是 taobao地址 ,按照通用逻辑,优先级别依次往下。

实际上,我后来在官网找到了这段说明,顺序是有优先级别意义的。
https://help.sonatype.com/repomanager3/repository-management?_ga=2.116980102.1037975644.1605598044-1818828394.1605598044#RepositoryManagement-RepositoryGroup

Note that the order of the repositories listed in the Member section is important. When the repository manage searches for a component in a repository group, it will return the first match. To reorder a repository in this list, click and the drag the repositories and groups in the Members list or use the arrow buttons between the Available and Members list. These arrows can be used to add and remove repositories as well.

后来找到网友的测试 https://my.oschina.net/polly/blog/2120650

https://swenfang.github.io/2018/06/03/Maven-Priority/

最终结论
settings_mirror 的优先级高于 central
settings_profile_repo 优先级高于 settings_mirror
settings_profile_repo 优先级高于 pom_repositories
settings_profile_repo 优先级高于 pom_profile_repo
pom_profile_repo 优先级高于 pom_repositories
pom_repositories 优先级高于 settings_mirror
通过上面的比较得出完整的搜索链:

local_repo > settings_profile_repo > pom_profile_repo > pom_repositories > settings_mirror > central

也就是这段优先级别符合实际情况一点,有机会再研究这个吧。

 

kubectl-cheatsheet

$
0
0

1. 背景

某客户咨询 kubectl 命令行实现k8s服务的重启和镜像版本的更新方法,参考k8s官网  https://kubernetes.io/zh/docs/reference/kubectl/cheatsheet/  整理出2个对应的步骤介绍。

 

2. 步骤

 

2.1. 服务重启

服务重启一般有2种方式,直接删除pod,实现重启;或者修改 ReplicaSet 的方法实现重启。

 

2.1.1. 得到pod名称

kubectl get po -n default

 

2.1.2. 删除pod

已 alpine为例

kubectl delete po alpine-alpine-576f9f8b49-tq284 -n default

重启完成

 

2.1.3. 修改replicas方法

修改 ReplicaSet 的方法实现重启,数量 scale 到 0,然后又 scale 到 1,那么 Pod 也就重启了。

kubectl get deploy -n default

kubectl scale deployment --replicas=0 alpine-alpine -n default

kubectl scale deployment --replicas=1 alpine-alpine -n default

2.2. 镜像更新

2.2.1. 首次更新

编辑查看 deployment内容,

kubectl get deploy -n default

以 alpine为例

kubectl edit deployment alpine-alpine -n default

直接修改相关内容即可自动更新 , 找到当中的 image字段和name字段,观察镜像版本得知为alpine:0.04,名字为alpine-alpine

我们替换成其他版本 alpine:0.05 或 alpine:latest, 提示编辑完成

2.2.2. 后续更新

前面得到版本和名称后,后续更新只需要一行命令即可,命令如下:

更换alpine的镜像地址或版本即可

kubectl set image deployment/alpine-alpine alpine-alpine=10.10.150.105/myapp/alpine:0.05

更新完成提示  deployment.apps "alpine-alpine" image updated

3. 参考链接

Azure cni No available addresses

$
0
0

1. 问题描述

准时达客户反馈他们的 Azure 环境,部署应用时出现ip地址不足的提示

Failed create pod sandbox: rpc error: code = Unknown desc = NetworkPlugin cni failed to set up pod "kube-enveter***" network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses

2. 原因分析

以前客户环境遇到过类似现象,说是 azure-cni 拿到网络内的 ip,需要手动给节点分配辅助 IP 的,这个集群应该是没有那么多IP,后来不清楚客户是否联系了Azure 管理员,恢复了,今天再次遇到。

2.1. 尝试定位

根据现象,找到了一个issue https://github.com/Azure/acs-engine/issues/2845

里面有一个评论

And looking at InUse in /var/run/azure-vnet.json, definitely at least one of these nodes is very close to the limit, and that is also the node showing the "No available addresses" error:

请收藏这个有用的命令

kubectl get nodes -o name | cut -d / -f 2 | xargs -I{} -n1 ssh {} 'echo 'node ' {}; grep InUse /var/run/azure-vnet-ipam.json | sort | uniq -c'

可正是这个原本可以直接定位的结果,让我产生了怀疑

我把关注点放到了后半段,工作节点 ip 资源是足够的,忽视了前面3个管理节点没有多余 ip 可用了。

2.2. 定位

同事看到上面到图后提醒我,用户可能把容器部署到管理节点了。

检查 kubelet 日志,果然如此。


Nov 25 21:07:01 azure-uat-mgt01 kubelet[5499]: E1125 21:07:01.607523 5499 remote_runtime.go:92] RunPodSandbox from runtime service failed: rpc error: code = Unknown desc = NetworkPlugin cni failed to set up pod "kube-eventer-5ddc7f9f7f-9lr9z_kube-system" network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses
Nov 25 21:07:01 azure-uat-mgt01 kubelet[5499]: E1125 21:07:01.607662 5499 kuberuntime_sandbox.go:54] CreatePodSandbox for pod "kube-eventer-5ddc7f9f7f-9lr9z_kube-system(7aa4e25d-2f1d-11eb-b8cc-0242ac120003)" failed: rpc error: code = Unknown desc = NetworkPlugin cni failed to set up pod "kube-eventer-5ddc7f9f7f-9lr9z_kube-system" network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses
Nov 25 21:07:01 azure-uat-mgt01 kubelet[5499]: E1125 21:07:01.607687 5499 kuberuntime_manager.go:646] createPodSandbox for pod "kube-eventer-5ddc7f9f7f-9lr9z_kube-system(7aa4e25d-2f1d-11eb-b8cc-0242ac120003)" failed: rpc error: code = Unknown desc = NetworkPlugin cni failed to set up pod "kube-eventer-5ddc7f9f7f-9lr9z_kube-system" network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses
Nov 25 21:07:01 azure-uat-mgt01 kubelet[5499]: E1125 21:07:01.607793 5499 pod_workers.go:186] Error syncing pod 7aa4e25d-2f1d-11eb-b8cc-0242ac120003 ("kube-eventer-5ddc7f9f7f-9lr9z_kube-system(7aa4e25d-2f1d-11eb-b8cc-0242ac120003)"), skipping: failed to "CreatePodSandbox" for "kube-eventer-5ddc7f9f7f-9lr9z_kube-system(7aa4e25d-2f1d-11eb-b8cc-0242ac120003)" with CreatePodSandboxError: "CreatePodSandbox for pod \"kube-eventer-5ddc7f9f7f-9lr9z_kube-system(7aa4e25d-2f1d-11eb-b8cc-0242ac120003)\" failed: rpc error: code = Unknown desc = NetworkPlugin cni failed to set up pod \"kube-eventer-5ddc7f9f7f-9lr9z_kube-system\" network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses"
Nov 25 21:07:04 azure-uat-mgt01 kubelet[5499]: E1125 21:07:04.457888 5499 cni.go:259] Error adding network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses
Nov 25 21:07:04 azure-uat-mgt01 kubelet[5499]: E1125 21:07:04.457927 5499 cni.go:227] Error while adding to cni network: Failed to allocate address: Failed to delegate: Failed to allocate address: No available addresses

3. 解决方法

请用户部署到其它有空余 ip 的工作节点,成功部署,问题解决。

4. 后续改进

  •  检查日志时多看一些环节
  • 了解Azure cni ip的分配机制

anyconnect

$
0
0

anyconnect vpn 一键登录保存密码的方法,Mac 、Windows、Android

Mac 下 安装 原版 anconnect ,然后使用如下脚本即可,断线自动重连。


#!/bin/bash
# connect some vpn without password
USERNAME= # your username
PASSWORD= # your password
VPN_URL="your vpn and port"
VPN_BIN="/opt/cisco/anyconnect/bin/vpn"
ANYCONNECT_PATH="/Applications/Cisco/Cisco AnyConnect Secure Mobility Client.app"
get_anyclient_ui_pid() {
local pid=$(ps -ef | grep "$ANYCONNECT_PATH" | grep -v 'grep' | awk '{print $2}')
echo $pid
if [[ -z "$pid" ]]; then
return 1
else
return 0
fi
}
kill_anyconnect_ui() {
$VPN_BIN disconnect
local pid=$(get_anyclient_ui_pid)
# echo "PID: $pid"
if [[ -n "$pid" ]]; then
kill -9 $pid
fi
}
open_client_ui() {
if ! get_anyclient_ui_pid &> /dev/zero; then
open "$ANYCONNECT_PATH"
fi
}
connect() {
# sudo /opt/cisco/anyconnect/bin/vpnagentd
kill_anyconnect_ui
$VPN_BIN -s << EOF
connect $VPN_URL
1
$USERNAME
$PASSWORD
EOF
open_client_ui
}
main() {
if [[ -z "$USERNAME" || -z "$PASSWORD" || -z "$VPN_URL" ]]; then
echo "Error: empty user info"
exit 1
fi
case "$1" in
stop|s )
$VPN_BIN disconnect
;;
* )
connect
esac
}
main "$*"

Windows 下 使用 openconnect-gui 这个软件即可保存密码,界面简洁。


Android 下 OpenConnect 这个app即可,不要使用思科原版 AnyConnect.

openssl-1.1.1j-centos

$
0
0

这是一个简单记录,代码非原创,属于升级openssh 8.4 过程中,自行打centos下rpm包的过渡产物,属于就是“为了这点醋,包的这顿饺子”,故事之  -- openssl-1.1.1j 打包篇.

 

代码如下


#!/bin/bash
echo ----openssl-1.1.1j--2021-02-25--by cnrock------
set -e
set -v
if [[ ! -f "/root/openssl-1.1.1j.tar.gz" ]];then
wget -O /root/openssl-1.1.1j.tar.gz https://www.openssl.org/source/openssl-1.1.1j.tar.gz
fi
mkdir ~/openssl && cd ~/openssl
yum -y install \
curl \
which \
make \
gcc \
perl \
perl-WWW-Curl \
rpm-build
# Get openssl tarball
if [[ ! -f "./openssl-1.1.1j.tar.gz" ]];then
cp /root/openssl-1.1.1j.tar.gz ./
fi
# SPEC file
cat << 'EOF' > ~/openssl/openssl.spec
Summary: OpenSSL 1.1.1j for Centos by cnrock
Name: openssl
Version: %{?version}%{!?version:1.1.1j}
Release: 1%{?dist}
Obsoletes: %{name} <= %{version}
Provides: %{name} = %{version}
URL: https://www.openssl.org/
License: GPLv2+
Source: https://www.openssl.org/source/%{name}-%{version}.tar.gz
BuildRequires: make gcc perl perl-WWW-Curl
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%global openssldir /usr/local/openssl
%description
OpenSSL RPM for version 1.1.1j on Centos
%package devel
Summary: Development files for programs which will use the openssl library
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
%description devel
OpenSSL RPM for version 1.1.1j on Centos (development package)
%prep
%setup -q
%build
./config --prefix=%{openssldir} --openssldir=%{openssldir}
make
%install
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%make_install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libssl.so.1.1 %{buildroot}%{_libdir}
ln -sf %{openssldir}/lib/libcrypto.so.1.1 %{buildroot}%{_libdir}
ln -sf %{openssldir}/bin/openssl %{buildroot}%{_bindir}
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%files
%{openssldir}
%defattr(-,root,root)
/usr/bin/openssl
/usr/lib64/libcrypto.so.1.1
/usr/lib64/libssl.so.1.1
%files devel
%{openssldir}/include/*
%defattr(-,root,root)
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
EOF
mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cp ~/openssl/openssl.spec /root/rpmbuild/SPECS/openssl.spec
mv openssl-1.1.1j.tar.gz /root/rpmbuild/SOURCES
cd /root/rpmbuild/SPECS && \
rpmbuild \
-D "version 1.1.1j" \
-ba openssl.spec
# Before Uninstall Openssl : rpm -qa openssl
# Uninstall Current Openssl Vesion : yum -y remove openssl
# For install: rpm -ivvh /root/rpmbuild/RPMS/x86_64/openssl-1.1.1j-1.el7.x86_64.rpm --nodeps
# or rpm -Uvh openssl-1.1.1j-1.el7.x86_64.rpm --nodeps --force
# Verify install: rpm -qa openssl
# openssl version

打包输出略
升级前后版本变化如下

# cd /root/rpmbuild/RPMS/x86_64
# ls
openssl-1.1.1j-1.el7.x86_64.rpm openssl-devel-1.1.1j-1.el7.x86_64.rpm
openssl-debuginfo-1.1.1j-1.el7.x86_64.rpm
# rpm -Uvh openssl-1.1.1j-1.el7.x86_64.rpm --nodeps --force
Preparing... ################################# [100%]
Updating / installing...
1:openssl-1.1.1j-1.el7 ################################# [ 50%]
Cleaning up / removing...
2:openssl-1.1.1i-1.el7 ################################# [100%]
# openssl version
OpenSSL 1.1.1j 16 Feb 2021

openssl-1.1.1j

openssl-1.1.1j rpm

centos-openssl-cve

$
0
0

这是一个openssh cve漏洞系列中的一篇,也就是“为了这点醋,包的这顿饺子”,故事之  --openssl 和 openssh 漏洞修补流水账。

起因:

本来是一次普通的客户 几个漏洞咨询,涉及 OpenSSH 命令注入漏洞(CVE-2020-15778)、 OpenSSL拒绝服务漏洞 (CVE-2020-1971)、 OpenSSH 安全漏洞(CVE-2017-15906)、 OpenSSH CBC模式信息泄露漏洞(CVE-2008-5161)【原理扫描】等几个漏洞,其实仔细看一下,这些漏洞被利用的可能性极低,个人感觉某盟给出这样的结果主要是吓唬人,扫描报告好看。

过程:

想想爱升级、爱刷机的我,还是自己打 rpm 离线包给人升级了吧,于是有了这一篇 https://blog.wanjie.info/2021/02/openssh-rpm-pkg-sh/ ‎

再后来发现还是先升级 openssl合适,网上说需要 openssl-1.1.1i,然后看了下官网,修复了漏洞,于是有了这一篇  https://blog.wanjie.info/2021/02/openssl-1-1-1j-centos/

最后还有这篇,openssh 升级8.4 ,有几个文件需要修改,否则会有些错误,于是有了这篇, openssh 离线安装脚本篇

serverchan

$
0
0

实际上 sc.ftqq.com 用了好几年了,增加了一个webhook来通知到微信,作为邮件提醒的补充,场景很简单.

今天折腾tg bot的时候,突然想起给server酱也能用shell来传递简单的参数。于是定时监控了一下某节点的当前pid,定时发出。正好观察一下机器是否由于pid问题导致的无法分配内存以及无法ssh连接问题。

代码如下


#!/bin/bash
send(){
key=SCU2187T
title=Node19当前Pid个数
content=$(ps -eLf |wc -l)
curl "http://sc.ftqq.com/$key.send?text=$title&desp=$content" >/dev/null 2>&1 &
}
count=`ps -eLf |wc -l`
if [ $count -gt 100000 ];then
send
date >> /tmp/pid-history.log
ps -eLf |wc -l >> /tmp/pid-history.log
fi

然后每半小时执行一下计划任务。
收到微信通知如下图


tg bot

$
0
0

上一次用tg还是给路由器刷机的那会儿,然后还通过汉堡王的消费券快速兑换新的薯条,这么说快2年了。

今天无意间刷到tg bot,于是实践了一下,似乎只能海外服务器使用,所以后来还是继续server酱来做简单提醒。

搭建步骤中,记录2个关键信息。

登录Telegram,并找到@BotFather,然后按提示来,得到token,保存下来。

然后和自己bot开聊,开聊后,访问

https://api.telegram.org/bot<token>/getUpdates

找到

"message":{"message_id":1,"from":{"id":保密id,"is_bot,id 保存下来。

简单脚本如下。

#!/bin/bash

TOKEN=1700:马赛克 #TG机器人token
chat_ID=65马赛克 #用户ID或频道、群ID
message_text="vm测试消息" #要发送的信息
CurrentPidNum=$(ps -elf |wc -l)
MODE='HTML' #解析模式,可选HTML或Markdown
URL="https://api.telegram.org/bot${TOKEN}/sendMessage" #api接口
StickerUrl="https://api.telegram.org/bot${TOKEN}/sendSticker"
# 推送文本信息
# # 测试1:终端自定义消息
curl -s -X POST $URL -d chat_id=${chat_ID} -d parse_mode=${MODE} -d text="${CurrentPidNum}"
# 推送贴图
curl -s -X POST $StickerUrl -d sticker="CgACAgQAAxkDAAMRYFNq3KzpvZZeVt-yF3gjtHiQkCcAAhICAAL0YE1Tu20UrjRidS4eBA" -d chat_id=$chat_ID
这个sticker的id获得方式,依然和前面一样,
手机发一条自己喜欢的,然后在这里找到它,替换掉 https://api.telegram.org/bot<token>/getUpdates

最后效果如下。

how-to-connect-mirrors-cloud-aliyuncs-com

$
0
0

在阿里云环境安装某个软件包时遇到解析错误  Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error”

找到这个介绍 https://developer.aliyun.com/article/767805

mirrors.cloud.aliyuncs.com 这个域名需要阿里云vpc下dns才能解析。

vim  /etc/resolv.conf

常规写入以下内容:

options timeout:1 attempts:1 rotate
nameserver 100.100.2.136
nameserver 100.100.2.138

结果发现客户的这2行被注释了:),问题解决。

xshell-mfc110u.dll-msvcr110.dll

$
0
0

远程用的win10终端,安装绿色版xshell时提示 mfc110u.dll 等文件找不到..., 知道是c++ 环境缺失,结果还没那么简单.

https://www.microsoft.com/zh-cn/download/details.aspx?id=30679

想当然的去了微软网站,按照平台X64 下载了vcredist_64位的包,安装,结果还是报同样的错误。

查了一下,原来xshell是32位的,也要再装一份32位 vcredist包,安装后,顺利运行xshell,问题解决。

 

trojan-web

$
0
0

其实几年前就用过trojan,有台夜间线路很差的 vps上还一直挂着这个服务,利用率不高,为啥今天想起要写它呢?

小结了一下与以前比有了几点变化:

对比

过去 小结 现在 小结
端口 443 其他端口需要事先改脚本 4430 可以直接改配置文件
证书 Let's Encrypt 由于被墙的原因,和限制,申请困难 zerossl 脚本或网站单独申请,目前一次成功,未遇到申请困难的现象。
流量监控

也用不上

闲得慌时可以看看
多用户

也用不上

实际上也用不上
路由器 集成

也接过

多配了一条
clash

没接过

外出时手机和电脑多配一条

面版

安装

这次用了大牛的脚本 https://github.com/Jrohy/trojan 一行命令搞定,提前准备一个二级域名即可。

source <(curl -sL https://git.io/trojan-install)

安装过程略,这里介绍一下哪里改端口把。

cat /usr/local/etc/trojan/config.json

如图,修改 local_port 对应的端口为自己需要的新端口 , remote_port 为 web页面管理端口。

ssl 位置放证书 crt 、key 文件即可。

web管理页面默认没有启动,需要执行 trojan web 命令。

其他命令这里也转一下。

Usage:
trojan [flags]
trojan [command]

Available Commands:
add 添加用户
clean 清空指定用户流量
completion 自动命令补全(支持bash和zsh)
del 删除用户
help Help about any command
info 用户信息列表
log 查看trojan日志
restart 重启trojan
start 启动trojan
status 查看trojan状态
stop 停止trojan
tls 证书安装
update 更新trojan
updateWeb 更新trojan管理程序
version 显示版本号
import [path] 导入sql文件
export [path] 导出sql文件
web 以web方式启动

Flags:
-h, --help help for trojan

路由器或clash设置

地址端口密码正常设置,如果连接有问题的话,可以试试关闭  “允许不安全连接”,即 是否允许不安全连接。当选择时,将不会检查远端主机所提供的 TLS 证书的有效性。

 

i40e-ovs-tc

$
0
0

缘起

一个奇特的标题 i40e-ovs-tc . :smile:  起初的现象是k8s集群终端无法 ssh登陆 ,3台物理机机器都这样,提示  kex_exchange_identification: read: Connection reset by peer,通过 bmc web界面查看到疯狂刷屏的内核日志告警 "i40e 0000:18:00.0: Invalid traffic class"。

修复过程

同事提醒尝试通过 alt+f1~alt+f6 切换,效果不佳,依然疯狂刷屏,登陆很困难,半盲打状态下输入了账号密码登陆了,重启了sshd,似乎有时能登陆了,先尝试一波 更新i40e的驱动。

更新i40e驱动

驱动地址,最新版本为2.17.4

https://www.intel.com/content/www/us/en/download/18026/24411/intel-network-adapter-driver-for-pcie-40-gigabit-ethernet-network-connections-under-linux.html

大概装了这么一些包
yum -y install rpm-build rpmdevtools

开始 # rpmbuild -tb i40e-2.17.4.tar.gz,遇到报错
error: Failed build dependencies:
kernel-devel is needed by i40e-2.16.11-1.x86_64

yum install gcc kernel-header kernel-devel

继续运行,继续报错,


+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd i40e-2.16.11
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.uPhM53
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd i40e-2.16.11
+ make -C src clean
make: Entering directory `/root/rpmbuild/BUILD/i40e-2.16.11/src'
common.mk:82: *** Kernel header files not in any of the expected locations.
common.mk:83: *** Install the appropriate kernel development package, e.g.
common.mk:84: *** kernel-devel, for building kernel modules and try again. Stop.
make: Leaving directory `/root/rpmbuild/BUILD/i40e-2.16.11/src'
error: Bad exit status from /var/tmp/rpm-tmp.uPhM53 (%build)

最终一股脑全装上

yum install pcre-devel zlib-devel openssl-devel make cmake gcc gcc-c++ bison ncurses-devel rpm-build  -y
yum groupinstall "Development Tools"
大概有遇到这个报错
# Kernel Search Path # All the places we look for kernel source KSP := /lib/modules/${BUILD_KERNEL}/source \ /lib/modules/${BUILD_KERNEL}/build \ /usr/src/linux-${BUILD_KERNEL} \ /usr/src/linux-$(${BUILD_KERNEL} | sed 's/-.*//') \ /usr/src/kernel-headers-${BUILD_KERNEL} \ /usr/src/kernel-source-${BUILD_KERNEL} \ /usr/src/linux-$(${BUILD_KERNEL} | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \ /usr/src/linux \ /usr/src/kernels/${BUILD_KERNEL} \ /usr/src/kernels
解决方法,创建软连接
ln -s /usr/src/kernels/3.10.0-1160.45.1.el7.x86_64/ /usr/src/linux
再次继续编译
rpmbuild -tb i40e-2.17.4.tar.gz
编译成功,最后部分输出日志大致如下

<Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/i40e-2.17.4-1.x86_64
Wrote: /root/rpmbuild/RPMS/x86_64/i40e-2.17.4-1.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/auxiliary-1.0.0-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.n2andN
+ umask 022
+ cd /root/rpmbuild/BUILD
+ cd i40e-2.17.4
+ rm -rf /root/rpmbuild/BUILDROOT/i40e-2.17.4-1.x86_64
+ exit 0

更新驱动
rpm -Uvh i40e-2.17.4-1.x86_64.rpm
rpm -Uvh auxiliary-1.0.0-1.x86_64.rpm

查看 modinfo i40e
modinfo i40e
filename: /lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/net/ethernet/intel/i40e/i40e.ko.xz
version: 2.8.20-k
似乎一直没变,后来手动make,make install一轮
更换 rmmod i40e; modprobe i40e
dracut --force

终于完成驱动更新了,版本从2.8.20-k更新为2.17.4

ovs 和 tc

可是开机仍然报错 Invalid traffic class,查了一下代码,应该和 tc 有关

drivers/net/ethernet/intel/i40e/i40e_main.c
不懂程序,不懂网络的我晕了,赶紧请教同事,竟然是一个过渡版本的bug, ovs 里面开了一个网卡 oc offload策略,但是发现有的网卡工作不好。
就是上图蓝色框里面的东东,关闭它即可。

ovs-vsctl remove Open_vSwitch . other_config hw-offload
ovs-vsctl remove Open_vSwitch . other_config tc-policy
systemctl restart openvswitch

差不多没有遇到 Invalid traffic class 刷屏了,还有1台会出现,需要改环境变量,这里不说了,继续有坑。
ksoftriqd 疯狂吃cpu,没空查了,最终把集群环境铲掉重建了。 :lol:

k8s multi cluster management with kubeconfig

$
0
0

1. 背景

有客户咨询如何在集群外通过kubectl命令行访问 公司平台产品集群(ps. 有特殊端口),正好有同事写过一篇《配置集群外访问某产品集群》,我这边测试后,参考了k8s官网文档《配置对多集群的访问》,2者做了一些结合,于是有此实践文档。

2. 步骤

2.1. 准备kubectl命令

下载kubectl 并保存至 /usr/local/bin, 以下命令在终端中执行
# curl 下载 kubectl ,以下3行 分别是 linux、mac 、windows版本
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl /usr/local/bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/darwin/amd64/kubectl /usr/local/bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/windows/amd64/kubectl.exe
# chmod 更改文件权限
chmod 755 /usr/local/bin/kubectl

2.2. 准备 config 文件

vi ~/.kube/config,输入以下内容并保存

apiVersion: v1
clusters:
- cluster:
server: 10.10.*.*:28081
name: hd1
- cluster:
server: 172.16.*.*:48081
name: hl0
- cluster:
server: 10.22.*.*:38081
name: l0
contexts:
- context:
cluster: hd1
user: ""
name: hd1
- context:
cluster: hl0
user: ""
name: hl0
- context:
cluster: l0
user: ""
name: l0
current-context: hd1
kind: Config
preferences: {}
users: []

可以看到,我分别添加了3个集群:

10.10.*.* 网段的产品版本  3.0.8,对应名字为  hd1, 对应上下文相同hd1

172.16.*.* 网段的 产品版本3.1.4,对应名字为  hl0, 对应上下文相同hl0

以及10.22.*.* 网段的 产品版本 4.0.1,对应名字为 l0, 对应上下文相同 l0

2.3. 开放主机端口

在对应的3个机器上分别执行

iptables -t nat -I PREROUTING -d 10.10.*.* -p tcp --dport 28081 -j DNAT --to 127.0.0.1:18081
iptables -t nat -I PREROUTING -d 172.16.*.* -p tcp --dport 48081 -j DNAT --to 127.0.0.1:18081
iptables -t nat -I PREROUTING -d 10.22.*.* -p tcp --dport 38081 -j DNAT --to 127.0.0.1:18081

  • iptables -t nat -I OUTPUT -d 10.10.*.* -p tcp --dport 28081 -j DNAT --to 127.0.0.1:18081  命令 备用,
    PREROUTING链:作用是在包刚刚到达防火墙时改变它的目的地址
    OUTPUT链:改变本地产生的包的目的地址
    POSTROUTING链:在包就要离开防火墙之前改变其源地址

2.4. 检查集群上下文

kubectl config get-contexts

2.5. 切换集群

我们来使用 kubectl 本地直连各种 产品版本 集群看看效果吧

2.5.1. 切换集群hd1

切换集群hd1,简单查看 default下的 pod
kubectl config use-context hd1
kubectl get po -n default

2.5.2. 切换集群hl0

切换集群hl0,同样简单查看 default下的 pod

2.5.3. 切换集群l0

切换集群l0,同样简单查看 default下的 pod

3个集群切换测试成功

3. 参考链接

https://kubernetes.io/zh/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

 

ps,前面写了一个月后,居然一直是草稿未发布状态,今天正好看到一个管理工具 https://github.com/lensapp/lens,这里新增一张图吧,管理起来也挺有意思。

docker pull error 504 fix

$
0
0

记录一次客户私有镜像下载遭遇504的排障记录,简单脱敏。

1. 缘起

客户反馈:新构建的镜像都无法部署,拉取镜像时会出现 502 或者 504现象,无法更新应用。

我这边通过多轮测试,发现国内线路正常,日本、美国、 香港均异常,报错如下:

docker pull...

error pulling image configuration: received unexpected HTTP status: 504 Gateway Timeout(偶尔502)

2. 排查

2.1. 排查第一波

几个环境 通过 curl 命令发现海外指向的ip是A252 ,  通过同事D 沟通,这些服务对某云上名字registry-outer ,也就是某云的负载均衡机器上,国内指向 A224,名字 registry-inner。

2.2. 排查第二波

登录某云前端页面和服务器终端

海外流量访问公网IP A252, 有一个80端口 ,它后面是 某云 内网A230 里面的5000端口

2.2.1. compose部分

A230里面有一个docker-compose启动的nginx和registry,compose.yml配置如下:

root@A230:~ #cat registry_china_prod/docker-compose.yml
version: '2'
services:
registry:
container_name: hub_registry
restart: always
image: xyz/registry:v1.1
network_mode: host
volumes:
- "./key-pair:/key-pair"
- "./registry-china.yml:/etc/docker/registry/config.yml"
logging:
driver: gelf
options:
gelf-address: udp://A172:12202
nginx:
container_name: hub_nginx
restart: always
image: xyz/nginx:1.11-alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
network_mode: host
logging:
driver: gelf
options:
gelf-address: udp://A172:12202

2.2.2. registry部分

root@A230:~# cat registry_china_prod/registry-china.yml

registry使用了6000端口,主要是指向一个某云的镜像存放文件地址 file对应的bucket

version: 0.1
log:
level: info
formatter: text
storage:
maintenance:
uploadpurging:
enabled: false
delete:
enabled: false
file:
driver: file
publickey: 略
privatekey: 略
bucket: 略
uploadendpoint: 略
redirect:
disable: false
cache:
blobdescriptor: inmemory
reporting:
newrelic:
licensekey: 略
name: Hub-Registry
http:
addr: :6000
host: https://xyz
secret: thesecrethahah
headers:
X-Content-Type-Options: [nosniff]
compatibility:
schema1:
signingkeyfile: /etc/docker/registry/key.json
auth:
token:
realm: https://xyz/auth
service: xyz
issuer: hub
rootcertbundle: /key-pair/public.cert
notifications:
endpoints:
- name: A_notify
url: http://A239:4000/event
timeout: 5s
backoff: 1s
ignoredmediatypes:
- application/octet-stream

2.2.3. nginx.conf配置部分

nginx使用了 5000 端口,这个自身A230 的 5000端口 与前面 A252 的 80 对应上了。

里面还有一个 location v2对应的  proxy_pass http://A.15:9002 代理设置,也就是说下一步指向 A.15

root@A230:~# cat registry_china_prod/nginx.conf


worker_processes auto;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 900;
gzip on;
upstream registry {
server 127.0.0.1:6000;
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $request_time $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"';
access_log /var/log/nginx/access.log main;
server {
listen 5000;
server_name xyz;
chunked_transfer_encoding on;
client_max_body_size 0;
client_body_timeout 9000;
client_header_timeout 9000;
location ~ /v2/(.*)/(.*)/tags/list {
rewrite /v2/(.*)/(.*)/tags/list /wrapper/$1/$2/tags/list break;
proxy_pass http://A15:9002;
}
location ~ /v2/ {
proxy_pass http://registry;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 9000;
proxy_connect_timeout 9000;
proxy_send_timeout 9000;
send_timeout 9000;
}
location ^~ /v1/ {
proxy_pass http://registry;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 9000;
proxy_connect_timeout 9000;
proxy_send_timeout 9000;
send_timeout 9000;
}
location /ping {
add_header Content-Type "text/plain;charset=utf-8";
return 200 "OK";
}
location / {
rewrite ^/(.*) https://xyz/$1 permanent;
}
}
}

2.2.4. lb部分

前面找到的A15 是某云的 lb, 它 9002 端口后面是  2 台机器 的 6000 端口 A.97 和 A.165

诡异的事情,某云界面提示 “由于全部节点健康检查失败,*已停止服务。。“

看着是健康检查失效,一度怀疑是这里,和 同事H 看上下游服务器日志看了很久,没找到异常日志。

这些服务跑了好几年了,最近一次容器重启还是15个月前,配置肯定没问题的,陷在这里很久,

某云工程师后来回复 健康检查失败这个是 某服务未配置造成的,需要改系统参数,暂时搁置,这是后话。

2.3. 曙光

接着从头看配置文件,找到nginx 配置有 graylog 的日志部分,请教了同事F 如何查看,F发现 graylog 有组件挂了一阵,启动临时文件被锁定,F顺手修复了。

接着查看 graylog ,边做测试,没有 504 日志,说明这个504不是我们沿途服务器打出来的。

F开始使用 神器  tcpdump 抓包,果然有发现,504是某云 cdn这边给出的。

 

3. 解决方法

定位问题在某云这边后,继续联系 某云 工程师,给出多个测试地址和截图,他们海外环境也复现了。

他们一番后台调整,给我留言,“原因是后端 dns 服务器的问题,已经修复了。”

今天早上和下午多轮测试,顺利打包,问题解决。

4. 测试地址

测试方法除开 直接拖包外,拖解析的层或直接从cdn取其 cdn加速地址的 静态文件也行。

5. 后续改进

  • 了解镜像存取服务逻辑
  • 抓包解决疑难问题
  • 联系供应商排障

Android Flash Tool

$
0
0

前面看到pixel 3xl 的新版rom RP1A.201005.004, Oct 2020   https://developers.google.com/android/images

看到日期够新鲜啊,一查 2020.10.06发布的,1.69G 都下载好了,点了一下flash ,原来还能在线刷机,体验一下。

11.0.0 (RP1A.201005.004, Oct 2020) Flash Link c7b477a72ed36047dafb103d9612b8b3c8b4e12707fd073c95c117d68fee3b0b

截了几个图,在线刷机,提示设备使用中,断开其它软件即可


提示连接正常

现有设备版本11.0.0 (RP1A.200720.009, Sep 2020),新版 11.0.0 (RP1A.201005.004, Oct 2020)

同意,准备刷机

继续同意条款

再次选择设备pixel 3xl

在线下载中

竟然没用多久,更新完毕

The software has been successfully updated.
It is now safe to unplug your phone.

k8s-set-capabilities-for-a-container

$
0
0

1. 问题描述

某客户咨询如何更改某一个容器的系统时间,沟通了一番后才知道不是修改时区,是开发需要固定机器时间,设置时提示没权限,于是我这边做了复现,得到解决方法如下文。

 

2. 原因分析

简单来说,k8s默认不给容器修改时间权限,如果执行类似 "date -s 2020-10-10" 时间修改命令,会提示 “date: can't set date: Operation not permitted“

 

3. 解决方法

 

3.1. 为容器单独添加内核功能

即修改部署Deployment,在containers 字段里面加几行参数

securityContext:
        capabilities:    //该参数用于pod添加或者禁用某项内核功能
          add:
          - SYS_TIME      //添加修改系统时间参数

修改部署文件重启后,容器可以随意修改时间了。

 

4.  参考链接

change container time

$
0
0

某客户程序调试需要,希望将容器系统时间固定为某个日期 ,如 2020-09-16

我这边做了复现,默认是无法修改时间的,会提示

/ # date -s 2010-10-19
date: can't set date: Operation not permitted

经过查找资料,为 Container 设置权能才行  https://kubernetes.io/zh/docs/tasks/configure-pod-container/security-context/#set-capabilities-for-a-container

可以单独开设一些权限给容器,因此,需要修改depolyment,添加如下2个参数

securityContext:
capabilities:
add:

  • NET_ADMIN
  • SYS_TIME

添加后,重新部署的容器就可以修改时间了

/ # date -s 2020-09-16
Wed Sep 16 00:00:00 UTC 2020

npm-group 500 with

$
0
0

客户反馈,nexus仓库下npm拖包,当使用npm-group时,报错500,无法下载,直接使用npm-proxy时,反而顺利拖包。

这简直不符合常理,一般group含的源要多于单独的proxy。

检查发现npm-proxy实际仅有 官网地址http://registry.npmjs.org/。

一边开启nexus日志详细模式,

  • 更改 nexus 日志级别,org.sonatype.nexus.repository 从 info 设置为 debug

一边拖包时加上详情参数,然后做了几组实验。

先说第一个结论, registry.npm.taobao.org这边的问题,当npm-group含了 registry.npm.taobao.org ,拖包会报错。

客户新疑问来了,npm-group里面含了 私有库地址 abc、官网 http://registry.npmjs.org/,  最后才是 taobao地址 ,按照通用逻辑,优先级别依次往下。

实际上,我后来在官网找到了这段说明,顺序是有优先级别意义的。
https://help.sonatype.com/repomanager3/repository-management?_ga=2.116980102.1037975644.1605598044-1818828394.1605598044#RepositoryManagement-RepositoryGroup

Note that the order of the repositories listed in the Member section is important. When the repository manage searches for a component in a repository group, it will return the first match. To reorder a repository in this list, click and the drag the repositories and groups in the Members list or use the arrow buttons between the Available and Members list. These arrows can be used to add and remove repositories as well.

后来找到网友的测试 https://my.oschina.net/polly/blog/2120650

https://swenfang.github.io/2018/06/03/Maven-Priority/

最终结论
settings_mirror 的优先级高于 central
settings_profile_repo 优先级高于 settings_mirror
settings_profile_repo 优先级高于 pom_repositories
settings_profile_repo 优先级高于 pom_profile_repo
pom_profile_repo 优先级高于 pom_repositories
pom_repositories 优先级高于 settings_mirror
通过上面的比较得出完整的搜索链:

local_repo > settings_profile_repo > pom_profile_repo > pom_repositories > settings_mirror > central

也就是这段优先级别符合实际情况一点,有机会再研究这个吧。

 

kubectl-cheatsheet

$
0
0

1. 背景

某客户咨询 kubectl 命令行实现k8s服务的重启和镜像版本的更新方法,参考k8s官网  https://kubernetes.io/zh/docs/reference/kubectl/cheatsheet/  整理出2个对应的步骤介绍。

 

2. 步骤

 

2.1. 服务重启

服务重启一般有2种方式,直接删除pod,实现重启;或者修改 ReplicaSet 的方法实现重启。

 

2.1.1. 得到pod名称

kubectl get po -n default

 

2.1.2. 删除pod

已 alpine为例

kubectl delete po alpine-alpine-576f9f8b49-tq284 -n default

重启完成

 

2.1.3. 修改replicas方法

修改 ReplicaSet 的方法实现重启,数量 scale 到 0,然后又 scale 到 1,那么 Pod 也就重启了。

kubectl get deploy -n default

kubectl scale deployment --replicas=0 alpine-alpine -n default

kubectl scale deployment --replicas=1 alpine-alpine -n default

2.2. 镜像更新

2.2.1. 首次更新

编辑查看 deployment内容,

kubectl get deploy -n default

以 alpine为例

kubectl edit deployment alpine-alpine -n default

直接修改相关内容即可自动更新 , 找到当中的 image字段和name字段,观察镜像版本得知为alpine:0.04,名字为alpine-alpine

我们替换成其他版本 alpine:0.05 或 alpine:latest, 提示编辑完成

2.2.2. 后续更新

前面得到版本和名称后,后续更新只需要一行命令即可,命令如下:

更换alpine的镜像地址或版本即可

kubectl set image deployment/alpine-alpine alpine-alpine=10.10.150.105/myapp/alpine:0.05

更新完成提示  deployment.apps "alpine-alpine" image updated

3. 参考链接

Viewing all 82 articles
Browse latest View live