[init] 修改大量代码

This commit is contained in:
zeaslity
2023-11-13 16:50:50 +08:00
parent fe25545fc1
commit e2aee45ff1
4 changed files with 236 additions and 95 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="dataSourceStorageLocal" created-in="IU-231.9392.1"> <component name="dataSourceStorageLocal" created-in="IU-232.10203.10">
<data-source name="腾讯云-成都" uuid="79c9466f-d8a3-418a-b54a-f6e314306a0c"> <data-source name="腾讯云-成都" uuid="79c9466f-d8a3-418a-b54a-f6e314306a0c">
<database-info product="MySQL" version="8.0.27" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-java-8.0.25 (Revision: 08be9e9b4cba6aa115f9b27b215887af40b159e0)" dbms="MYSQL" exact-version="8.0.27" exact-driver-version="8.0"> <database-info product="MySQL" version="8.0.27" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-java-8.0.25 (Revision: 08be9e9b4cba6aa115f9b27b215887af40b159e0)" dbms="MYSQL" exact-version="8.0.27" exact-driver-version="8.0">
<extra-name-characters>#@</extra-name-characters> <extra-name-characters>#@</extra-name-characters>

View File

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

View File

@@ -1,10 +1,11 @@
#!/bin/bash #!/bin/bash
. ./wdd-lib-log.sh octopus_agent_path=/usr/local/etc/octpus-agent
. ./wdd-lib-sys.sh . "$octopus_agent_path/lib/wdd-lib-log.sh"
. "$octopus_agent_path/lib/wdd-lib-sys.sh"
host_arch_version="" host_arch_version=""
host_arch="" cpu_arch=""
#### CollectSystemInfo #### #### CollectSystemInfo ####
server_name="" server_name=""
server_ip_pb_v4="" server_ip_pb_v4=""
@@ -27,9 +28,10 @@ io_speed=""
machine_id="" machine_id=""
arch_info="" arch_info=""
agent_version="" agent_version=""
os_bit=""
### tmp usage ### tmp usage
io_avg="" io_speed=""
public_ipv4="" public_ipv4=""
inner_ipv4="" inner_ipv4=""
public_ipv6="" public_ipv6=""
@@ -37,7 +39,7 @@ inner_ipv6=""
country="" country=""
region="" region=""
city="" city=""
org="" net_provider=""
manage_port="" manage_port=""
machine_number="" machine_number=""
l_bit="" l_bit=""
@@ -52,6 +54,60 @@ io_test() {
(LANG=C dd if=/dev/zero of=benchtest_$$ bs=512k count=$1 conv=fdatasync && rm -f benchtest_$$) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' (LANG=C dd if=/dev/zero of=benchtest_$$ bs=512k count=$1 conv=fdatasync && rm -f benchtest_$$) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//'
} }
####### 获取系统版本及64位或32位信息
check_sys() {
local sys_bit
sys_bit=$(uname -m)
case $sys_bit in
i[36]86)
os_bit="32"
cpu_arch="386"
;;
x86_64)
os_bit="64"
cpu_arch="amd64"
;;
*armv6*)
os_bit="arm"
cpu_arch="arm6"
;;
*armv7*)
os_bit="arm"
cpu_arch="arm7"
;;
*aarch64* | *armv8*)
os_bit="arm64"
cpu_arch="arm64"
;;
*)
error "
哈哈……这个 辣鸡脚本 不支持你的系统。 (-_-) \n
备注: 仅支持 Ubuntu 16+ / Debian 8+ / CentOS 7+ 系统
" && exit 1
;;
esac
## 判定Linux的发行版本
if [ -f /etc/redhat-release ]; then
host_arch_version="centos"
elif cat /etc/issue | grep -Eqi "debian"; then
host_arch_version="debian"
elif cat /etc/issue | grep -Eqi "ubuntu"; then
host_arch_version="ubuntu"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
host_arch_version="centos"
elif cat /proc/version | grep -Eqi "debian"; then
host_arch_version="debian"
elif cat /proc/version | grep -Eqi "ubuntu"; then
host_arch_version="ubuntu"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
host_arch_version="centos"
else
host_arch_version=""
fi
return 0
}
####################################### #######################################
# description # description
# Arguments: # Arguments:
@@ -94,9 +150,11 @@ calc_size() {
####################################### #######################################
get_host_arch_info() { get_host_arch_info() {
FunctionStart "开始获取系统架构信息!" FunctionStart "开始获取系统架构信息!"
[ -f /etc/redhat-release ] && awk '{print $0}' /etc/redhat-release && return [ -f /etc/redhat-release ] && awk '{print $0}' /etc/redhat-release && return
[ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
[ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
FunctionEnd FunctionEnd
} }
@@ -137,8 +195,8 @@ start_io_test() {
ioraw3=$(echo $io3 | awk 'NR==1 {print $1}') ioraw3=$(echo $io3 | awk 'NR==1 {print $1}')
[ "$(echo $io3 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw3=$(awk 'BEGIN{print '$ioraw3' * 1024}') [ "$(echo $io3 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw3=$(awk 'BEGIN{print '$ioraw3' * 1024}')
ioall=$(awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}') ioall=$(awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}')
io_avg=$(awk 'BEGIN{printf "%.1f", '$ioall' / 3}') io_speed=$(awk 'BEGIN{printf "%.1f", '$ioall' / 3}')
log "I/O Speed(average) : $io_avg MB/s)" log "I/O Speed(average) : $io_speed MB/s)"
else else
echo " $(_red "Not enough space for I/O Speed test!")" echo " $(_red "Not enough space for I/O Speed test!")"
fi fi
@@ -254,7 +312,7 @@ get_manage_port() {
# Globals: # Globals:
# city # city
# country # country
# org # net_provider
# public_ipv4 # public_ipv4
# region # region
# Arguments: # Arguments:
@@ -265,7 +323,7 @@ get_ipv4_info() {
FunctionStart "开始收集服务器IP信息" FunctionStart "开始收集服务器IP信息"
# public ip info # public ip info
org="$(wget -q -T10 -O- ipinfo.io/org)" net_provider="$(wget -q -T10 -O- ipinfo.io/org)"
city="$(wget -q -T10 -O- ipinfo.io/city)" city="$(wget -q -T10 -O- ipinfo.io/city)"
country="$(wget -q -T10 -O- ipinfo.io/country)" country="$(wget -q -T10 -O- ipinfo.io/country)"
region="$(wget -q -T10 -O- ipinfo.io/region)" region="$(wget -q -T10 -O- ipinfo.io/region)"
@@ -281,17 +339,29 @@ get_ipv4_info() {
fi fi
# inner ipinfo # inner ipinfo
local interface_prefix=("[[:space:]]eth[0-9]{1,2}" "[[:space:]]ens[0-9]{1,3}" "[[:space:]]eno[0-9]{1,3}" "[[:space:]]enp[0-9]{1,2}") local interface_prefix=("eth[0-9]{1,2}" "ens[0-9]{1,3}" "eno[0-9]{1,3}" "enp[0-9]{1,2}" "enp[0-9]{1,2}s[0-9]{1,2}")
local real_interface="eth90" local real_interface="eth90"
local interface local interface
for interface in "${interface_prefix[@]}"; do
if ip link show | grep -oE "${interface}" | head -1; then if command_exists ifconfig; then
real_interface=$(ip link show | grep -oE "${interface}" | head -1 | cut -d" " -f2) log "使用ifconfig检测内部IP地址信息"
echo "当前主机的真实内网网卡为 => [$real_interface]" for interface in "${interface_prefix[@]}"; do
if ifconfig | grep -oqE "${interface}:"; then
real_interface=$(ifconfig | grep -E "${interface}:" | cut -d ":" -f1)
break break
fi fi
done done
else
log "使用 ip link show检测内部IP地址信息"
for interface in "${interface_prefix[@]}"; do
if ip link show | grep -oqE "${interface}:"; then
real_interface=$(ip link show | grep -oE "${interface}:" | head -1 | cut -d" " -f2)
break
fi
done
fi
echo "当前主机的真实内网网卡为 => [$real_interface]"
# 提取IPv4地址CIDR格式 # 提取IPv4地址CIDR格式
local ipv4_regex="inet[[:space:]](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}" local ipv4_regex="inet[[:space:]](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}"
@@ -300,11 +370,11 @@ get_ipv4_info() {
local ipv6_regex="inet6[[:space:]]([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}" local ipv6_regex="inet6[[:space:]]([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}"
# 查找IPv4地址 # 查找IPv4地址
inner_ipv4=$(ip addr show "$real_interface" | grep -oE "$ipv4_regex" | cut -d" " -f2) inner_ipv4=$(ip addr show "$real_interface" | grep -oE "$ipv4_regex" | grep -v 127 | cut -d" " -f2)
echo "Interface: $real_interface, IPv4 Address: $inner_ipv4" echo "Interface: $real_interface, IPv4 Address: $inner_ipv4"
# 查找IPv6地址 # 查找IPv6地址
inner_ipv6=$(ip addr show "$real_interface" | grep -oE "$ipv6_regex" | cut -d" " -f2) inner_ipv6=$(ip addr show "$real_interface" | grep -oE "$ipv6_regex" | grep -v "::1" | cut -d" " -f2)
echo "Interface: $real_interface, IPv4 Address: $inner_ipv6" echo "Interface: $real_interface, IPv4 Address: $inner_ipv6"
FunctionEnd FunctionEnd
@@ -323,14 +393,14 @@ get_ipv4_info() {
# cpu_virt # cpu_virt
# disk_total_size # disk_total_size
# disk_used_size # disk_used_size
# freq # cpu_freq
# kern # kernel_info
# lbit # lbit
# load # load
# opsy # os_info
# swap # swap
# tcp_ctrl # tcp_ctrl
# tram # mem_total
# unused_ram # unused_ram
# unused_swap # unused_swap
# up # up
@@ -338,24 +408,24 @@ get_ipv4_info() {
# None # None
####################################### #######################################
collect_system_info() { collect_system_info() {
FunctionStart "开始收集系统信息!" FunctionStart "开始收集系统信息!"
check_sys check_sys
cpu_name=$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//') cpu_name=$(awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')
cores=$(awk -F: '/processor/ {core++} END {print core}' /proc/cpuinfo) cores=$(awk -F: '/processor/ {core++} END {print core}' /proc/cpuinfo)
freq=$(awk -F'[ :]' '/cpu MHz/ {print $4;exit}' /proc/cpuinfo) cpu_freq=$(awk -F'[ :]' '/cpu MHz/ {print $4;exit}' /proc/cpuinfo)
local c_cache local c_cache
local cpu_aes local cpu_aes
local cpu_virt local cpu_virt
c_cache=$(awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//') c_cache=$(awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')
cpu_aes=$(grep -i 'aes' /proc/cpuinfo) cpu_aes=$(grep -i 'aes' /proc/cpuinfo)
cpu_virt=$(grep -Ei 'vmx|svm' /proc/cpuinfo) cpu_virt=$(grep -Ei 'vmx|svm' /proc/cpuinfo)
tram=$( mem_total=$(
LANG=C LANG=C
free | awk '/Mem/ {print $2}' free | awk '/Mem/ {print $2}'
) )
tram=$(calc_size "$tram") mem_total=$(calc_size "$mem_total")
local unused_ram local unused_ram
unused_ram=$( unused_ram=$(
LANG=C LANG=C
@@ -388,7 +458,7 @@ collect_system_info() {
uptime | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' uptime | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//'
) )
fi fi
opsy=$(get_host_arch_info) os_info=$(get_host_arch_info)
arch=$(uname -m) arch=$(uname -m)
local l_bit local l_bit
if command_exists "getconf"; then if command_exists "getconf"; then
@@ -396,7 +466,7 @@ collect_system_info() {
else else
echo "${arch}" | grep -q "64" && l_bit="64" || l_bit="32" echo "${arch}" | grep -q "64" && l_bit="64" || l_bit="32"
fi fi
kern=$(uname -r) kernel_info=$(uname -r)
disk_total_size=$( disk_total_size=$(
LANG=C LANG=C
df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $2 }' df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total 2>/dev/null | grep total | awk '{ print $2 }'
@@ -409,7 +479,6 @@ collect_system_info() {
disk_used_size=$(calc_size "$disk_used_size") disk_used_size=$(calc_size "$disk_used_size")
tcp_ctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}') tcp_ctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}')
local machine_number=""
if [[ $(cut -d"-" -f 3 </etc/hostname | grep -c '^[0-9][0-9]') -gt 0 ]]; then if [[ $(cut -d"-" -f 3 </etc/hostname | grep -c '^[0-9][0-9]') -gt 0 ]]; then
machine_number=$(cut -d"-" -f 3 </etc/hostname) machine_number=$(cut -d"-" -f 3 </etc/hostname)
else else
@@ -437,13 +506,21 @@ get_agent_version() {
FunctionStart "获取Agent的版本信息" FunctionStart "获取Agent的版本信息"
local file local file
for file in ${octopus_agent_path}; do for file in "${octopus_agent_path}"/*; do
if grep -q "octopus-agent_" <"${file}"; then if [[ ! -d ${file} ]]; then
agent_version=$(cut -d "_" -f4- <"${file}") if echo "$file" | grep "octopus-agent_linux_amd64_"; then
log "获取到的Agent版本信息为 => ${agent_version}" agent_version=$(echo "${file}" | cut -d "_" -f4-)
break
fi
fi fi
done done
if [[ $agent_version -eq "" ]]; then
agent_version=2011-11-11-11-11-11
fi
log "获取到的Agent版本信息为 => ${agent_version}"
FunctionEnd FunctionEnd
} }
@@ -458,22 +535,22 @@ get_agent_version() {
# cpu_name # cpu_name
# disk_total_size # disk_total_size
# disk_used_size # disk_used_size
# freq # cpu_freq
# host_arch # cpu_arch
# inner_ipv4 # inner_ipv4
# inner_ipv6 # inner_ipv6
# io_avg # io_speed
# kern # kernel_info
# lbit # lbit
# machine_number # machine_number
# manage_port # manage_port
# opsy # os_info
# org # net_provider
# public_ipv4 # public_ipv4
# public_ipv6 # public_ipv6
# region # region
# tcp_ctrl # tcp_ctrl
# tram # mem_total
# virt # virt
# Arguments: # Arguments:
# None # None
@@ -482,6 +559,8 @@ main() {
# todo # todo
# start_iotest # start_iotest
check_sys
get_manage_port get_manage_port
collect_system_info collect_system_info
@@ -492,34 +571,43 @@ main() {
get_agent_version get_agent_version
local agent_server_info_file="/octopus-agent/octopus-agent.conf" local agent_server_info_file="$octopus_agent_path/octopus-agent.conf"
touch "$agent_server_info_file" touch "$agent_server_info_file"
cat >"$agent_server_info_file" <<EOF cat >"$agent_server_info_file" <<EOF
serverName: ${city}-${host_arch}-${machine_number} serverName: "${city}-${cpu_arch}-${machine_number}"
serverIpPbV4: $public_ipv4 serverIpPbV4: "$public_ipv4"
serverIpInV4: $inner_ipv4 serverIpInV4: "$inner_ipv4"
serverIpPbV6: $public_ipv6 serverIpPbV6: "$public_ipv6"
serverIpInV6: $inner_ipv6 serverIpInV6: "$inner_ipv6"
location: "$city $region $country" location: "$city $region $country"
provider: $org provider: "$net_provider"
managePort: $manage_port managePort: "$manage_port"
cpuCore: "$cores @ $freq MHz" cpuCore: "$cores @ $cpu_freq MHz"
cpuBrand: "$cpu_name" cpuBrand: "$cpu_name"
memoryTotal: $tram memoryTotal: "$mem_total"
diskTotal: $disk_total_size diskTotal: "$disk_total_size"
diskUsage: $disk_used_size diskUsage: "$disk_used_size"
archInfo: "$arch ($l_bit Bit)" archInfo: "$arch ($os_bit Bit)"
osInfo: "$opsy" osInfo: "$os_info"
osKernelInfo: $kern osKernelInfo: "$kernel_info"
tcpControl: $tcp_ctrl tcpControl: "$tcp_ctrl"
virtualization: $virt virtualization: "$virt"
ioSpeed: "$io_avg MB/s" ioSpeed: "$io_speed MB/s"
machineId: $(cat /etc/machine-id) machineId: "$(cat /etc/machine-id)"
agentVersion: ${agent_version} agentVersion: "${agent_version}"
EOF EOF
log "agent server info has collect complete!" log "agent server info has collect complete!"
log "file is => $agent_server_info_file" log "file is => $agent_server_info_file"
echo ""
SplitGreen "查看Agent的环境信息"
cat - 1>&2 <<EOF
cat $agent_server_info_file
EOF
} }
main main

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
oss_url_prefix="https://oss-s1.107421.xyz" oss_url_prefix="https://oss-s1.107421.xyz"
octopus_agent_path=/usr/local/etc/octpus-agent/ octopus_agent_path=/usr/local/etc/octpus-agent
echo "" echo ""
echo "" echo ""
@@ -97,7 +97,7 @@ check_sys() {
else else
linux_release_version="" linux_release_version=""
fi fi
log "系统参数信息如下: LinuxReleaseVersion => $linux_release_version" log "系统参数信息如下: linux_release_version => $linux_release_version"
# 判断系统的包管理工具 apt, yum, or zypper # 判断系统的包管理工具 apt, yum, or zypper
get_package_manage_tool() { get_package_manage_tool() {