当Harbor和负载均衡软件haproxy安装在同一台机器时,安装harbor会报端口冲突。
所以需要修改Harbor配置文件的默认端口。
用shell实现下面文件内容修改:
修改harbor配置文件/opt/harbor/harbor.yml中的两个端口信息
要修改Harbor配置文件中的端口,可以使用以下Shell脚本:
bash
#!/bin/bash
# 定义要修改的配置文件和端口
config_file="/opt/harbor/harbor.yml"
http_port="9080"
https_port="9443"
# 修改HTTP端口
sed -i '/^http:/,/^[^[:space:]#]/ {
/^[[:space:]]*port:[[:space:]]*80[[:space:]]*$/ {
s/80/'$http_port'/
}
}' "$config_file"
# 修改HTTPS端口
sed -i '/^https:/,/^[^[:space:]#]/ {
/^[[:space:]]*port:[[:space:]]*443[[:space:]]*$/ {
s/443/'$https_port'/
}
}' "$config_file"
echo "端口已修改完成"
脚本说明:
-
精确范围匹配:
-
使用模式
/^http:/,/^[^[:space:]#]/定位整个http:配置块 -
使用模式
/^https:/,/^[^[:space:]#]/定位整个https:配置块
-
-
精确端口匹配:
-
^[[:space:]]*port:[[:space:]]*80[[:space:]]*$确保只匹配包含port: 80的行 -
^[[:space:]]*port:[[:space:]]*443[[:space:]]*$确保只匹配包含port: 443的行
-
-
安全修改:
-
只替换端口数字部分(
s/80/.../和s/443/.../) -
保留原有缩进格式和注释内容
-
-
直接生效:
-
使用
sed -i直接修改原文件 -
不需要生成临时文件
-
使用说明:
-
将脚本保存为
modify_harbor_ports.sh -
添加执行权限:
bash
chmod +x modify_harbor_ports.sh
-
执行脚本:
bash
sudo ./modify_harbor_ports.sh
预期修改效果:
diff
# http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port - port: 80 + port: 9080 # https related config https: # https port for harbor, default is 443 - port: 443 + port: 9443
注意:脚本需要以root权限运行(因文件路径在/opt下)。如果您的环境不同,请调整配置文件路径。
189

被折叠的 条评论
为什么被折叠?



