[init] 修改大量代码

This commit is contained in:
zeaslity
2023-10-20 14:10:20 +08:00
parent 3b30f5eee1
commit 7beab04895
8 changed files with 419 additions and 234 deletions

View File

@@ -0,0 +1,3 @@
https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/plugins/command-not-found/command-not-found.plugin.zsh
https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/plugins/autojump/autojump.plugin.zsh
https://cdn.jsdelivr.net/gh/ohmyzsh/ohmyzsh/plugins/themes/themes.plugin.zsh

View File

@@ -26,6 +26,12 @@
140.83.58.96 osaka-2 o2 140.83.58.96 osaka-2 o2
129.146.171.163 p2
129.146.65.80 p3
129.146.57.94 p4
42.192.52.227 tc-sh 42.192.52.227 tc-sh
43.128.39.232 tc-hk 43.128.39.232 tc-hk

View File

@@ -54,7 +54,7 @@ install_demand_softwares() {
log "正在安装 ${software}..." log "正在安装 ${software}..."
## 判断该软件是否安装成功 ## 判断该软件是否安装成功
if ! $CMD_INSTALL "${software}"; then if ! $cmd_install "${software}"; then
error "安装 ${software} 失败。" error "安装 ${software} 失败。"
error "如果是重要软件,本脚本会自动终止!!" error "如果是重要软件,本脚本会自动终止!!"
colorEchoPurple "一般软件,本脚本会忽略错误并继续运行,请之后手动安装该程序。" colorEchoPurple "一般软件,本脚本会忽略错误并继续运行,请之后手动安装该程序。"
@@ -186,7 +186,7 @@ EOF
# description # description
# Globals: # Globals:
# BLUE # BLUE
# CMD_REMOVE # cmd_remove
# deploy_in_cn # deploy_in_cn
# docker_version # docker_version
# GREEN # GREEN
@@ -210,7 +210,7 @@ install_docker() {
local pre_soft_ware=(docker-ce containerd.io docker-ce-cli docker-compose kubelet kubeadm kubectl) local pre_soft_ware=(docker-ce containerd.io docker-ce-cli docker-compose kubelet kubeadm kubectl)
local pre_one="" local pre_one=""
for pre_one in ${pre_soft_ware[@]}; do for pre_one in ${pre_soft_ware[@]}; do
$CMD_REMOVE "$pre_one" $cmd_remove "$pre_one"
done done
colorEchoGreen "----------docker环境清理完成----------" colorEchoGreen "----------docker环境清理完成----------"
@@ -259,7 +259,7 @@ install_docker() {
else else
log "开始安装相关的Docker基础组件" log "开始安装相关的Docker基础组件"
install_demand_softwares apt-transport-https ca-certificates curl gnupg-agent software-properties-common lsb-release install_demand_softwares apt-transport-https ca-certificates curl gnupg software-properties-common lsb-release
colorEchoGreen " 基础组件安装成功 " colorEchoGreen " 基础组件安装成功 "
echo "" echo ""
@@ -423,7 +423,7 @@ EOF
if [[ $deploy_in_cn -eq 1 ]]; then if [[ $deploy_in_cn -eq 1 ]]; then
log "开始从 Gitee 下载 自动补全 插件…………" log "开始从 Gitee 下载 自动补全 插件…………"
git clone https://gitee.com/githubClone/zsh-autosuggestions.git ~/.oh-my-zsh/plugins/zsh-autosuggestions git clone https://gitee.com/wangl-cc/zsh-autosuggestions.git ~/.oh-my-zsh/plugins/zsh-autosuggestions
else else
log "开始从 GitHub 下载 自动补全 插件…………" log "开始从 GitHub 下载 自动补全 插件…………"
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
@@ -432,7 +432,7 @@ EOF
if [[ $deploy_in_cn -eq 1 ]]; then if [[ $deploy_in_cn -eq 1 ]]; then
log "开始从 Gitee 下载 命令高亮 插件…………" log "开始从 Gitee 下载 命令高亮 插件…………"
git clone https://gitee.com/mo2/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting git clone https://gitee.com/xiaoqqya/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
else else
log "开始从 GitHub 下载 命令高亮 插件…………" log "开始从 GitHub 下载 命令高亮 插件…………"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting

View File

@@ -5,7 +5,7 @@ if [[ ! -f /root/wdd/lib/wdd-lib-log.sh ]]; then
fi fi
source /root/wdd/lib/wdd-lib-log.sh source /root/wdd/lib/wdd-lib-log.sh
CleanOracleAgent() { clean_oracle_agent() {
FunctionStart FunctionStart
colorEchoBlue "准备清理 Oracle Agent的相关内容 " colorEchoBlue "准备清理 Oracle Agent的相关内容 "
@@ -28,7 +28,7 @@ CleanOracleAgent() {
FunctionEnd FunctionEnd
} }
CleanIpPersist() { clean_ip_persist() {
FunctionStart FunctionStart
colorEchoBlue "开始关闭 防火墙持久化存储 …………" colorEchoBlue "开始关闭 防火墙持久化存储 …………"
systemctl stop systemd-resolved.service && systemctl disable systemd-resolved.service systemctl stop systemd-resolved.service && systemctl disable systemd-resolved.service

View File

@@ -1,38 +1,35 @@
#!/bin/bash #!/bin/bash
. /octopus-agent/shell/lib/wdd-lib-log.sh . ./wdd-lib-log.sh
. /octopus-agent/shell/lib/wdd-lib-sys.sh . ./wdd-lib-sys.sh
#. .wdd-lib-log.sh host_arch_version=""
#. .wdd-lib-sys.sh host_arch=""
hostArchVersion=""
hostArch=""
#### CollectSystemInfo #### #### CollectSystemInfo ####
serverName="" server_name=""
serverIpPbV4="" server_ip_pb_v4=""
serverIpInV4="" server_ip_in_v4=""
serverIpPbV6="" server_ip_pb_v6=""
serverIpInV6="" server_ip_in_v6=""
location="" location=""
provider="" provider=""
managePort="" manage_port=""
cpuBrand="" cpu_brand=""
cpuCore="" cpu_core=""
memoryTotal="" memory_total=""
diskTotal="" disk_total=""
diskUsage="" disk_usage=""
osInfo="" os_info=""
osKernelInfo="" os_kernel_info=""
tcpControl="" tcp_control=""
virtualization="" virtualization=""
ioSpeed="" io_speed=""
machineId="" machine_id=""
archInfo="" arch_info=""
agentVersion="" agent_version=""
### tmp usage ### tmp usage
ioavg="" io_avg=""
public_ipv4="" public_ipv4=""
inner_ipv4="" inner_ipv4=""
public_ipv6="" public_ipv6=""
@@ -41,7 +38,9 @@ country=""
region="" region=""
city="" city=""
org="" org=""
managePort="" manage_port=""
machine_number=""
l_bit=""
#### CollectSystemInfo #### #### CollectSystemInfo ####
####################################### #######################################
@@ -49,7 +48,7 @@ managePort=""
# Arguments: # Arguments:
# 1 # 1
####################################### #######################################
GoIOTest() { 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]*$//'
} }
@@ -93,10 +92,12 @@ calc_size() {
# Returns: # Returns:
# <unknown> ... # <unknown> ...
####################################### #######################################
GethostArchInfo() { get_host_arch_info() {
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
} }
####################################### #######################################
@@ -115,19 +116,19 @@ GethostArchInfo() {
# Arguments: # Arguments:
# None # None
####################################### #######################################
StartIOTest() { start_io_test() {
log "start IO speed test !" FunctionStart "开始测试IO速度"
freespace=$(df -m . | awk 'NR==2 {print $4}') freespace=$(df -m . | awk 'NR==2 {print $4}')
if [ -z "${freespace}" ]; then if [ -z "${freespace}" ]; then
freespace=$(df -m . | awk 'NR==3 {print $3}') freespace=$(df -m . | awk 'NR==3 {print $3}')
fi fi
if [ ${freespace} -gt 1024 ]; then if [ ${freespace} -gt 1024 ]; then
writemb=2048 writemb=2048
io1=$(GoIOTest ${writemb}) io1=$(go_iotest ${writemb})
log "I/O Speed(1st run) : $io1)" log "I/O Speed(1st run) : $io1)"
io2=$(GoIOTest ${writemb}) io2=$(go_iotest ${writemb})
log "I/O Speed(2st run) : $io2)" log "I/O Speed(2st run) : $io2)"
io3=$(GoIOTest ${writemb}) io3=$(go_iotest ${writemb})
log "I/O Speed(3st run) : $io3)" log "I/O Speed(3st run) : $io3)"
ioraw1=$(echo $io1 | awk 'NR==1 {print $1}') ioraw1=$(echo $io1 | awk 'NR==1 {print $1}')
[ "$(echo $io1 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw1=$(awk 'BEGIN{print '$ioraw1' * 1024}') [ "$(echo $io1 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw1=$(awk 'BEGIN{print '$ioraw1' * 1024}')
@@ -136,42 +137,40 @@ StartIOTest() {
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'}')
ioavg=$(awk 'BEGIN{printf "%.1f", '$ioall' / 3}') io_avg=$(awk 'BEGIN{printf "%.1f", '$ioall' / 3}')
log "I/O Speed(average) : $ioavg MB/s)" log "I/O Speed(average) : $io_avg 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
} FunctionEnd
#######################################
# description
# Arguments:
# None
#######################################
GetAgentLatestVersion() {
ls /octopus-agent | grep "octopus-agent" | cut -d "-" -f3- | cut -d"." -f1
} }
####################################### #######################################
# description # description
# Globals: # Globals:
# cpuName # cpu_name
# sys_manu # sys_manu
# sys_product # sys_product
# sys_ver # sys_ver
# virt # virt
# virtualx # virtual_x
# Arguments: # Arguments:
# None # None
####################################### #######################################
Check_Virtualization() { check_virtualization() {
log "start to check host virtualization !" FunctionStart "开始收集服务器虚拟化信息!"
local virtual_x
if command_exists "dmesg"; then
virtual_x="$(dmesg 2>/dev/null)"
fi
local sys_manu
local sys_product
local sys_ver
command_exists "dmesg" && virtualx="$(dmesg 2>/dev/null)"
if command_exists "dmidecode"; then if command_exists "dmidecode"; then
sys_manu="$(dmidecode -s system-manufacturer 2>/dev/null)" sys_manu="$(dmidecode -s system-manufacturer 2>/dev/null)"
sys_product="$(dmidecode -s system-product-name 2>/dev/null)" sys_product="$(dmidecode -s system-product-name 2>/dev/null)"
@@ -189,21 +188,21 @@ Check_Virtualization() {
virt="LXC" virt="LXC"
elif [[ -f /proc/user_beancounters ]]; then elif [[ -f /proc/user_beancounters ]]; then
virt="OpenVZ" virt="OpenVZ"
elif [[ ${virtualx} == *kvm-clock* ]]; then elif [[ ${virtual_x} == *kvm-clock* ]]; then
virt="KVM" virt="KVM"
elif [[ ${sys_product} == *KVM* ]]; then elif [[ ${sys_product} == *KVM* ]]; then
virt="KVM" virt="KVM"
elif [[ ${cpuName} == *KVM* ]]; then elif [[ ${cpu_name} == *KVM* ]]; then
virt="KVM" virt="KVM"
elif [[ ${cpuName} == *QEMU* ]]; then elif [[ ${cpu_name} == *QEMU* ]]; then
virt="KVM" virt="KVM"
elif [[ ${virtualx} == *"VMware Virtual Platform"* ]]; then elif [[ ${virtual_x} == *"VMware Virtual Platform"* ]]; then
virt="VMware" virt="VMware"
elif [[ ${sys_product} == *"VMware Virtual Platform"* ]]; then elif [[ ${sys_product} == *"VMware Virtual Platform"* ]]; then
virt="VMware" virt="VMware"
elif [[ ${virtualx} == *"Parallels Software International"* ]]; then elif [[ ${virtual_x} == *"Parallels Software International"* ]]; then
virt="Parallels" virt="Parallels"
elif [[ ${virtualx} == *VirtualBox* ]]; then elif [[ ${virtual_x} == *VirtualBox* ]]; then
virt="VirtualBox" virt="VirtualBox"
elif [[ -e /proc/xen ]]; then elif [[ -e /proc/xen ]]; then
if grep -q "control_d" "/proc/xen/capabilities" 2>/dev/null; then if grep -q "control_d" "/proc/xen/capabilities" 2>/dev/null; then
@@ -225,14 +224,28 @@ Check_Virtualization() {
virt="Dedicated" virt="Dedicated"
fi fi
FunctionEnd
} }
GetManagePort(){ #######################################
# description
# Globals:
# manage_port
# tmp_manage_ports
# Arguments:
# None
#######################################
get_manage_port() {
tmpManagePorts=$(netstat -ntulp | grep sshd | grep -w tcp | grep -v "127.0.0.1"| awk '{print$4}' | cut -d":" -f2) FunctionStart "开始收集服务器 管理端口 信息!"
local tmp_manage_ports
tmp_manage_ports=$(netstat -ntulp | grep sshd | grep -w tcp | grep -v "127.0.0.1" | awk '{print$4}' | cut -d":" -f2)
managePort=$(echo $tmpManagePorts | tr '\n' ' ') manage_port=$(echo "$tmp_manage_ports" | tr '\n' ' ')
log "manage Port is => $managePort" log "manage Port is => $manage_port"
FunctionEnd
} }
@@ -247,9 +260,9 @@ GetManagePort(){
# Arguments: # Arguments:
# None # None
####################################### #######################################
GetIpv4Info() { get_ipv4_info() {
log "start to get system public ip info !" FunctionStart "开始收集服务器IP信息"
# public ip info # public ip info
org="$(wget -q -T10 -O- ipinfo.io/org)" org="$(wget -q -T10 -O- ipinfo.io/org)"
@@ -259,148 +272,254 @@ GetIpv4Info() {
public_ipv4="$(wget -q -T10 -O- ipinfo.io/ip)" public_ipv4="$(wget -q -T10 -O- ipinfo.io/ip)"
public_ipv6="$(curl -q --max-time 5 -6 https://ifconfig.co/ip)" public_ipv6="$(curl -q --max-time 5 -6 https://ifconfig.co/ip)"
if [ -z "$public_ipv4" ] ; then if [ -z "$public_ipv4" ]; then
public_ipv4=" " public_ipv4=" "
fi fi
if [ -z "$public_ipv6" ] ; then if [ -z "$public_ipv6" ]; then
public_ipv6=" " public_ipv6=" "
fi fi
# inner ipinfo # inner ipinfo
export 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=("[[:space:]]eth[0-9]{1,2}" "[[:space:]]ens[0-9]{1,3}" "[[:space:]]eno[0-9]{1,3}" "[[:space:]]enp[0-9]{1,2}")
export real_interface="eth90" local real_interface="eth90"
local interface
for interface in "${interface_prefix[@]}"; do for interface in "${interface_prefix[@]}"; do
echo $(ip link show) | grep -oE ${interface} | head -1 if ip link show | grep -oE "${interface}" | head -1; then
if [[ $? -eq 0 ]]; then real_interface=$(ip link show | grep -oE "${interface}" | head -1 | cut -d" " -f2)
real_interface=$(echo $(ip link show) | grep -oE ${interface} | head -1 | cut -d" " -f2)
echo "当前主机的真实内网网卡为 => [$real_interface]" echo "当前主机的真实内网网卡为 => [$real_interface]"
break break
fi fi
done done
# 提取IPv4地址CIDR格式 # 提取IPv4地址CIDR格式
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}"
# 提取IPv6地址CIDR格式 # 提取IPv6地址CIDR格式
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=$(echo $(ip addr show $real_interface) | grep -oE $ipv4_regex | cut -d" " -f2) inner_ipv4=$(ip addr show "$real_interface" | grep -oE "$ipv4_regex" | cut -d" " -f2)
echo "Interface: $real_interface, IPv4 Address: $inner_ipv4" echo "Interface: $real_interface, IPv4 Address: $inner_ipv4"
# 查找IPv6地址 # 查找IPv6地址
inner_ipv6=$(echo $(ip addr show $real_interface) | grep -oE $ipv6_regex | cut -d" " -f2) inner_ipv6=$(ip addr show "$real_interface" | grep -oE "$ipv6_regex" | cut -d" " -f2)
echo "Interface: $real_interface, IPv4 Address: $inner_ipv6" echo "Interface: $real_interface, IPv4 Address: $inner_ipv6"
FunctionEnd
} }
log "start to collect system info !" #######################################
# description
# Globals:
# LANG
# arch
# c_cache
# cores
# cpu_aes
# cpu_name
# cpu_virt
# disk_total_size
# disk_used_size
# freq
# kern
# lbit
# load
# opsy
# swap
# tcp_ctrl
# tram
# unused_ram
# unused_swap
# up
# Arguments:
# None
#######################################
collect_system_info() {
FunctionStart "开始收集系统信息!"
check_sys check_sys
cpuName=$(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) freq=$(awk -F'[ :]' '/cpu MHz/ {print $4;exit}' /proc/cpuinfo)
ccache=$(awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//') local c_cache
cpu_aes=$(grep -i 'aes' /proc/cpuinfo) local cpu_aes
cpu_virt=$(grep -Ei 'vmx|svm' /proc/cpuinfo) local cpu_virt
tram=$( c_cache=$(awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//')
LANG=C cpu_aes=$(grep -i 'aes' /proc/cpuinfo)
free | awk '/Mem/ {print $2}' cpu_virt=$(grep -Ei 'vmx|svm' /proc/cpuinfo)
) tram=$(
tram=$(calc_size $tram)
uram=$(
LANG=C
free | awk '/Mem/ {print $3}'
)
uram=$(calc_size $uram)
swap=$(
LANG=C
free | awk '/Swap/ {print $2}'
)
swap=$(calc_size $swap)
uswap=$(
LANG=C
free | awk '/Swap/ {print $3}'
)
uswap=$(calc_size $uswap)
up=$(awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days, %d hour %d min\n",a,b,c)}' /proc/uptime)
if command_exists "w"; then
load=$(
LANG=C LANG=C
w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' free | awk '/Mem/ {print $2}'
) )
elif command_exists "uptime"; then tram=$(calc_size "$tram")
load=$( local unused_ram
unused_ram=$(
LANG=C LANG=C
uptime | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' free | awk '/Mem/ {print $3}'
) )
fi unused_ram=$(calc_size "$unused_ram")
opsy=$(GethostArchInfo) local swap
arch=$(uname -m) swap=$(
if command_exists "getconf"; then LANG=C
lbit=$(getconf LONG_BIT) free | awk '/Swap/ {print $2}'
else )
echo ${arch} | grep -q "64" && lbit="64" || lbit="32" swap=$(calc_size "$swap")
fi local unused_swap
kern=$(uname -r) unused_swap=$(
disk_total_size=$( LANG=C
LANG=C free | awk '/Swap/ {print $3}'
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 }' )
) unused_swap=$(calc_size "$unused_swap")
disk_total_size=$(calc_size $disk_total_size) local up
disk_used_size=$( up=$(awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days, %d hour %d min\n",a,b,c)}' /proc/uptime)
LANG=C local load
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 $3 }' if command_exists "w"; then
) load=$(
disk_used_size=$(calc_size $disk_used_size) LANG=C
tcpctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}') w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//'
)
elif command_exists "uptime"; then
load=$(
LANG=C
uptime | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//'
)
fi
opsy=$(get_host_arch_info)
arch=$(uname -m)
local l_bit
if command_exists "getconf"; then
l_bit=$(getconf LONG_BIT)
else
echo "${arch}" | grep -q "64" && l_bit="64" || l_bit="32"
fi
kern=$(uname -r)
disk_total_size=$(
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 }'
)
disk_total_size=$(calc_size "$disk_total_size")
disk_used_size=$(
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 $3 }'
)
disk_used_size=$(calc_size "$disk_used_size")
tcp_ctrl=$(sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}')
# todo local machine_number=""
# StartIOTest if [[ $(cut -d"-" -f 3 </etc/hostname | grep -c '^[0-9][0-9]') -gt 0 ]]; then
machine_number=$(cut -d"-" -f 3 </etc/hostname)
else
machine_number=99
fi
GetManagePort FunctionEnd
}
GetIpv4Info #######################################
# description
# Arguments:
# None
#######################################
Check_Virtualization #######################################
# description
# Globals:
# agent_version
# octopus_agent_path
# Arguments:
# None
#######################################
get_agent_version() {
FunctionStart "获取Agent的版本信息"
machineNumber="" local file
for file in ${octopus_agent_path}; do
if grep -q "octopus-agent_" <"${file}"; then
agent_version=$(cut -d "_" -f4- <"${file}")
log "获取到的Agent版本信息为 => ${agent_version}"
fi
done
if [[ $(cat /etc/hostname | cut -d"-" -f 3 | grep -c '^[0-9][0-9]') -gt 0 ]]; then FunctionEnd
machineNumber=$(cat /etc/hostname | cut -d"-" -f 3) }
else
machineNumber=99
fi
agentServerInfoFile="/octopus-agent/octopus-agent.conf"
#cat >/etc/environment.d/octopus-agent.conf <<EOF #######################################
touch $ageagentServerInfoFile # description
cat >"$agentServerInfoFile"<<EOF # Globals:
serverName: ${city}-${hostArch}-${machineNumber} # agent_server_info_file
# arch
# city
# cores
# country
# cpu_name
# disk_total_size
# disk_used_size
# freq
# host_arch
# inner_ipv4
# inner_ipv6
# io_avg
# kern
# lbit
# machine_number
# manage_port
# opsy
# org
# public_ipv4
# public_ipv6
# region
# tcp_ctrl
# tram
# virt
# Arguments:
# None
#######################################
main() {
# todo
# start_iotest
get_manage_port
collect_system_info
get_ipv4_info
check_virtualization
get_agent_version
local agent_server_info_file="/octopus-agent/octopus-agent.conf"
touch "$agent_server_info_file"
cat >"$agent_server_info_file" <<EOF
serverName: ${city}-${host_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: $org
managePort: $managePort managePort: $manage_port
cpuCore: "$cores @ $freq MHz" cpuCore: "$cores @ $freq MHz"
cpuBrand: "$cpuName" cpuBrand: "$cpu_name"
memoryTotal: $tram memoryTotal: $tram
diskTotal: $disk_total_size diskTotal: $disk_total_size
diskUsage: $disk_used_size diskUsage: $disk_used_size
archInfo: "$arch ($lbit Bit)" archInfo: "$arch ($l_bit Bit)"
osInfo: "$opsy" osInfo: "$opsy"
osKernelInfo: $kern osKernelInfo: $kern
tcpControl: $tcpctrl tcpControl: $tcp_ctrl
virtualization: $virt virtualization: $virt
ioSpeed: "$ioavg MB/s" ioSpeed: "$io_avg MB/s"
machineId: $(cat /etc/machine-id) machineId: $(cat /etc/machine-id)
agentVersion: $(ls /octopus-agent | grep "octopus-agent_" | cut -d "_" -f4-) agentVersion: ${agent_version}
EOF EOF
log "agent server info has collect complete!" log "agent server info has collect complete!"
log "file is => $agentServerInfoFile" log "file is => $agent_server_info_file"
}
main

View File

@@ -1,20 +1,25 @@
#!/bin/bash #!/bin/bash
if [[ ! -f /root/wdd/lib/wdd-lib-log.sh ]]; then oss_url_prefix="https://oss-s1.107421.xyz"
wget https://oss-s1.107421.xyz/wdd-lib-log.sh -O /root/wdd/lib/wdd-lib-log.sh octopus_agent_path=/usr/local/etc/octpus-agent/
fi
. /root/wdd/lib/wdd-lib-log.sh
echo ""
echo ""
lib_file_list=(wdd-lib-log.sh)
for lib_file in ${lib_file_list[@]}; do
wget "${oss_url_prefix}/${lib_file}" -qO "${octopus_agent_path}/lib/${lib_file}"
echo "加载库文件 < ${octopus_agent_path}/lib/${lib_file}"
. "${octopus_agent_path}/lib/${lib_file}"
done
# 系统相关 # 系统相关
linux_release_version="" linux_release_version=""
linux_release="" linux_release=""
OS_BIT="" os_bit=""
CMD_INSTALL="apt-get -y -qq install" cmd_install="apt-get -y -qq --allow-downgrades install"
CMD_UPDATE="apt-get -qq update" cmd_update="apt-get -qq update"
CMD_REMOVE="apt-get -y remove" cmd_remove="apt-get -y remove"
SOFTWARE_UPDATED=0 software_updated=0
# 判断命令是否存在 # 判断命令是否存在
command_exists() { command_exists() {
@@ -26,7 +31,7 @@ check_root() {
FunctionStart "判定Root用户" FunctionStart "判定Root用户"
if [[ $EUID != 0 ]]; then if [[ $EUID != 0 ]]; then
colorEchoRed "当前非root账号(或没有root权限)无法继续操作请更换root账号!" colorEchoRed "当前非root账号(或没有root权限)无法继续操作请更换root账号!"
colorEcho ${YELLOW} "使用sudo -命令获取临时root权限执行后可能会提示输入root密码" colorEchoYellow "使用sudo -命令获取临时root权限执行后可能会提示输入root密码"
exit 1 exit 1
else else
log "当前为root账号 " log "当前为root账号 "
@@ -42,27 +47,27 @@ check_sys() {
# local shell_width=$(stty size | awk '{print $2}') # local shell_width=$(stty size | awk '{print $2}')
# SplitLine=$(yes "-" | sed "${shell_width}"'q' | tr -d '\n') # SplitLine=$(yes "-" | sed "${shell_width}"'q' | tr -d '\n')
local sys_bit
sys_bit=$(uname -m) sys_bit=$(uname -m)
case $sys_bit in case $sys_bit in
i[36]86) i[36]86)
OS_BIT="32" os_bit="32"
linux_release="386" linux_release="386"
;; ;;
x86_64) x86_64)
OS_BIT="64" os_bit="64"
linux_release="amd64" linux_release="amd64"
;; ;;
*armv6*) *armv6*)
OS_BIT="arm" os_bit="arm"
linux_release="arm6" linux_release="arm6"
;; ;;
*armv7*) *armv7*)
OS_BIT="arm" os_bit="arm"
linux_release="arm7" linux_release="arm7"
;; ;;
*aarch64* | *armv8*) *aarch64* | *armv8*)
OS_BIT="arm64" os_bit="arm64"
linux_release="arm64" linux_release="arm64"
;; ;;
*) *)
@@ -72,7 +77,7 @@ check_sys() {
" && exit 1 " && exit 1
;; ;;
esac esac
log "获取的系统信息如下: OS_BIT => ${OS_BIT} LinuxRelease => $linux_release" log "获取的系统信息如下: OS_BIT => ${os_bit} LinuxRelease => $linux_release"
## 判定Linux的发行版本 ## 判定Linux的发行版本
if [ -f /etc/redhat-release ]; then if [ -f /etc/redhat-release ]; then
@@ -95,19 +100,19 @@ check_sys() {
log "系统参数信息如下: LinuxReleaseVersion => $linux_release_version" log "系统参数信息如下: LinuxReleaseVersion => $linux_release_version"
# 判断系统的包管理工具 apt, yum, or zypper # 判断系统的包管理工具 apt, yum, or zypper
getPackageManageTool() { get_package_manage_tool() {
if [[ -n $(command -v apt-get) ]]; then if [[ -n $(command -v apt-get) ]]; then
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"
CMD_REMOVE="apt-get -y remove" cmd_remove="apt-get -y remove"
elif [[ -n $(command -v yum) ]]; then elif [[ -n $(command -v yum) ]]; then
CMD_INSTALL="yum -y -q install" cmd_install="yum -y -q install"
CMD_UPDATE="yum -q makecache" cmd_update="yum -q makecache"
CMD_REMOVE="yum -y remove" cmd_remove="yum -y remove"
elif [[ -n $(command -v zypper) ]]; then elif [[ -n $(command -v zypper) ]]; then
CMD_INSTALL="zypper -y install" cmd_install="zypper -y install"
CMD_UPDATE="zypper ref" cmd_update="zypper ref"
CMD_REMOVE="zypper -y remove" cmd_remove="zypper -y remove"
else else
return 1 return 1
fi fi
@@ -115,20 +120,27 @@ check_sys() {
} }
# 检查系统包管理方式,更新包 # 检查系统包管理方式,更新包
getPackageManageTool get_package_manage_tool
if [[ $? -eq 1 ]]; then if [[ $? -eq 1 ]]; then
error "系统的包管理不是 APT or YUM, 请手动安装所需要的软件." error "系统的包管理不是 APT or YUM, 请手动安装所需要的软件."
return 1 return 1
fi fi
log "系统包管理工具为 => $CMD_INSTALL" log "系统包管理工具为 => $cmd_install"
### 更新程序引索 ### 更新程序引索
if [[ $SOFTWARE_UPDATED -eq 0 ]]; then if [[ $software_updated -eq 0 ]]; then
log "正在更新软件包管理...可能花费较长时间…………" log "正在更新软件包管理...可能花费较长时间…………"
$CMD_UPDATE $cmd_update
SOFTWARE_UPDATED=1 software_updated=1
fi fi
FunctionEnd FunctionEnd
} }
# main
main() {
log "sys脚本被调用了"
}
main

View File

@@ -1,28 +1,25 @@
#!/bin/bash #!/bin/bash
.
## 对外暴露的安装Redis的主函数 ## 对外暴露的安装Redis的主函数
InstallRedis() { install_redis() {
FunctionStart FunctionStart
RedisPort="6379" local redis_port="6379"
RedisInstallMethod="binary" local redis_install_method="binary"
RedisInstallHelp="0" local redis_install_help="0"
while [[ $# > 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
-p | --port) -p | --port)
RedisPort="${2}" redis_port="${2}"
shift # past argument shift # past argument
;; ;;
-m | --method) -m | --method)
RedisInstallMethod="${2}" redis_install_method="${2}"
shift # past argument shift # past argument
;; ;;
-h | --help) -h | --help)
RedisInstallHelp="1" redis_install_help="1"
;; ;;
*) *)
echo "输入的内容有误,请检查!" echo "输入的内容有误,请检查!"
@@ -32,7 +29,7 @@ InstallRedis() {
shift # past argument or value shift # past argument or value
done done
if [ "${RedisInstallHelp}" -eq "1" ]; then if [ "${redis_install_help}" -eq "1" ]; then
cat - 1>&2 <<EOF cat - 1>&2 <<EOF
./install-release.sh [-h] [-p|--port 6379] [-m|--method binary|docker] ./install-release.sh [-h] [-p|--port 6379] [-m|--method binary|docker]
-h, --help 打印此安装帮助说明 -h, --help 打印此安装帮助说明
@@ -41,28 +38,37 @@ InstallRedis() {
EOF EOF
fi fi
# echo $RedisPort # echo $redis_port
# echo $RedisInstallMethod # echo $redis_install_method
if [[ ${RedisInstallMethod} == "binary" ]]; then if [[ ${redis_install_method} == "binary" ]]; then
installRedisBinary ${RedisPort} install_redis_binary "${redis_port}"
else else
installRedisDocker ${RedisPort} install_redis_docker "${redis_port}"
fi fi
FunctionEnd FunctionEnd
} }
installRedisBinary() { #######################################
RedisPort="" # description
# Globals:
# redis_port
# Arguments:
# 1
# Returns:
# 3 ...
#######################################
install_redis_binary() {
redis_port=""
if [[ $1 -ne " " ]]; then if [[ $1 -ne " " ]]; then
RedisPort="$1" redis_port="$1"
echo "Redis Port = ${RedisPort}" echo "Redis Port = ${redis_port}"
fi fi
echo "InstallRedisBinary" echo "InstallRedisBinary"
CMD_REMOVE gcc CMD_REMOVE gcc
installDemandSoftwares gcc wget installDemandSoftwares gcc wget
echo "开始下载 Redis 6.2.6 的二进制包!" echo "开始下载 Redis 6.2.6 的二进制包!"
wget https://oss.107421.xyz/redis-6.2.6.tar.gz wget https://oss.107421.xyz/redis-6.2.6.tar.gz
@@ -94,22 +100,22 @@ installRedisBinary() {
if [ -e redis-6.2.6.conf ] && [ -e redis-server-6.2.6.service ]; then if [ -e redis-6.2.6.conf ] && [ -e redis-server-6.2.6.service ]; then
echo "redis配置文件下载成功开始进行修改" echo "redis配置文件下载成功开始进行修改"
echo "" echo ""
touch /var/log/redis_${RedisPort}.log touch /var/log/redis_${redis_port}.log
mkdir -p /var/redis/${RedisPort} mkdir -p /var/redis/${redis_port}
mkdir -p /etc/redis/ mkdir -p /etc/redis/
sed -i "s/RedisPort/${RedisPort}/g" redis-6.2.6.conf sed -i "s/RedisPort/${redis_port}/g" redis-6.2.6.conf
cp redis-6.2.6.conf /etc/redis/${RedisPort}.conf cp redis-6.2.6.conf /etc/redis/${redis_port}.conf
sed -i "s/RedisPort/${RedisPort}/g" redis-server-6.2.6.service sed -i "s/RedisPort/${redis_port}/g" redis-server-6.2.6.service
cp redis-server-6.2.6.service /etc/init.d/redisd cp redis-server-6.2.6.service /etc/init.d/redisd
cd /etc/init.d cd /etc/init.d
chmod +x /etc/init.d/redisd chmod +x /etc/init.d/redisd
if [ command_exists chkconfig ]; then if command_exists chkconfig ; then
chkconfig redisd on chkconfig redisd on
elif [ command_exists update-rc.d ]; then elif command_exists update-rc.d ; then
update-rc.d redisd defaults update-rc.d redisd defaults
else else
echo "所需要的守护程序未安装,请手动设置!!" echo "所需要的守护程序未安装,请手动设置!!"
@@ -135,17 +141,27 @@ installRedisBinary() {
} }
installRedisDocker() { #######################################
RedisPort="" # description
# Globals:
# RED
# redis_port
# Arguments:
# 1
# Returns:
# 3 ...
#######################################
install_redis_docker() {
redis_port=""
if [[ $1 -ne " " ]]; then if [[ $1 -ne " " ]]; then
RedisPort="$1" redis_port="$1"
echo "Redis Port = ${RedisPort}" echo "Redis Port = ${redis_port}"
fi fi
echo "InstallRedisDocker" echo "InstallRedisDocker"
echo "" echo ""
if [ ! command_exists "docker info" ]; then if ! command_exists "docker info" ; then
colorEcho ${RED} "docker 未安装!! 无法使用docker的方式安装 redis" colorEcho ${RED} "docker 未安装!! 无法使用docker的方式安装 redis"
return 3 return 3
fi fi
@@ -161,7 +177,7 @@ installRedisDocker() {
docker run -d \ docker run -d \
-e ALLOW_EMPTY_PASSWORD=yes \ -e ALLOW_EMPTY_PASSWORD=yes \
-e REDIS_AOF_ENABLED=no \ -e REDIS_AOF_ENABLED=no \
-e REDIS_PORT_NUMBER=${RedisPort} \ -e REDIS_PORT_NUMBER=${redis_port} \
--name redis-server \ --name redis-server \
--network host \ --network host \
bitnami/redis:6.2.6 bitnami/redis:6.2.6
@@ -178,7 +194,7 @@ InstallMysql() {
colorEcho ${BLUE} "本脚本默认安装版本为 8.0.27 的MySQL " colorEcho ${BLUE} "本脚本默认安装版本为 8.0.27 的MySQL "
colorEcho ${BLUE} "本脚本默认安装版本为 8.0.27 的MySQL " colorEcho ${BLUE} "本脚本默认安装版本为 8.0.27 的MySQL "
while [[ $# > 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
-p | --port) -p | --port)
MysqlPort="${2}" MysqlPort="${2}"
@@ -312,7 +328,7 @@ InstallJDK() {
JDK_Install_Method="binary" JDK_Install_Method="binary"
JDKInstallHelp="0" JDKInstallHelp="0"
while [[ $# > 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
-v | --version) -v | --version)
JDK_VERSION="${2}" JDK_VERSION="${2}"
@@ -439,3 +455,21 @@ installJDKPackage() {
java -version java -version
} }
install_golang_1.21.3(){
FunctionStart "开始安装Golang运行环境"
wget --timeout=10 -q https://go.dev/dl/go1.21.3.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz
log "开始配置环境变量!"
sed -i "$ a export GOPATH=/usr/local/go" /etc/profile
sed -i "$ a PATH=$PATH:/usr/local/go/bin" /etc/profile
source /etc/profile
log "查看golang的版本"
go version
}

View File

@@ -0,0 +1,11 @@
version: '3.9'
services:
chatgpt-next-web:
container_name: chatgpt-next-web
image: yidadaa/chatgpt-next-web
ports:
- 3002:3000
environment:
- OPENAI_API_KEY=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
- CODE=lovemm.23
- HIDE_USER_API_KEY=1