parent
27dca64b13
commit
273289e9d9
|
@ -1,225 +0,0 @@
|
|||
#!/bin/bash
|
||||
# auth:kaliarch
|
||||
# func:sys info check
|
||||
# version:v1.0
|
||||
|
||||
[ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1
|
||||
sysversion=$(rpm -q centos-release|cut -d- -f3)
|
||||
line="-------------------------------------------------"
|
||||
|
||||
|
||||
[ -d logs ] || mkdir logs
|
||||
|
||||
sys_check_file="logs/$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')-`date +%Y%m%d`.txt"
|
||||
|
||||
# 获取系统cpu信息
|
||||
function get_cpu_info() {
|
||||
Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
|
||||
Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
|
||||
CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
|
||||
CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
|
||||
CPU_Arch=$(uname -m)
|
||||
cat <<EOF
|
||||
CPU信息:
|
||||
|
||||
物理CPU个数:$Physical_CPUs
|
||||
逻辑CPU个数:$Virt_CPUs
|
||||
每CPU核心数:$CPU_Kernels
|
||||
CPU型号:$CPU_Type
|
||||
CPU架构:$CPU_Arch
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统内存信息
|
||||
function get_mem_info() {
|
||||
check_mem=$(free -m)
|
||||
MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB
|
||||
MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB
|
||||
let MemUsed=MemTotal-MemFree
|
||||
MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")
|
||||
report_MemTotal="$((MemTotal/1024))""MB" #内存总容量(MB)
|
||||
report_MemFree="$((MemFree/1024))""MB" #内存剩余(MB)
|
||||
report_MemUsedPercent="$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")""%" #内存使用率%
|
||||
|
||||
cat <<EOF
|
||||
内存信息:
|
||||
|
||||
${check_mem}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统网络信息
|
||||
function get_net_info() {
|
||||
pri_ipadd=$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')
|
||||
pub_ipadd=$(curl ifconfig.me -s)
|
||||
gateway=$(ip route | grep default | awk '{print $3}')
|
||||
mac_info=$(ip link| egrep -v "lo"|grep link|awk '{print $2}')
|
||||
dns_config=$(egrep -v "^$|^#" /etc/resolv.conf)
|
||||
route_info=$(route -n)
|
||||
cat <<EOF
|
||||
IP信息:
|
||||
|
||||
系统公网地址:${pub_ipadd}
|
||||
系统私网地址:${pri_ipadd}
|
||||
网关地址:${gateway}
|
||||
MAC地址:${mac_info}
|
||||
|
||||
路由信息:
|
||||
${route_info}
|
||||
|
||||
DNS 信息:
|
||||
${dns_config}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统磁盘信息
|
||||
function get_disk_info() {
|
||||
disk_info=$(fdisk -l|grep "Disk /dev"|cut -d, -f1)
|
||||
disk_use=$(df -hTP|awk '$2!="tmpfs"{print}')
|
||||
disk_inode=$(df -hiP|awk '$1!="tmpfs"{print}')
|
||||
|
||||
cat <<EOF
|
||||
磁盘信息:
|
||||
|
||||
${disk_info}
|
||||
磁盘使用:
|
||||
|
||||
${disk_use}
|
||||
inode信息:
|
||||
|
||||
${disk_inode}
|
||||
EOF
|
||||
|
||||
|
||||
}
|
||||
|
||||
# 获取系统信息
|
||||
function get_systatus_info() {
|
||||
sys_os=$(uname -o)
|
||||
sys_release=$(cat /etc/redhat-release)
|
||||
sys_kernel=$(uname -r)
|
||||
sys_hostname=$(hostname)
|
||||
sys_selinux=$(getenforce)
|
||||
sys_lang=$(echo $LANG)
|
||||
sys_lastreboot=$(who -b | awk '{print $3,$4}')
|
||||
sys_runtime=$(uptime |awk '{print $3,$4}'|cut -d, -f1)
|
||||
sys_time=$(date)
|
||||
sys_load=$(uptime |cut -d: -f5)
|
||||
|
||||
cat <<EOF
|
||||
系统信息:
|
||||
|
||||
系统: ${sys_os}
|
||||
发行版本: ${sys_release}
|
||||
系统内核: ${sys_kernel}
|
||||
主机名: ${sys_hostname}
|
||||
selinux状态: ${sys_selinux}
|
||||
系统语言: ${sys_lang}
|
||||
系统当前时间: ${sys_time}
|
||||
系统最后重启时间: ${sys_lastreboot}
|
||||
系统运行时间: ${sys_runtime}
|
||||
系统负载: ${sys_load}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取服务信息
|
||||
function get_service_info() {
|
||||
port_listen=$(netstat -lntup|grep -v "Active Internet")
|
||||
kernel_config=$(sysctl -p 2>/dev/null)
|
||||
if [ ${sysversion} -gt 6 ];then
|
||||
service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled")
|
||||
run_service=$(systemctl list-units --type=service --state=running |grep ".service")
|
||||
else
|
||||
service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t)
|
||||
run_service=$(/sbin/service --status-all|grep -E "running")
|
||||
fi
|
||||
cat <<EOF
|
||||
服务启动配置:
|
||||
|
||||
${service_config}
|
||||
${line}
|
||||
运行的服务:
|
||||
|
||||
${run_service}
|
||||
${line}
|
||||
监听端口:
|
||||
|
||||
${port_listen}
|
||||
${line}
|
||||
内核参考配置:
|
||||
|
||||
${kernel_config}
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
function get_sys_user() {
|
||||
login_user=$(awk -F: '{if ($NF=="/bin/bash") print $0}' /etc/passwd)
|
||||
ssh_config=$(egrep -v "^#|^$" /etc/ssh/sshd_config)
|
||||
sudo_config=$(egrep -v "^#|^$" /etc/sudoers |grep -v "^Defaults")
|
||||
host_config=$(egrep -v "^#|^$" /etc/hosts)
|
||||
crond_config=$(for cronuser in /var/spool/cron/* ;do ls ${cronuser} 2>/dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done)
|
||||
cat <<EOF
|
||||
系统登录用户:
|
||||
|
||||
${login_user}
|
||||
${line}
|
||||
ssh 配置信息:
|
||||
|
||||
${ssh_config}
|
||||
${line}
|
||||
sudo 配置用户:
|
||||
|
||||
${sudo_config}
|
||||
${line}
|
||||
定时任务配置:
|
||||
|
||||
${crond_config}
|
||||
${line}
|
||||
hosts 信息:
|
||||
|
||||
${host_config}
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
function process_top_info() {
|
||||
|
||||
top_title=$(top -b n1|head -7|tail -1)
|
||||
cpu_top10=$(top b -n1 | head -17 | tail -11)
|
||||
mem_top10=$(top -b n1|head -17|tail -10|sort -k10 -r)
|
||||
|
||||
cat <<EOF
|
||||
CPU占用top10:
|
||||
|
||||
${top_title}
|
||||
${cpu_top10}
|
||||
|
||||
内存占用top10:
|
||||
|
||||
${top_title}
|
||||
${mem_top10}
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
function sys_check() {
|
||||
get_cpu_info
|
||||
echo ${line}
|
||||
get_mem_info
|
||||
echo ${line}
|
||||
get_net_info
|
||||
echo ${line}
|
||||
get_disk_info
|
||||
echo ${line}
|
||||
get_systatus_info
|
||||
echo ${line}
|
||||
get_service_info
|
||||
echo ${line}
|
||||
get_sys_user
|
||||
echo ${line}
|
||||
process_top_info
|
||||
}
|
||||
|
||||
|
||||
sys_check > ${sys_check_file}
|
|
@ -1,155 +0,0 @@
|
|||
#!/bin/bash
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:git 2.0.0/2.10.0/2.18.0 安装
|
||||
|
||||
# 定义安装目录、及日志信息
|
||||
. /etc/init.d/functions
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
download_path=/tmp/tmpdir/
|
||||
install_log_name=install_git.log
|
||||
env_file=/etc/profile.d/git.sh
|
||||
install_log_path=/var/log/appinstall/
|
||||
install_path=/usr/local/
|
||||
#software_config_file=${install_path}
|
||||
|
||||
clear
|
||||
echo "##########################################"
|
||||
echo "# #"
|
||||
echo "# 安装 git 2.0.0/2.10.0/2.18.0 #"
|
||||
echo "# #"
|
||||
echo "##########################################"
|
||||
echo "1: Install git 2.0.0"
|
||||
echo "2: Install git 2.10.0"
|
||||
echo "3: Install git 2.18.0"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/git/git-2.0.0.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/git/git-2.10.0.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/git/git-2.18.0.tar.gz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
echo "input Error! Place input{1|2|3|4}"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
|
||||
# yum 安装软件包,可传入多个软件包,用空格隔开
|
||||
yum_install_software() {
|
||||
output_msg "yum 安装软件"
|
||||
yum -y install $* >/dev/null 2>${install_log_path}${install_log_name}
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S`yum install $* 完成" >>${install_log_path}${install_log_name}
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
|
||||
# 下载文件并解压至安装目录,传入url链接地址
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 编译安装git,传入$1 为解压后软件包的名称
|
||||
source_install_git() {
|
||||
output_msg "编译安装git"
|
||||
mv ${install_path}${1} ${install_path}tmp${1}
|
||||
cd ${install_path}tmp${1} && make prefix=${install_path}git all >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
make prefix=${install_path}git install >/dev/null 2>&1 echo "`date +%F' '%H:%M:%S` git source install success ">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` git source install fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
check_yum_command make make
|
||||
yum_install_software curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
|
||||
source_install_git ${software_name}
|
||||
mv /usr/bin/git /usr/bin/git.bak
|
||||
|
||||
rm -fr ${download_path}
|
||||
config_env ${install_path}git/bin
|
||||
}
|
||||
|
||||
main
|
||||
|
|
@ -1,139 +0,0 @@
|
|||
#!/bin/bash
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:kafka 0.10.2/0.11.0/1.1.0/2.0.0 安装
|
||||
|
||||
# 定义安装目录、及日志信息
|
||||
. /etc/init.d/functions
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
download_path=/tmp/tmpdir/
|
||||
install_log_name=install_kafka.log
|
||||
env_file=/etc/profile.d/kafka.sh
|
||||
install_log_path=/var/log/appinstall/
|
||||
install_path=/usr/local/
|
||||
software_config_file=${install_path}kafka/config/server.properties
|
||||
|
||||
clear
|
||||
echo "##########################################"
|
||||
echo "# #"
|
||||
echo "# 安装kafka 0.10.2/0.11.0/1.1.0/2.0.0 #"
|
||||
echo "# #"
|
||||
echo "##########################################"
|
||||
echo "1: Install kafka 0.10.2"
|
||||
echo "2: Install kafka 0.11.0"
|
||||
echo "3: Install kafka 1.1.0"
|
||||
echo "4: Install kafka 2.0.0"
|
||||
echo "5: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-0.10.2.2.tgz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-0.11.0.3.tgz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-1.1.0.tgz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/kafka/kafka_2.12-2.0.0.tgz"
|
||||
elif [ "${softversion}" == "5" ];then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
echo "input Error! Place input{1|2|3|4|5}"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
|
||||
# 下载文件并解压至安装目录,传入url链接地址
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ] || [ "${file##*.}" == "tgz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
# 添加配置文件
|
||||
add_config() {
|
||||
cat> $1 <<EOF
|
||||
broker.id=1 #kafka集群标识,不能相同,第一台是1以此类推,其他都一样。
|
||||
log.dirs=/usr/local/kafka/kafka-logs
|
||||
host.name=127.0.0.1 #主机ip
|
||||
#zookeeper.connect=127.0.0.1:2181 #zookeeper连接
|
||||
EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tgz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}kafka
|
||||
add_config ${software_config_file}
|
||||
check_dir ${install_path}kafka/kafka-logs
|
||||
config_env ${install_path}kafka/bin
|
||||
}
|
||||
|
||||
main
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
#!/bin/bash
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:maven 3.0.5/3.3.9/3.5.4 安装
|
||||
|
||||
# 定义安装目录、及日志信息
|
||||
. /etc/init.d/functions
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
download_path=/tmp/tmpdir/
|
||||
install_log_name=install_maven.log
|
||||
env_file=/etc/profile.d/maven.sh
|
||||
install_log_path=/var/log/appinstall/
|
||||
install_path=/usr/local/
|
||||
#software_config_file=${install_path}filebeat/filebeat.yml
|
||||
|
||||
clear
|
||||
echo "##########################################"
|
||||
echo "# #"
|
||||
echo "# 安装 maven 3.0.5/3.3.9/3.5.4 #"
|
||||
echo "# #"
|
||||
echo "##########################################"
|
||||
echo "1: Install maven 3.0.5"
|
||||
echo "2: Install maven 3.2.9"
|
||||
echo "3: Install maven 3.5.4"
|
||||
echo "4: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/maven/apache-maven-3.0.5-bin.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/maven/apache-maven-3.3.9-bin.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/maven/apache-maven-3.5.4-bin.tar.gz"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
echo "input Error! Place input{1|2|3|4}"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
|
||||
# 下载文件并解压至安装目录,传入url链接地址
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'-bin.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}maven
|
||||
config_env ${install_path}maven/bin
|
||||
}
|
||||
|
||||
main
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
#!/bin/bash
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:tomcat 6.0/7.0/8.5/9.0 安装
|
||||
|
||||
# 定义安装目录、及日志信息
|
||||
. /etc/init.d/functions
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
download_path=/tmp/tmpdir/
|
||||
install_log_name=install_tomcat.log
|
||||
env_file=/etc/profile.d/tomcat.sh
|
||||
install_log_path=/var/log/appinstall/
|
||||
install_path=/usr/local/
|
||||
|
||||
clear
|
||||
echo "##########################################"
|
||||
echo "# #"
|
||||
echo "# 安装 tomcat 6.0/7.0/8.5/9.0 #"
|
||||
echo "# #"
|
||||
echo "##########################################"
|
||||
echo "1: Install tomcat-6.0"
|
||||
echo "2: Install tomcat-7.0"
|
||||
echo "3: Install tomcat-8.5"
|
||||
echo "4: Install tomcat-9.0"
|
||||
echo "5: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-6.0.9.zip"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-7.0.79.zip"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-8.5.20.zip"
|
||||
elif [ "${softversion}" == "4" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/tomcat/apache-tomcat-9.0.0.M26.zip"
|
||||
elif [ "${softversion}" == "5" ];then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
echo "input Error! Place input{1|2|3|4|5}"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
|
||||
# 下载文件并解压至安装目录,传入url链接地址
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
check_yum_command unzip unzip
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.zip' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}tomcat
|
||||
config_env ${install_path}tomcat/bin
|
||||
}
|
||||
|
||||
main
|
|
@ -1,137 +0,0 @@
|
|||
#!/bin/bash
|
||||
# auth:kaliarch
|
||||
# version:v1.0
|
||||
# func:zookeeper 3.4/3.5 安装
|
||||
|
||||
# 定义安装目录、及日志信息
|
||||
. /etc/init.d/functions
|
||||
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1
|
||||
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
download_path=/tmp/tmpdir/
|
||||
install_log_name=install_zookeeper.log
|
||||
env_file=/etc/profile.d/zookeeper.sh
|
||||
install_log_path=/var/log/appinstall/
|
||||
install_path=/usr/local/
|
||||
software_config_file=${install_path}zookeeper/conf/zoo.cfg
|
||||
|
||||
clear
|
||||
echo "##########################################"
|
||||
echo "# #"
|
||||
echo "# 安装 zookeeper 3.4/3.5 #"
|
||||
echo "# #"
|
||||
echo "##########################################"
|
||||
echo "1: Install zookeeper 3.4"
|
||||
echo "2: Install zookeeper 3.5"
|
||||
echo "3: EXIT"
|
||||
# 选择安装软件版本
|
||||
read -p "Please input your choice:" softversion
|
||||
if [ "${softversion}" == "1" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/zookeeper/zookeeper-3.4.12.tar.gz"
|
||||
elif [ "${softversion}" == "2" ];then
|
||||
URL="https://anchnet-script.oss-cn-shanghai.aliyuncs.com/zookeeper/zookeeper-3.5.4-beta.tar.gz"
|
||||
elif [ "${softversion}" == "3" ];then
|
||||
echo "you choce channel!"
|
||||
exit 1;
|
||||
else
|
||||
echo "input Error! Place input{1|2|3}"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
# 传入内容,格式化内容输出,可以传入多个参数,用空格隔开
|
||||
output_msg() {
|
||||
for msg in $*;do
|
||||
action $msg /bin/true
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 判断命令是否存在,第一个参数 $1 为判断的命令,第二个参数为提供该命令的yum 软件包名称
|
||||
check_yum_command() {
|
||||
output_msg "命令检查:$1"
|
||||
hash $1 >/dev/null 2>&1
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` check command $1 ">>${install_log_path}${install_log_name} && return 0
|
||||
else
|
||||
yum -y install $2 >/dev/null 2>&1
|
||||
# hash $Command || { echo "`date +%F' '%H:%M:%S` $2 is installed fail">>${install_log_path}${install_log_name} ; exit 1 }
|
||||
fi
|
||||
}
|
||||
|
||||
# 判断目录是否存在,传入目录绝对路径,可以传入多个目录
|
||||
check_dir() {
|
||||
output_msg "目录检查"
|
||||
for dirname in $*;do
|
||||
[ -d $dirname ] || mkdir -p $dirname >/dev/null 2>&1
|
||||
echo "`date +%F' '%H:%M:%S` $dirname check success!" >> ${install_log_path}${install_log_name}
|
||||
done
|
||||
}
|
||||
|
||||
# 下载文件并解压至安装目录,传入url链接地址
|
||||
download_file() {
|
||||
output_msg "下载源码包"
|
||||
mkdir -p $download_path
|
||||
for file in $*;do
|
||||
wget $file -c -P $download_path &> /dev/null
|
||||
if [ $? -eq 0 ];then
|
||||
echo "`date +%F' '%H:%M:%S` $file download success!">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%s` $file download fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# 解压文件,可以传入多个压缩文件绝对路径,用空格隔开,解压至安装目录
|
||||
extract_file() {
|
||||
output_msg "解压源码"
|
||||
for file in $*;do
|
||||
if [ "${file##*.}" == "gz" ];then
|
||||
tar -zxf $file -C $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
elif [ "${file##*.}" == "zip" ];then
|
||||
unzip -q $file -d $install_path && echo "`date +%F' '%H:%M:%S` $file extrac success!,path is $install_path">>${install_log_path}${install_log_name}
|
||||
else
|
||||
echo "`date +%F' '%H:%M:%S` $file type error, extrac fail!">>${install_log_path}${install_log_name} && exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 配置环境变量,第一个参数为添加环境变量的绝对路径
|
||||
config_env() {
|
||||
output_msg "环境变量配置"
|
||||
echo "export PATH=\$PATH:$1" >${env_file}
|
||||
source ${env_file} && echo "`date +%F' '%H:%M:%S` 软件安装完成!">> ${install_log_path}${install_log_name}
|
||||
|
||||
}
|
||||
|
||||
# 添加配置文件
|
||||
add_config() {
|
||||
cat> $1 <<EOF
|
||||
tickTime=2000 #服务之间或者客户端与服务段之间心跳时间
|
||||
initLimit=10 #Follower启动过程中,从Leader同步所有最新数据的时间
|
||||
syncLimit=5 #Leader与集群之间的通信时间
|
||||
dataDir=/usr/local/zookeeper/data #zookeeper存储数据
|
||||
datalogDir=/usr/local/zookeeper/logs #zookeeper存储数据的日志
|
||||
clientPort=2181 #zookeeper默认端口
|
||||
#server.1=127.0.0.1:2888:3888 #集群配置
|
||||
EOF
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dir $install_log_path $install_path
|
||||
check_yum_command wget wget
|
||||
download_file $URL
|
||||
|
||||
software_name=$(echo $URL|awk -F'/' '{print $NF}'|awk -F'.tar.gz' '{print $1}')
|
||||
for filename in `ls $download_path`;do
|
||||
extract_file ${download_path}$filename
|
||||
done
|
||||
rm -fr ${download_path}
|
||||
ln -s $install_path$software_name ${install_path}zookeeper
|
||||
add_config ${software_config_file}
|
||||
check_dir "${install_path}zookeeper/data" "${install_path}zookeeper/logs"
|
||||
echo "1">${install_path}zookeeper/data/myid
|
||||
config_env ${install_path}zookeeper/bin
|
||||
}
|
||||
|
||||
main
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
#DIRS="/var/log /home /opt"
|
||||
|
||||
#DATE=$(date '+%m%d%y')
|
||||
#exec > disk_space_${DATE}.log
|
||||
|
||||
echo "Top Ten Disk Space Usage"
|
||||
echo "for ${DIRS} Directories"
|
||||
for DIR in ${DIRS}
|
||||
do
|
||||
echo ""
|
||||
echo "The ${DIR} Directory:"
|
||||
du -S ${DIR} 2>/dev/null |
|
||||
sort -rn |
|
||||
sed '{11,$D; =}' |
|
||||
sed 'N; s/\n/ /' |
|
||||
gawk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
|
||||
done
|
|
@ -1,31 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Big_Users - find big disk space users in various directories
|
||||
#############################################################
|
||||
#Parameters for script
|
||||
#
|
||||
CHECK_DIRECTORIES="/var/log /home" #directories to check
|
||||
#
|
||||
######################### Main Script #######################
|
||||
#
|
||||
DATE=$(date '+%m%d%y') #Date for report file
|
||||
#
|
||||
exec > disk_space_$DATE.rpt #Make report file Std Output
|
||||
#
|
||||
echo "Top Ten Disk Space Usage" #Report header for while report
|
||||
echo "for $CHECK_DIRECTORIES Directories"
|
||||
#
|
||||
for DIR_CHECK in $CHECK_DIRECTORIES #loop to du directories
|
||||
do
|
||||
echo ""
|
||||
echo "The $DIR_CHECK Directory:" #Title header for each directory
|
||||
#
|
||||
# Creating a listing of top ten disk space users
|
||||
du -S $DIR_CHECK 2>/dev/null |
|
||||
sort -rn |
|
||||
sed '{11,$D; =}' |
|
||||
sed 'N; s/\n/ /' |
|
||||
gawk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
|
||||
#
|
||||
done #End of for loop for du directories
|
||||
#
|
|
@ -0,0 +1,320 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cat << EOF
|
||||
###################################################################################
|
||||
# 系统信息检查脚本
|
||||
# @author: Zhang Peng
|
||||
###################################################################################
|
||||
EOF
|
||||
|
||||
[[ $(id -u) -gt 0 ]] && echo "请用root用户执行此脚本!" && exit 1
|
||||
sysversion=$(rpm -q centos-release|cut -d- -f3)
|
||||
double_line="==============================================================="
|
||||
line="----------------------------------------------"
|
||||
|
||||
# 定义字体色彩
|
||||
C_RESET="$(tput sgr0)"
|
||||
C_BLACK="\033[1;30m"
|
||||
C_RED="\033[1;31m"
|
||||
C_GREEN="\033[1;32m"
|
||||
C_YELLOW="\033[1;33m"
|
||||
C_BLUE="\033[1;34m"
|
||||
C_PURPLE="\033[1;35m"
|
||||
C_CYAN="\033[1;36m"
|
||||
C_WHITE="\033[1;37m"
|
||||
|
||||
# 打印头部信息
|
||||
printHeadInfo() {
|
||||
cat << EOF
|
||||
|
||||
+---------------------------------------------------------------------------------+
|
||||
| 欢迎使用 【系统信息检查脚本】 |
|
||||
| @author: Zhang Peng |
|
||||
+---------------------------------------------------------------------------------+
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# 打印尾部信息
|
||||
printFootInfo() {
|
||||
cat << EOF
|
||||
|
||||
+---------------------------------------------------------------------------------+
|
||||
| 脚本执行结束,感谢使用! |
|
||||
+---------------------------------------------------------------------------------+
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
options=("获取系统信息" "获取服务信息" "获取CPU信息" "获取系统网络信息" "获取系统内存信息" "获取系统磁盘信息" "获取CPU/内存占用TOP10" "获取系统用户信息" "输出所有信息" "退出")
|
||||
printMenu() {
|
||||
printf "${C_BLUE}"
|
||||
printf "主菜单:\n"
|
||||
for i in "${!options[@]}"; do
|
||||
index=`expr ${i} + 1`
|
||||
val=`expr ${index} % 2`
|
||||
printf "\t(%02d) %-30s" "${index}" "${options[$i]}"
|
||||
if [[ ${val} -eq 0 ]]; then
|
||||
printf "\n"
|
||||
fi
|
||||
done
|
||||
printf "${C_BLUE}请输入需要执行的指令:\n"
|
||||
printf "${C_RESET}"
|
||||
}
|
||||
|
||||
# 获取系统信息
|
||||
get_systatus_info() {
|
||||
sys_os=$(uname -o)
|
||||
sys_release=$(cat /etc/redhat-release)
|
||||
sys_kernel=$(uname -r)
|
||||
sys_hostname=$(hostname)
|
||||
sys_selinux=$(getenforce)
|
||||
sys_lang=$(echo $LANG)
|
||||
sys_lastreboot=$(who -b | awk '{print $3,$4}')
|
||||
sys_runtime=$(uptime |awk '{print $3,$4}'|cut -d, -f1)
|
||||
sys_time=$(date)
|
||||
sys_load=$(uptime |cut -d: -f5)
|
||||
|
||||
cat << EOF
|
||||
【系统信息】
|
||||
|
||||
系统: ${sys_os}
|
||||
发行版本: ${sys_release}
|
||||
系统内核: ${sys_kernel}
|
||||
主机名: ${sys_hostname}
|
||||
selinux状态: ${sys_selinux}
|
||||
系统语言: ${sys_lang}
|
||||
系统当前时间: ${sys_time}
|
||||
系统最后重启时间: ${sys_lastreboot}
|
||||
系统运行时间: ${sys_runtime}
|
||||
系统负载: ${sys_load}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取CPU信息
|
||||
get_cpu_info() {
|
||||
Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
|
||||
Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
|
||||
CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
|
||||
CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
|
||||
CPU_Arch=$(uname -m)
|
||||
cat << EOF
|
||||
【CPU信息】
|
||||
|
||||
物理CPU个数:$Physical_CPUs
|
||||
逻辑CPU个数:$Virt_CPUs
|
||||
每CPU核心数:$CPU_Kernels
|
||||
CPU型号:$CPU_Type
|
||||
CPU架构:$CPU_Arch
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取服务信息
|
||||
get_service_info() {
|
||||
port_listen=$(netstat -lntup|grep -v "Active Internet")
|
||||
kernel_config=$(sysctl -p 2>/dev/null)
|
||||
if [[ ${sysversion} -gt 6 ]];then
|
||||
service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled")
|
||||
run_service=$(systemctl list-units --type=service --state=running |grep ".service")
|
||||
else
|
||||
service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t)
|
||||
run_service=$(/sbin/service --status-all|grep -E "running")
|
||||
fi
|
||||
cat << EOF
|
||||
【服务信息】
|
||||
|
||||
${service_config}
|
||||
${line}
|
||||
运行的服务:
|
||||
|
||||
${run_service}
|
||||
${line}
|
||||
监听端口:
|
||||
|
||||
${port_listen}
|
||||
${line}
|
||||
内核参考配置:
|
||||
|
||||
${kernel_config}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统内存信息
|
||||
get_mem_info() {
|
||||
check_mem=$(free -m)
|
||||
MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB
|
||||
MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB
|
||||
let MemUsed=MemTotal-MemFree
|
||||
MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf \"%.2f\",$MemUsed*100/$MemTotal}}")
|
||||
report_MemTotal="$((MemTotal/1024))""MB" #内存总容量(MB)
|
||||
report_MemFree="$((MemFree/1024))""MB" #内存剩余(MB)
|
||||
report_MemUsedPercent=$(free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/')
|
||||
|
||||
cat << EOF
|
||||
【内存信息】
|
||||
|
||||
内存总容量(MB): ${report_MemTotal}
|
||||
内存剩余量(MB):${report_MemFree}
|
||||
内存使用率: ${report_MemUsedPercent}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统网络信息
|
||||
get_net_info() {
|
||||
pri_ipadd=$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')
|
||||
pub_ipadd=$(curl ifconfig.me -s)
|
||||
gateway=$(ip route | grep default | awk '{print $3}')
|
||||
mac_info=$(ip link| egrep -v "lo"|grep link|awk '{print $2}')
|
||||
dns_config=$(egrep -v "^$|^#" /etc/resolv.conf)
|
||||
route_info=$(route -n)
|
||||
cat << EOF
|
||||
【网络信息】
|
||||
|
||||
系统公网地址:${pub_ipadd}
|
||||
系统私网地址:${pri_ipadd}
|
||||
网关地址:${gateway}
|
||||
MAC地址:${mac_info}
|
||||
|
||||
路由信息:
|
||||
${route_info}
|
||||
|
||||
DNS 信息:
|
||||
${dns_config}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统磁盘信息
|
||||
get_disk_info() {
|
||||
disk_info=$(fdisk -l|grep "Disk /dev"|cut -d, -f1)
|
||||
disk_use=$(df -hTP|awk '$2!="tmpfs"{print}')
|
||||
disk_percent=$(free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/')
|
||||
disk_inode=$(df -hiP|awk '$1!="tmpfs"{print}')
|
||||
|
||||
cat << EOF
|
||||
【磁盘信息】
|
||||
|
||||
${disk_info}
|
||||
|
||||
磁盘使用: ${disk_use}
|
||||
磁盘使用百分比: ${disk_percent}
|
||||
inode信息: ${disk_inode}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取系统用户信息
|
||||
get_sys_user() {
|
||||
login_user=$(awk -F: '{if ($NF=="/bin/bash") print $0}' /etc/passwd)
|
||||
ssh_config=$(egrep -v "^#|^$" /etc/ssh/sshd_config)
|
||||
sudo_config=$(egrep -v "^#|^$" /etc/sudoers |grep -v "^Defaults")
|
||||
host_config=$(egrep -v "^#|^$" /etc/hosts)
|
||||
crond_config=$(for cronuser in /var/spool/cron/* ;do ls ${cronuser} 2>/dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done)
|
||||
cat << EOF
|
||||
【用户信息】
|
||||
|
||||
系统登录用户:
|
||||
|
||||
${login_user}
|
||||
${line}
|
||||
ssh 配置信息:
|
||||
|
||||
${ssh_config}
|
||||
${line}
|
||||
sudo 配置用户:
|
||||
|
||||
${sudo_config}
|
||||
${line}
|
||||
定时任务配置:
|
||||
|
||||
${crond_config}
|
||||
${line}
|
||||
hosts 信息:
|
||||
|
||||
${host_config}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 获取CPU/内存占用TOP10
|
||||
get_process_top_info() {
|
||||
|
||||
top_title=$(top -b n1|head -7|tail -1)
|
||||
cpu_top10=$(top b -n1 | head -17 | tail -11)
|
||||
mem_top10=$(top -b n1|head -17|tail -10|sort -k10 -r)
|
||||
|
||||
cat << EOF
|
||||
【TOP10】
|
||||
CPU占用TOP10:
|
||||
|
||||
${top_title}
|
||||
${cpu_top10}
|
||||
|
||||
内存占用TOP10:
|
||||
|
||||
${top_title}
|
||||
${mem_top10}
|
||||
EOF
|
||||
}
|
||||
|
||||
show_dead_process() {
|
||||
printf "僵尸进程:\n"
|
||||
ps -al | gawk '{print $2,$4}' | grep Z
|
||||
}
|
||||
|
||||
get_all_info() {
|
||||
get_systatus_info
|
||||
echo ${double_line}
|
||||
get_service_info
|
||||
echo ${double_line}
|
||||
get_cpu_info
|
||||
echo ${double_line}
|
||||
get_net_info
|
||||
echo ${double_line}
|
||||
get_mem_info
|
||||
echo ${double_line}
|
||||
get_disk_info
|
||||
echo ${double_line}
|
||||
get_process_top_info
|
||||
echo ${double_line}
|
||||
get_sys_user
|
||||
}
|
||||
|
||||
main() {
|
||||
while [[ 1 ]]
|
||||
do
|
||||
printMenu
|
||||
read option
|
||||
local index=$[${option} - 1]
|
||||
case ${options[${index}]} in
|
||||
"获取系统信息")
|
||||
get_systatus_info;;
|
||||
"获取服务信息")
|
||||
get_service_info ;;
|
||||
"获取CPU信息")
|
||||
get_cpu_info ;;
|
||||
"获取系统网络信息")
|
||||
get_net_info ;;
|
||||
"获取系统内存信息")
|
||||
get_mem_info ;;
|
||||
"获取系统磁盘信息")
|
||||
get_disk_info ;;
|
||||
"获取CPU/内存占用TOP10")
|
||||
get_process_top_info ;;
|
||||
"获取系统用户信息")
|
||||
get_sys_user ;;
|
||||
"输出所有信息")
|
||||
get_all_info > sys.log
|
||||
printf "${C_GREEN}信息已经输出到 sys.log 中。${C_RESET}\n\n"
|
||||
;;
|
||||
"退出")
|
||||
exit ;;
|
||||
*)
|
||||
clear
|
||||
echo "抱歉,不支持此选项";;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
######################################## MAIN ########################################
|
||||
printHeadInfo
|
||||
main
|
||||
printFootInfo
|
||||
printf "${C_RESET}"
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#查看僵尸进程
|
||||
ps -al | gawk '{print $2,$4}' | grep Z
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#查看内存使用百分比
|
||||
free | sed -n '2p' | gawk 'x = int(( $3 / $2 ) * 100) {print x}' | sed 's/$/%/'
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#查看磁盘实用百分比
|
||||
df -h /dev/sda1 | sed -n '/% \//p' | gawk '{ print $5 }'
|
Loading…
Reference in New Issue