[init] 修改大量代码
This commit is contained in:
@@ -9,6 +9,7 @@ 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
|
||||
agent_config_url=https://happybirthday.107421.xyz/agent-config
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
@@ -73,7 +74,7 @@ install_demand_softwares() {
|
||||
# Globals:
|
||||
# BLUE
|
||||
# GREEN
|
||||
# LinuxReleaseVersion
|
||||
# linux_release_version
|
||||
# Arguments:
|
||||
# None
|
||||
#######################################
|
||||
@@ -85,15 +86,15 @@ shutdown_firewall() {
|
||||
systemctl disable firewalld
|
||||
SplitBlue
|
||||
|
||||
if [ "${LinuxReleaseVersion}" = "centos" ]; then
|
||||
colorEchoGreen "当前系统的发行版为-- ${LinuxReleaseVersion}!!"
|
||||
if [ "${linux_release_version}" = "centos" ]; then
|
||||
colorEchoGreen "当前系统的发行版为-- ${linux_release_version}!!"
|
||||
SplitGreen
|
||||
log "开始关闭SELinux……"
|
||||
setenforce 0
|
||||
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
|
||||
colorEchoGreen " SELinux关闭完成 "
|
||||
else
|
||||
colorEchoGreen "当前系统的发行版为-- ${LinuxReleaseVersion}!!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${linux_release_version}!!"
|
||||
systemctl stop ufw
|
||||
systemctl disable ufw
|
||||
colorEchoGreen "无需关闭SELinux,现在 跳过"
|
||||
@@ -112,7 +113,7 @@ shutdown_firewall() {
|
||||
add_octopus_host() {
|
||||
FunctionStart "添加Octopus自定义Hosts!"
|
||||
|
||||
cat >/etc/hosts<<EOF
|
||||
cat >/etc/hosts <<EOF
|
||||
127.0.0.1 localhost $(hostname)
|
||||
# The following lines are desirable for IPv6 capable hosts
|
||||
::1 ip6-localhost ip6-loopback
|
||||
@@ -125,12 +126,10 @@ ff02::3 ip6-allhosts
|
||||
|
||||
EOF
|
||||
|
||||
|
||||
log "开始下载 自定义的Hosts文件"
|
||||
wget "$oss_url_prefix/wdd-server-host.txt" -O /tmp/wdd-server-host.txt
|
||||
cat /tmp/wdd-server-host.txt >>/etc/hosts
|
||||
|
||||
|
||||
if grep -q "140.238" </etc/hosts; then
|
||||
colorEchoGreen "自定义hosts添加成功!"
|
||||
SplitGreen
|
||||
@@ -190,7 +189,7 @@ EOF
|
||||
# deploy_in_cn
|
||||
# docker_version
|
||||
# GREEN
|
||||
# LinuxReleaseVersion
|
||||
# linux_release_version
|
||||
# RED
|
||||
# pre_one
|
||||
# Arguments:
|
||||
@@ -216,10 +215,10 @@ install_docker() {
|
||||
colorEchoGreen "----------docker环境清理完成----------"
|
||||
SplitGreen
|
||||
|
||||
colorEchoGreen "当前系统的发行版为-- ${LinuxReleaseVersion}!!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${linux_release_version}!!"
|
||||
SplitLine
|
||||
|
||||
if [[ $LinuxReleaseVersion == "centos" ]]; then
|
||||
if [[ $linux_release_version == "centos" ]]; then
|
||||
## 安装docker的依赖
|
||||
log "正在安装安装docker的依赖"
|
||||
install_demand_softwares yum-utils device-mapper-persistent-data lvm2 || return $?
|
||||
@@ -666,7 +665,7 @@ modify_ssh_port() {
|
||||
else
|
||||
if sed -i "/^#Port 22/a Port ${modify_ssh_port}" $ssh_config_file; then
|
||||
log "ssh的登陆端口已被修改为${modify_ssh_port},请修改防火墙以开放该端口!!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
SplitGreen
|
||||
|
||||
@@ -713,7 +712,7 @@ modify_ssh_login() {
|
||||
ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa
|
||||
fi
|
||||
|
||||
if grep $(cut -d " " -f3 < ~/.ssh/id_rsa.pub) < ~/.ssh/authorized_keys; then
|
||||
if grep $(cut -d " " -f3 <~/.ssh/id_rsa.pub) <~/.ssh/authorized_keys; then
|
||||
log "本机的ssh-key信息已经写入,跳过!"
|
||||
else
|
||||
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
|
||||
@@ -744,45 +743,75 @@ modify_ssh_login() {
|
||||
common_tool_install() {
|
||||
FunctionStart "安装Linux常用工具"
|
||||
|
||||
colorEchoGreen "当前系统的发行版为-- ${LinuxReleaseVersion} !!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${LinuxReleaseVersion} !!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${LinuxReleaseVersion} !!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${linux_release_version} !!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${linux_release_version} !!"
|
||||
colorEchoGreen "当前系统的发行版为-- ${linux_release_version} !!"
|
||||
echo ""
|
||||
if [[ ${LinuxReleaseVersion} == "centos" ]]; then
|
||||
if [[ ${linux_release_version} == "centos" ]]; then
|
||||
local centos_common_tool=(deltarpm net-tools iputils bind-utils lsof curl wget vim mtr htop)
|
||||
install_demand_softwares ${centos_common_tool[@]}
|
||||
elif [[ ${LinuxReleaseVersion} == "ubuntu" ]] || [[ ${LinuxReleaseVersion} == "debian" ]]; then
|
||||
elif [[ ${linux_release_version} == "ubuntu" ]] || [[ ${linux_release_version} == "debian" ]]; then
|
||||
local ubuntu_common_tool=(iputils-ping net-tools dnsutils lsof curl wget mtr-tiny vim htop lrzsz)
|
||||
install_demand_softwares ${ubuntu_common_tool[@]}
|
||||
fi
|
||||
FunctionEnd
|
||||
}
|
||||
|
||||
remove_octopus_agent(){
|
||||
#######################################
|
||||
# description
|
||||
# Globals:
|
||||
# octopus_agent_path
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# 0 ...
|
||||
#######################################
|
||||
remove_octopus_agent() {
|
||||
|
||||
FunctionStart "清理Octopus Agent"
|
||||
|
||||
if not systemctl status octopus-agent.service; then
|
||||
log "octopus agent 没有安装! 直接返回"
|
||||
local systemd_config_path=("/lib/systemd/system/" "/etc/systemd/system/")
|
||||
|
||||
local systemd_config_file
|
||||
local agent_installed=0
|
||||
for systemd_config_file in ${systemd_config_path[@]}; do
|
||||
if ls "${systemd_config_file}"* | grep -q octopus-agent.service; then
|
||||
agent_installed=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $agent_installed -eq 0 ]]; then
|
||||
log "octopus agent 没有安装! 卸载成功!"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 关闭服务
|
||||
log "开始关闭OctopusAgent的服务!"
|
||||
systemctl stop octopus-agent.service
|
||||
sleep 2
|
||||
SplitLine
|
||||
systemctl disable octopus-agent.service
|
||||
SplitLine
|
||||
|
||||
log "删除OctopusAgent的守护进程配置文件!"
|
||||
rm -rf /etc/systemd/system/octopus-agent.service
|
||||
sleep 1
|
||||
systemctl daemon-reload
|
||||
# 删除残留
|
||||
SplitLine
|
||||
log "删除OctopusAgent的文件残留!"
|
||||
rm -rf ${octopus_agent_path}
|
||||
rm -rf "${octopus_agent_path}/lib"
|
||||
FunctionEnd
|
||||
|
||||
}
|
||||
daemon_octopus_agent(){
|
||||
#######################################
|
||||
# description
|
||||
# Globals:
|
||||
# octopus_agent_path
|
||||
# Arguments:
|
||||
# None
|
||||
#######################################
|
||||
daemon_octopus_agent() {
|
||||
# https://www.baeldung.com/linux/run-java-application-as-service
|
||||
FunctionStart "[守护]-开始设置Agent的守护进程"
|
||||
|
||||
@@ -818,11 +847,23 @@ EOF
|
||||
FunctionEnd
|
||||
}
|
||||
|
||||
install_octopus_agent(){
|
||||
#######################################
|
||||
# description
|
||||
# Globals:
|
||||
# agent_config_url
|
||||
# file_array
|
||||
# linux_release
|
||||
# octopus_agent_path
|
||||
# octopus_agent_url
|
||||
# oss_url_prefix
|
||||
# Arguments:
|
||||
# None
|
||||
#######################################
|
||||
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-)
|
||||
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
|
||||
@@ -832,17 +873,28 @@ install_octopus_agent(){
|
||||
|
||||
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
|
||||
SplitGreen
|
||||
cp "${octopus_agent_path}/$agent_latest_version" "${octopus_agent_path}/octopus-agent"
|
||||
chmod +x "${octopus_agent_path}/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 ""
|
||||
rm -rf index.html
|
||||
|
||||
local agentConfigFileList=$(curl "$agent_config_url/" | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4- | tr "\n" " ")
|
||||
|
||||
IFS=" " read -ra file_array <<<"$agentConfigFileList"
|
||||
|
||||
local agent_config
|
||||
for agent_config in "${file_array[@]}"; do
|
||||
colorEchoBlue "agent config file is => $agent_config"
|
||||
wget -q "$agent_config_url/$agent_config" -qO "${octopus_agent_path}/$agent_config"
|
||||
echo ""
|
||||
done
|
||||
|
||||
colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------"
|
||||
ls ${octopus_agent_path} | grep ".yaml"
|
||||
echo ""
|
||||
@@ -851,9 +903,10 @@ install_octopus_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主机的信息!"
|
||||
log "开始收集Agent主机的信息!"
|
||||
echo ""
|
||||
${octopus_agent_path}/lib/wdd-lib-env.sh
|
||||
chmod +x "${octopus_agent_path}/lib/wdd-lib-env.sh"
|
||||
bash "${octopus_agent_path}/lib/wdd-lib-env.sh"
|
||||
echo ""
|
||||
SplitGreen
|
||||
|
||||
|
||||
Reference in New Issue
Block a user