晨曦's Blog

This is a window to the soul

安装

1
2
3
4
wget -c https://ghproxy.com/https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_exporter-0.25.0.linux-amd64.tar.gz
tar -zxvf blackbox_exporter-0.25.0.linux-amd64.tar.gz
mkdir /opt/blackbox_exporter
cp blackbox_exporter-0.25.0.linux-amd64/blackbox_exporter /opt/blackbox_exporter/blackbox_exporter

config

vim /opt/blackbox_exporter/config.yml

1
2
3
4
5
6
7
8
9
modules:
http_2xx:
prober: http
http:
method: GET
http_post_2xx:
prober: http
http:
method: POST

service

vim /usr/lib/systemd/system/blackbox_exporter.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Blackbox Exporter
Documentation=https://github.com/prometheus/blackbox_exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/opt/blackbox_exporter/blackbox_exporter \
--config.file=/opt/blackbox_exporter/config.yml \
--web.listen-address=:9116
Restart=always

[Install]
WantedBy=multi-user.target

启动

1
2
3
systemctl daemon-reload
systemctl start blackbox_exporter
systemctl enable blackbox_exporter

测试

1
curl -iv "http://127.0.0.1:9116/probe?module=http_2xx&target=baidu.com"

Prometheus 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- job_name: 'blackbox'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- http://10.113.75.134:5000/v1/datasets/8a9302de-ded1-493c-8a12-e8acf3d80772/files?apikey=ka-admin123
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
regex: '(http|https)://([^/]+)/.*'
replacement: '${2}'
target_label: site
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9116

问题排查

1
journalctl -xe -u blackbox_exporter

参考:

https://flashcat.cloud/docs/content/flashcat-partner/prometheus/exporter/commonly/blackbox-exporter/

错误

1
No route to host

原因

目标服务器防火墙导致

解决

1
2
3
4
5
systemctl status firewalld

systemctl stop firewalld

systemctl disable firewalld

1
2
3
4
5
6
RUN yum install -y kde-l10n-Chinese && \
yum install -y glibc-common && \
localedef -c -f UTF-8 -i zh_CN zh_CN.utf8

# ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8

错误

1
2
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=container error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

解决

1
2
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo

替换成华为源

参考:

https://developer.aliyun.com/mirror/centos

https://mirrors.huaweicloud.com/mirrorDetail/5ea14ecab05943f36fb75ee5

ansible

1
2
3
4
5
6
7
8
9
10
11
12
13
# 1、安装yumdownloader
yum install yum-utils -y

# 2、获取ansible安装包及依赖
mkdir /tmp/ansible
yumdownloader --resolve --destdir /tmp/ansible ansible
tar zcf ansible.tar.gz /tmp/ansible

# 3、在离线服务器上解压压缩包
tar zxf /tmp/ansible.tar.gz

# 4、执行安装
rpm -ivh ansible-2.9.27-1.el7.noarch.rpm

参考:

https://github.com/wgrice/notebook/blob/master/devops/ansible/ansible%E7%A6%BB%E7%BA%BF%E5%AE%89%E8%A3%85.md

Mac

https://github.com/ktver/NgX 注:会修改底层 Wifi 中的代理设置

Win

https://github.com/2dust/v2rayN

https://github.com/KevinSHIT/NaiveSharp

参考

https://github.com/klzgrad/naiveproxy/issues/158

NgX

  1. NgX 不要给超管,会起一个 socks5 的代理在 10800 端口上
  2. 可以手动在电脑 Wifi - 详细信息 - 代理 中设置 SOCKS 代理,用以利用 NgX 的代理规则
  3. 可以设置不走代理域,如:* .jakehu.me,192.168. .*

CentOS:

1
2
3
4
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc

MacOS:

1
2
$ brew install bash-completion
$ kubectl completion bash > $(brew --prefix)/etc/bash_completion.d/kubectl

参考:

https://kubernetes.io/docs/tasks/tools/#enabling-shell-autocompletion

https://github.com/xujiyou/blog-data/blob/master/%E4%BA%91%E5%8E%9F%E7%94%9F/Kubernetes/K8sFAQ.md

现象

k8s 集群某一个节点 kubelet 挂了,无法启动

错误

1
2
# cat /var/log/messages | grep kubelet | grep failed
failed to run Kubelet: unable to load bootstrap kubeconfig: stat /etc/kubernetes/bootstrap-kubelet.conf: no such file or directory

解决

1
2
3
4
5
6
7
8
rm -rf /var/lib/kubelet/pki/

# 大于1.20的版本
kubectl get cm kubeadm-config -n kube-system -o=jsonpath="{.data.ClusterConfiguration}" > kubeadm.yaml
kubeadm kubeconfig user --org system:nodes --client-name system:node:$(hostname) --config kubeadm.yaml > /etc/kubernetes/kubelet.conf

# 小于1.20的版本
kubeadm alpha kubeconfig user --org system:nodes --client-name system:node:$(hostname) > /etc/kubernetes/kubelet.conf

其他解决方案

参考:https://blog.csdn.net/margu_168/article/details/135844420

1
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

注册表 & 加速

参考:https://github.com/abiosoft/colima/issues/834

比起加速,代理更快

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 设置
colima start --edit
docker:
insecure-registries:
- harbor.jakehu.me:31104
registry-mirrors:
- https://docker.registry.huwenxi.com

# 查看配置
colima ssh -- cat /etc/docker/daemon.json; echo
{
"exec-opts": [
"native.cgroupdriver=cgroupfs"
],
"features": {
"buildkit": true
},
"host-gateway-ip": "192.168.5.2",
"insecure-registries": [
"harbor.jakehu.me:31104"
],
"registry-mirrors": [
"https://docker.registry.huwenxi.com"
]
}

Docker 代理

参考:https://github.com/abiosoft/colima/issues/294

1
2
3
4
5
6
7
8
9
# 设置
colima start --edit
env:
HTTP_PROXY: http://10.168.64.147:1080
HTTPS_PROXY: http://10.168.64.147:1080
NO_PROXY: localhost,127.0.0.1,y2-harbor.geega.com,y2-harbor.geega.com:31104

# 校验
docker info | grep "Proxy"

0%