[init] 增加octopus agent的部分
This commit is contained in:
@@ -4,27 +4,29 @@
|
|||||||
# set -o nounset
|
# set -o nounset
|
||||||
# set -o pipefail
|
# set -o pipefail
|
||||||
|
|
||||||
|
docker_version=20.10.10
|
||||||
|
oss_url_prefix="https://oss-s1.107421.xyz"
|
||||||
|
modify_ssh_port=22333
|
||||||
|
octopus_agent_path=/usr/local/etc/octpus-agent/
|
||||||
|
octopus_agent_url=https://happybirthday.107421.xyz/octopus-agent/
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
mkdir -p /root/wdd/lib/
|
mkdir -p ${octopus_agent_path}/lib/
|
||||||
lib_file_list=(wdd-lib-log.sh wdd-lib-sys.sh)
|
lib_file_list=(wdd-lib-log.sh wdd-lib-sys.sh)
|
||||||
for lib_file in ${lib_file_list[@]}; do
|
for lib_file in ${lib_file_list[@]}; do
|
||||||
wget "https://oss-s1.107421.xyz/${lib_file}" -qO "/root/wdd/lib/${lib_file}"
|
wget "${oss_url_prefix}/${lib_file}" -qO "${octopus_agent_path}/lib/${lib_file}"
|
||||||
echo "加载库文件 < /root/wdd/lib/${lib_file}"
|
echo "加载库文件 < ${octopus_agent_path}/lib/${lib_file}"
|
||||||
. "/root/wdd/lib/${lib_file}"
|
. "${octopus_agent_path}/lib/${lib_file}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# debug
|
# debug
|
||||||
#lib_file_list=(wdd-lib-sys.sh wdd-lib-log.sh )
|
#lib_file_list=(wdd-lib-sys.sh wdd-lib-log.sh )
|
||||||
#for lib_file in ${lib_file_list[@]} ; do
|
#for lib_file in ${lib_file_list[@]} ; do
|
||||||
# echo "加载库文件 < /root/wdd/lib/${lib_file}"
|
# echo "加载库文件 < ${octopus_agent_path}/lib/${lib_file}"
|
||||||
# . "/root/wdd/lib/${lib_file}"
|
# . "${octopus_agent_path}/lib/${lib_file}"
|
||||||
#done
|
#done
|
||||||
|
|
||||||
docker_version=20.10.10
|
|
||||||
oss_url_prefix="https://oss-s1.107421.xyz"
|
|
||||||
modify_ssh_port=22333
|
|
||||||
|
|
||||||
# 脚本执行内容
|
# 脚本执行内容
|
||||||
deploy_in_cn=0
|
deploy_in_cn=0
|
||||||
is_shutdown_firewall=0
|
is_shutdown_firewall=0
|
||||||
@@ -36,6 +38,8 @@ is_install_zsh=0
|
|||||||
is_install_host=0
|
is_install_host=0
|
||||||
is_modify_ssh_login=0
|
is_modify_ssh_login=0
|
||||||
is_modify_ssh_port=0
|
is_modify_ssh_port=0
|
||||||
|
is_install_agent=0
|
||||||
|
is_remove_agent=0
|
||||||
# 脚本执行内容
|
# 脚本执行内容
|
||||||
|
|
||||||
## 安装所需要的程序,及依赖程序
|
## 安装所需要的程序,及依赖程序
|
||||||
@@ -754,6 +758,130 @@ common_tool_install() {
|
|||||||
FunctionEnd
|
FunctionEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_octopus_agent(){
|
||||||
|
|
||||||
|
FunctionStart "清理Octopus Agent"
|
||||||
|
|
||||||
|
if not systemctl status octopus-agent.service; then
|
||||||
|
log "octopus agent 没有安装! 直接返回"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 关闭服务
|
||||||
|
systemctl stop octopus-agent.service
|
||||||
|
sleep 2
|
||||||
|
SplitLine
|
||||||
|
systemctl disable octopus-agent.service
|
||||||
|
SplitLine
|
||||||
|
rm -rf /etc/systemd/system/octopus-agent.service
|
||||||
|
sleep 1
|
||||||
|
systemctl daemon-reload
|
||||||
|
# 删除残留
|
||||||
|
SplitLine
|
||||||
|
rm -rf ${octopus_agent_path}
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
}
|
||||||
|
daemon_octopus_agent(){
|
||||||
|
# https://www.baeldung.com/linux/run-java-application-as-service
|
||||||
|
FunctionStart "[守护]-开始设置Agent的守护进程"
|
||||||
|
|
||||||
|
cat >/etc/systemd/system/octopus-agent.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Octopus Agent Service
|
||||||
|
Documentation=https://octopus.107421.xyz/
|
||||||
|
After=syslog.target network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
SuccessExitStatus=143
|
||||||
|
SyslogIdentifier=octopus-agent
|
||||||
|
User=root
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/octopus-agent
|
||||||
|
ExecStart=/octopus-agent/octopus-agent -agentServerInfoConf=/octopus-agent/octopus-agent.conf -version=shanghai
|
||||||
|
ExecStop=/bin/kill -15 \$MAINPID
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
colorEchoBlue "开始配置Agent日志输出文件!"
|
||||||
|
# https://www.benzhu.xyz/linux12/
|
||||||
|
cat >/etc/rsyslog.d/octopus-agent.conf <<EOF
|
||||||
|
if \$programname == 'octopus-agent' then /var/log/octopus-agent.log
|
||||||
|
& stop
|
||||||
|
EOF
|
||||||
|
|
||||||
|
rsyslogd -N1 -f /etc/rsyslog.d/octopus-agent.conf
|
||||||
|
systemctl restart rsyslog
|
||||||
|
|
||||||
|
FunctionEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
install_octopus_agent(){
|
||||||
|
FunctionStart "安装 Octopus Agent"
|
||||||
|
|
||||||
|
colorEchoBlue "开始检查最新的版本!"
|
||||||
|
local latest_version=$(curl $octopus_agent_url | grep -v h1 | grep "a href=" | head -1 | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-)
|
||||||
|
|
||||||
|
log "查询得到的Octopus Agent的最新版本为 => ${latest_version}"
|
||||||
|
SplitBlue
|
||||||
|
# Agent二进制文件的命名规则为 octopus-agent_linux_amd64_<version>
|
||||||
|
local agent_latest_version="octopus-agent_linux_${linux_release}_${latest_version}"
|
||||||
|
colorEchoBlue "octopus agent latest version is => [ $agent_latest_version ]"
|
||||||
|
|
||||||
|
log "开始下载最新版本的Octopus Agent !"
|
||||||
|
wget "${octopus_agent_url}${agent_latest_version}" -qO "${octopus_agent_path}${agent_latest_version}"
|
||||||
|
SplieGreen
|
||||||
|
cp "$agent_latest_version" octopus-agent
|
||||||
|
chmod +x octopus-agent
|
||||||
|
echo ""
|
||||||
|
colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------"
|
||||||
|
ls ${octopus_agent_path} | grep octopus-agent
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
log "开始下载 Octopus Agent Config !"
|
||||||
|
wget "${oss_url_prefix}/octopus-agent.yaml" -qO "${octopus_agent_path}octopus-agent.yaml"
|
||||||
|
echo ""
|
||||||
|
colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------"
|
||||||
|
ls ${octopus_agent_path} | grep ".yaml"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
log "开始配置Agent启动的基础环境信息"
|
||||||
|
rm -rf "$octopus_agent_path/lib/wdd-lib-env.sh"
|
||||||
|
wget "${oss_url_prefix}/wdd-lib-env.sh" -qO "${octopus_agent_path}/lib/wdd-lib-env.sh"
|
||||||
|
SplitGreen
|
||||||
|
log "开始手机Agent主机的信息!"
|
||||||
|
echo ""
|
||||||
|
${octopus_agent_path}/lib/wdd-lib-env.sh
|
||||||
|
echo ""
|
||||||
|
SplitGreen
|
||||||
|
|
||||||
|
daemon_octopus_agent
|
||||||
|
|
||||||
|
log "开始启动 Octopus Agent!"
|
||||||
|
|
||||||
|
systemctl daemon-reload
|
||||||
|
sleep 1
|
||||||
|
systemctl enable octopus-agent.service
|
||||||
|
systemctl restart octopus-agent.service
|
||||||
|
|
||||||
|
cat - 1>&2 <<EOF
|
||||||
|
|
||||||
|
查看Octopus Agent的运行日志 👇
|
||||||
|
|
||||||
|
tail -f -n 1500 /var/log/octopus-agent.log
|
||||||
|
|
||||||
|
journalctl -u octopus-agent.service -n 200 -f
|
||||||
|
|
||||||
|
----------------------------
|
||||||
|
查看 Octopus Agent的运行状态 systemctl status octopus-agent.service -l
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
FunctionEnd
|
||||||
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# description
|
# description
|
||||||
# Arguments:
|
# Arguments:
|
||||||
@@ -781,6 +909,9 @@ help() {
|
|||||||
# 不安装docker的初始化
|
# 不安装docker的初始化
|
||||||
$base_init_command --cn
|
$base_init_command --cn
|
||||||
|
|
||||||
|
# 启动 Octopus Agent
|
||||||
|
$base_init_command --agent-install
|
||||||
|
|
||||||
-h, --help 打印本说明文档
|
-h, --help 打印本说明文档
|
||||||
--firewall 关闭防火墙
|
--firewall 关闭防火墙
|
||||||
--swap 关闭Swap
|
--swap 关闭Swap
|
||||||
@@ -794,6 +925,9 @@ help() {
|
|||||||
--ssh-login 修改ssh的登录密钥
|
--ssh-login 修改ssh的登录密钥
|
||||||
--ssh-port <port> 修改ssh的登录端口 端口 <port>
|
--ssh-port <port> 修改ssh的登录端口 端口 <port>
|
||||||
|
|
||||||
|
--agent-install 安装 Octopus-Agent
|
||||||
|
--agent-remove 卸载 Octopus-Agent
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -837,6 +971,12 @@ while [[ $# -gt 0 ]]; do
|
|||||||
is_modify_ssh_port=1
|
is_modify_ssh_port=1
|
||||||
modify_ssh_port=$2
|
modify_ssh_port=$2
|
||||||
;;
|
;;
|
||||||
|
--agent-install)
|
||||||
|
is_install_agent=1
|
||||||
|
;;
|
||||||
|
--agent-remove)
|
||||||
|
is_remove_agent=1
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
# unknown option
|
# unknown option
|
||||||
;;
|
;;
|
||||||
@@ -902,6 +1042,16 @@ main() {
|
|||||||
change_docker_register_mirror
|
change_docker_register_mirror
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $is_install_agent -eq 1 ]]; then
|
||||||
|
# 安装agent
|
||||||
|
install_octopus_agent
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $is_remove_agent -eq 1 ]]; then
|
||||||
|
# 卸载agent
|
||||||
|
remove_octopus_agent
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $is_install_zsh -eq 1 ]]; then
|
if [[ $is_install_zsh -eq 1 ]]; then
|
||||||
# 安装宇宙第一shell的zsh
|
# 安装宇宙第一shell的zsh
|
||||||
install_zsh
|
install_zsh
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ CleanOracleAgent() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
rm -rf /root/snap
|
rm -rf /root/snap
|
||||||
|
rm -rf /var/snap
|
||||||
|
rm -rf /usr/bin/snap
|
||||||
|
rm -rf /snap/
|
||||||
FunctionSuccess
|
FunctionSuccess
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# 系统相关
|
# 系统相关
|
||||||
LinuxReleaseVersion=""
|
linux_release_version=""
|
||||||
LinuxRelease=""
|
linux_release=""
|
||||||
OS_BIT=""
|
OS_BIT=""
|
||||||
CMD_INSTALL="apt-get -y -qq install"
|
CMD_INSTALL="apt-get -y -qq install"
|
||||||
CMD_UPDATE="apt-get -qq update"
|
CMD_UPDATE="apt-get -qq update"
|
||||||
@@ -47,23 +47,23 @@ check_sys() {
|
|||||||
case $sys_bit in
|
case $sys_bit in
|
||||||
i[36]86)
|
i[36]86)
|
||||||
OS_BIT="32"
|
OS_BIT="32"
|
||||||
LinuxRelease="386"
|
linux_release="386"
|
||||||
;;
|
;;
|
||||||
x86_64)
|
x86_64)
|
||||||
OS_BIT="64"
|
OS_BIT="64"
|
||||||
LinuxRelease="amd64"
|
linux_release="amd64"
|
||||||
;;
|
;;
|
||||||
*armv6*)
|
*armv6*)
|
||||||
OS_BIT="arm"
|
OS_BIT="arm"
|
||||||
LinuxRelease="arm6"
|
linux_release="arm6"
|
||||||
;;
|
;;
|
||||||
*armv7*)
|
*armv7*)
|
||||||
OS_BIT="arm"
|
OS_BIT="arm"
|
||||||
LinuxRelease="arm7"
|
linux_release="arm7"
|
||||||
;;
|
;;
|
||||||
*aarch64* | *armv8*)
|
*aarch64* | *armv8*)
|
||||||
OS_BIT="arm64"
|
OS_BIT="arm64"
|
||||||
LinuxRelease="arm64"
|
linux_release="arm64"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "
|
error "
|
||||||
@@ -72,27 +72,27 @@ check_sys() {
|
|||||||
" && exit 1
|
" && exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
log "获取的系统信息如下: OS_BIT => ${OS_BIT} LinuxRelease => $LinuxRelease"
|
log "获取的系统信息如下: OS_BIT => ${OS_BIT} LinuxRelease => $linux_release"
|
||||||
|
|
||||||
## 判定Linux的发行版本
|
## 判定Linux的发行版本
|
||||||
if [ -f /etc/redhat-release ]; then
|
if [ -f /etc/redhat-release ]; then
|
||||||
LinuxReleaseVersion="centos"
|
linux_release_version="centos"
|
||||||
elif cat /etc/issue | grep -Eqi "debian"; then
|
elif cat /etc/issue | grep -Eqi "debian"; then
|
||||||
LinuxReleaseVersion="debian"
|
linux_release_version="debian"
|
||||||
elif cat /etc/issue | grep -Eqi "ubuntu"; then
|
elif cat /etc/issue | grep -Eqi "ubuntu"; then
|
||||||
LinuxReleaseVersion="ubuntu"
|
linux_release_version="ubuntu"
|
||||||
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
|
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
|
||||||
LinuxReleaseVersion="centos"
|
linux_release_version="centos"
|
||||||
elif cat /proc/version | grep -Eqi "debian"; then
|
elif cat /proc/version | grep -Eqi "debian"; then
|
||||||
LinuxReleaseVersion="debian"
|
linux_release_version="debian"
|
||||||
elif cat /proc/version | grep -Eqi "ubuntu"; then
|
elif cat /proc/version | grep -Eqi "ubuntu"; then
|
||||||
LinuxReleaseVersion="ubuntu"
|
linux_release_version="ubuntu"
|
||||||
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
|
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
|
||||||
LinuxReleaseVersion="centos"
|
linux_release_version="centos"
|
||||||
else
|
else
|
||||||
LinuxReleaseVersion=""
|
linux_release_version=""
|
||||||
fi
|
fi
|
||||||
log "系统参数信息如下: LinuxReleaseVersion => $LinuxReleaseVersion"
|
log "系统参数信息如下: LinuxReleaseVersion => $linux_release_version"
|
||||||
|
|
||||||
# 判断系统的包管理工具 apt, yum, or zypper
|
# 判断系统的包管理工具 apt, yum, or zypper
|
||||||
getPackageManageTool() {
|
getPackageManageTool() {
|
||||||
|
|||||||
Reference in New Issue
Block a user