本期带来一个超级程序!在linux界面实现类图像化界面的操作体验。具体功能代码如下:
1733行完整代码
想要完成部署,只需在本地创建一个QiaoMuOS.sh的文件,然后将源码复制进去即可,启动的时候使用指令,sh QiaoMuOS.sh
即可开启使用!
完成源码如下:
#!/usr/bin/bash
# *******************************************#
# #
# * CDDN : M乔木 #
# * qq邮箱 : [email protected] #
# * 创建时间 : 2023-12-29 11:40:59 #
# * 解释器 : 这是一个shell脚本 #
# #
# *******************************************#
#声明函数
function zz_ll(){
clear
cat<<EOF
=============================
作者信息
=============================
CSDN: M乔木
mail: [email protected]
=============================
EOF
read -p "输入q退出" zzname
case $zzname in
q)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
clear
cat <<EOF
===============
"输入错误"
"已结束运行!"
===============
EOF
exit 6
esac
}
function qhnetw(){
clear # 清除屏幕
cat<<EOF # 输出菜单内容
=======================
1.有线网络---wired
2.无线网络---wireless
3.退出程序
=======================
EOF
read -p "请输入序列号" networkid # 提示用户输入序列号
case $networkid in # 根据用户输入的序列号执行相应的操作
1)
echo "开始切换有线网络..." # 输出提示信息
sed -i 's/BOOTPROTO="dhcp"/BOOTPROTO="none"/' /etc/sysconfig/network-scripts/ifcfg-ens33 # 修改配置文件,禁用DHCP
systemctl restart network # 重启网络服务
wiredid=`ip a | grep ens33 | grep 10 | awk '/inet/{print $2}' | awk -F"/" '{print $1}'` # 获取当前有线网络IP地址
echo "当前最新ip为:$wiredid" # 输出当前IP地址
exit 0 # 退出函数
;;
2)
echo "开始切换无线网络..." # 输出提示信息
sed -i 's/BOOTPROTO="none"/BOOTPROTO="dhcp"/' /etc/sysconfig/network-scripts/ifcfg-ens33 # 修改配置文件,启用DHCP
systemctl restart network # 重启网络服务
wirelessid=`ip a | grep ens33 | grep 192 | awk '{print $2}' | awk -F"/" '{print $1}'` # 获取当前无线网络IP地址
echo "当前最新ip为:$wirelessid" # 输出当前IP地址
exit 0 # 退出函数
;;
3)
clear
echo "========"
echo "已退出"
echo "========"
exit 0 # 退出函数
;;
*)
clear
echo ==================
echo "输入错误 重新运行" # 输出错误提示信息
echo ==================
sleep 1 # 等待1秒
qhnetw # 重新调用函数qhnetw
esac
}
function jqhfun(){
clear
cat<<EOF
=====================
1.第一次使用请点这里
2.登录远程服务器
3.远程操作设备
4.历史登录服务器列表
5.查看密码本
6.删除密码本
7.返回主菜单
8.退出程序
======================
EOF
read -p "请输入序列号:" jqhnum
case $jqhnum in
1)
clear
#创建环境 下载sshpass 和 创建后面要用的密码本 即:/opt/sshpass_passwd 该目录里的文件用于存储每一台服务器的账号密码ip地址
echo "正在准备第一次使用所需的环境..."
if [ -d /opt/sshpass_passwd ];then
echo "环境已准备好 请勿再输入1.选项"
else
yum -y install sshpass &>/dev/null #|| echo "yum源异常无法下载环境已退出" ;exit 2
mkdir /opt/sshpass_passwd # || echo "密码本创建异常已停止,请检查/opt目录下有没有包含sshpass的同名目录或文件,请修改冲突文件或删除冲突文件之后重新运行程序" ;exit 2
echo "本目录为sshpass远程连接所用密码存储目录请勿修改,否则可能出现异常!" >/opt/sshpass_passwd/instruction_book.txt
jqhfun
fi
;;
2)
clear
echo "开始登录远程服务器"
sleep 1
read -p "请输入你的服务器用户名" name_jqh
sleep 1
read -p "请输入你的服务器密码" passwd_jqh
sleep 1
read -p "请输入你的服务器ip" ip_jqh
sleep 1
echo $passwd_jqh >/opt/sshpass_passwd/$name_jqh.md
sshpass -f /opt/sshpass_passwd/$ip_jqh.md ssh -o StrictHostKeyChecking=no $name_jqh@$ip_jqh
;;
3)
clear
read -pp "请输入你的远程操作命令[注意格式和间隔]" jqh_admin
sshpass -f /opt/sshpass_passwd/$name_jqh.md ssh $name_jqh@$ip_jqh "$jqh_admin"
sleep 3
jqhfun
;;
4)
clear
echo "==============================="
ll /opt/sshpass_passwd | awk '{print $9}'
echo "==============================="
sleep 3
jqhfun
;;
5)
clear
echo "==============================="
echo "已打开密码本"
cat /opt/sshpass_passwd/*
echo "==============================="
sleep 3
jqhfun
;;
6)
clear
if [ -d /opt/sshpass_passwd];then
rm -rf /opt/sshpass_passwd
echo "==============================="
echo "密码本已删除"
echo "==============================="
sleep 1
jqhfun
else
echo "==============================="
echo "密码本已删除"
echo "==============================="
sleep 1
jqhfun
fi
;;
7)
menus
;;
8)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
clear
echo ===============
echo "序列号输入错误"
echo ===============
sleep 1
echo ==========
echo "重新输入"
echo ==========
jqhfun
esac
}
function phpintnginx(){
clear
echo "开始配置nginx支持php页面..."
sleep 1
echo "开始配置nginx请求php信息..."
cd /etc/nginx/
mv nginx.conf nginx.conf.LinuxGj
sleep 1
echo "你的初始化nginx配置文件已更名为:nginx.conf.LinuxGj"
echo "正在创建新的配置文件..."
cat >>nginx.conf<<EOF
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
cd /
sleep 1
echo "正在检查配置文件语法..."
nginx -t &>/dev/null
nginx -s reload &>/dev/null
sleep 1
echo "nginx关联php文件成功"
wbcg
}
function pingip(){
> /opt/a.md
> /opt/b.md
for i in {1..254}
do
{
ping -W1 -c3 10.12.153.$i &>/dev/null
if [ $? -eq 0 ]
then
echo "10.12.153.${i} 此ip繁忙" >> /opt/b.md
else
echo "10.12.153.${i} 此ip空闲" >> /opt/a.md
fi
}&
done
sleep 3
read -p "请选择查看空闲IP还是已用iP[1|2]" IPnumxz
case $IPnumxz in
1)
echo "========================"
echo "已显示前十条空闲ip"
cat /opt/a.md | head
echo "========================"
sleep 6
;;
2)
echo "========================"
echo "已显示前十条已用ip"
cat /opt/b.md | head
echo "========================"
sleep 6
;;
*)
echo "序列号输入错误重新运行"
pingip
esac
rm -f /opt/a.md
rm -f /opt/b.md
onekey
}
function akey(){
clear
cat<<EOF
==================
1.启动apache
2.停止apache
3.重启apache
4.查看apache状态
5.返回上一级
6.退出程序
==================
EOF
read -p "请输入序列号" akeynum
case $akeynum in
1)
systemctl start httpd
echo "已启动apache"
sleep 2
akey
;;
2)
systemctl stop httpd
echo "已停止apache"
sleep 2
akey
;;
3)
systemctl restart httpd
echo "已重启apache"
sleep 2
akey
;;
4)
systemctl status httpd
echo "已打开apache状态"
sleep 3
akey
;;
5)
lnmpkey
;;
6)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ===============
echo "序列号输入错误"
echo ===============
sleep 1
echo ==========
echo "重新输入"
echo ==========
akey
esac
}
function pkey(){
clear
cat<<EOF
================
1.启动php
2.停止php
3.重启php
4.查看php状态
5.返回上一级
6.退出程序
================
EOF
read -p "请输入序列号" pkeynum
case $pkeynum in
1)
systemctl start php-fpm
echo "已启动php"
sleep 2
pkey
;;
2)
systemctl stop php-fpm
echo "已停止php"
sleep 2
pkey
;;
3)
systemctl restart php-fpm
echo "已重启php"
sleep 2
pkey
;;
4)
systemctl status php-fpm
echo "已打开php状态"
sleep 3
pkey
;;
5)
lnmpkey
;;
6)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ===============
echo "序列号输入错误"
echo ===============
sleep 1
echo ==========
echo "重新输入"
echo ==========
pkey
esac
}
function mkey(){
clear
cat<<EOF
================
1.启动MySQL
2.停止MySQL
3.重启MySQL
4.查看MySQL状态
5.返回上一级
6.退出程序
================
EOF
read -p "请输入序列号" mkeynum
case $mkeynum in
1)
systemctl start mysqld
echo "已启动MySQL"
sleep 2
mkey
;;
2)
systemctl stop mysqld
echo "已停止MySQL"
sleep 2
mkey
;;
3)
systemctl restart mysqld
echo "已重启MySQL"
sleep 2
mkey
;;
4)
systemctl status mysqld
echo "已打开MySQL状态"
sleep 3
mkey
;;
5)
lnmpkey
;;
6)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ===============
echo "序列号输入错误"
echo ===============
sleep 1
echo ==========
echo "重新输入"
echo ==========
mkey
esac
}
function nkey(){
clear
cat<<EOF
=================
1.启动nginx
2.停止nginx
3.重启nginx
4.查看nginx状态
5.返回上一级
6.退出程序
=================
EOF
read -p "请输入序列号" nkeynum
case $nkeynum in
1)
systemctl start nginx
echo "已启动nginx"
sleep 2
nkey
;;
2)
systemctl stop nginx
echo "已停止nginx"
sleep 2
nkey
;;
3)
systemctl restart nginx
echo "已重启nginx"
sleep 2
nkey
;;
4)
systemctl status nginx
echo "已打开nginx状态"
sleep 3
nkey
;;
5)
lnmpkey
;;
6)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ===============
echo "序列号输入错误"
echo ===============
sleep 1
echo ==========
echo "重新输入"
echo ==========
nkey
esac
}
function lnmpkey(){
clear
cat<<EOF
=====================
1.nginx管理
2.MySQL管理
3.PHP管理
4.apache管理
5.返回主菜单
6.退出程序
=====================
EOF
read -p "请输入序列号" numlnmp
case $numlnmp in
1)
nkey
;;
2)
mkey
;;
3)
pkey
;;
4)
akey
;;
5)
menus
;;
6)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ===============
echo "序列号输入错误"
echo ===============
sleep 1
echo =========
echo "重新输入"
echo =========
lnmpkey
esac
}
function onekey(){
clear
cat<<EOF
=====================
1.LNMP管理界面
2.查看空闲局域网IP
3.切换系统提示到中文
4.查看防火墙selinux
5.查看yum仓库
6.密码生成器
7.返回主菜单
8.退出程序
======================
EOF
read -p "请输入序列号" numkey
case $numkey in
1)
lnmpkey
;;
2)
pingip
;;
3)
export LANG=zh_CN.UTF-8 &>/dev/null
onekey
;;
4)
getenforce && systemctl status firewalld
sleep 5
onekey
;;
5)
echo "开始清理yum缓存"
sleep 1
yum clean all &>/dev/null
echo "开始生成yum缓存"
sleep 1
yum makecache &>/dev/null
echo "开始抓取yum仓库包数量"
sleep 1
yum repolist
sleep 5
onekey
;;
6)
passwdbcm
onekey
;;
7)
menus
;;
8)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ================
echo "序列号输入错误"
echo ================
sleep 1
echo ==========
echo "重新输入"
echo ==========
onekey
esac
}
function Apachefunct(){
clear
echo "开始安装apache..."
sleep 1
#调用函数 关闭防火墙
fwset
#安装阿帕奇
sleep 1
echo "即将开始安装阿帕奇服务器 本次安转将持续两分钟请耐心等待..."
yum -y install httpd &>/dev/null
#启动阿帕奇
systemctl start httpd
echo "apache安装成功! 现在可以使用system工具来使用管理PHP了!"
sleep 1
cat<<EOF
system工具管理apache
systemctl start httpd --启动apache
systemctl restart httpd --重启apache
systemctl stop httpd --停止apache
systemctl status httpd --查看apache状态
EOF
sleep 3
wbcg
}
function PHPfunct(){
clear
echo "开始安装PHP..."
sleep 1
echo "本次安装将根据网速的情况持续2分钟到五分钟左右,请耐心等待..."
yum -y install php php-fpm php-curl php-intl php-mcrypt php-mysql php-mbstring php-xml php-dom php-gd gd &>/dev/null
echo "PHP安装成功! 现在可以使用system工具来使用管理PHP了!"
sleep 1
cat<<EOF
system工具管理PHP
systemctl start php-fpm --启动php
systemctl restart php-fpm --重启php
systemctl stop php-fpm --停止php
systemctl status php-fpm --查看php状态
EOF
sleep 3
wbcg
}
function MySqlfunct(){
clear
echo "开始安装MySQL..."
sleep 1
read -p "请选择是否清理环境[y|n]" hjmysql
case $hjmysql in
y)
echo "开始清理环境"
yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y &>/dev/null
userdel -r mysql &>/dev/null
rm -rf /etc/my* &>/dev/null
rm -rf /var/lib/mysql &>/dev/null
sleep 1
echo "环境清理完毕..."
;;
n)
sleep 1
echo "已跳过清理环境..."
sleep 1
;;
*)
echo "序列号输入错误,已退出"
echo "请重新运行程序"
exit 9
esac
#调用关闭防火墙函数 fwset
fwset
#下载MySQLyum源
echo "开始安装MySQL 整个过程将根据网络持续1~5分钟 请耐心等待..."
yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm &>/dev/null
#清理缓存生成缓存
yum clean all &>/dev/null
yum makecache &>/dev/null
#安装MySQL
yum install -y mysql-community-server --enablerepo mysql57-community --disablerepo mysql80-community &>/dev/null
#安装结束
sleep 1
echo "安装成功!开始感受畅快淋漓的澎湃MySQL的体验"
read -p "请选择是否关闭密码策略并修改密码[y|n]" MYpasswd
case $MYpasswd in
y)
systemctl start mysqld
passwdmysql=`awk '/temporary password/{p=$NF}END{print p}' /var/log/mysqld.log`
echo '正在设置密码,请稍后'
echo 'validate-password=OFF' >> /etc/my.cnf
systemctl restart mysqld
read -p '请输入新密码:' passwdmysqldx
mysqladmin -uroot -p"$passwdmysql" password "$passwdmysqldx" &>/dev/null
echo '安装完成,密码已设置为:'$passwdmysqldx
sleep 1
cat<<EOF
system工具管理MySQL
systemctl start mysqld --启动MySQL
systemctl restart mysqld --重启MySQL
systemctl stop mysqld --停止MySQL
systemctl status mysqld --查看MySQL状态
EOF
sleep 3
wbcg
;;
n)
systemctl start mysqld
passwdmysql=`awk '/temporary password/{p=$NF}END{print p}' /var/log/mysqld.log`
echo "初始密码为:"$passwdmysql
echo "初始密码为:$passwdmysql" >/MySQL.txt
sleep 1
echo "初始密码已发送到根目录下"
sleep 1
read -p "是否要修改密码 修改密码要符合密码强度策略[y|n]" passwdxg
case $passwdxg in
y)
read -p "请输入新密码:" adminpasswd
mysqladmin -uroot -p"$passwdmysql" password "$adminpasswd" &>/dev/null
;;
n)
echo ""
;;
*)
echo "序列号输入错误 无法修改密码"
sleep 1
echo "请自行到根下的MySQL.txt文件获取初始密码并修改"
sleep 1
echo "修改密码命令已发送到MySQL.txt中 请查收!"
echo "请使用此命令修改密码:mysqladmin -uroot -p""initial-passwd"" password ""new-passwd""" >> /MySQL.txt
esac
cat<<EOF
system工具管理MySQL
systemctl start mysqld --启动MySQL
systemctl restart mysqld --重启MySQL
systemctl stop mysqld --停止MySQL
systemctl status mysqld --查看MySQL状态
EOF
sleep 3
wbcg
;;
*)
echo "序列号输入错误,已退出"
echo "已结束运行程序"
exit 9
esac
}
function NGfunct(){
clear
read -p "安装前是否准备环境[y|n]" NGfunctjc
case $NGfunctjc in
y)
sleep 1
;;
n)
echo "请前往系统设置[关闭防火墙|校准时间|固定IP]"
sleep 3
systemft
;;
*)
echo ======================
echo "序列号输入错误,已退出"
echo "请重新运行程序"
echo ======================
exit 9
esac
echo "开始安装Nginx..."
yum -y install nginx
echo "==================================================="
echo "现在可以使用system工具开始管理Nginx了"
echo "支持操作 systenctl[start|restart|stop|status]Nginx"
echo "==================================================="
sleep 3
wbcg
}
function JCset(){
clear
#开机欢迎
SHAN='\E[33;5m' #黄色闪烁警示
RES='\E[0m' # 清除颜色
echo "========================================"
echo " "
echo -e " ${SHAN} 欢迎使用乔木的基础环境配置脚本3.0 ${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo " "
echo "========================================"
#关闭防火墙
echo "开始关闭防火墙..."
sleep 1
systemctl disable firewalld &>/dev/null
echo "防火墙已关闭..."
sleep 1
#关闭selinux
echo "开始关闭selinux..."
sleep 1
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
echo "selinux已关闭..."
sleep 1
#修改主机名 定义变量nameeJC 接收输入
echo "开始修改主机名..."
sleep 1
read -p "请输入你想修改的主机名" nameeJC
hostnamectl set-hostname $nameeJC
echo "主机名修改完毕,设置为$nameeJC"
sleep 1
#固定IP
clear
SHAN='\E[33;5m' #黄色闪烁警示
RES='\E[0m' # 清除颜色
echo "========================================"
echo " "
echo -e " ${SHAN} 欢迎使用固定IP程序 ${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo " "
echo "========================================"
echo "正在配置网卡,请稍后..."
sleep 1
#获取当前网卡配置文件
echo "获取当前网卡配置文件"
sleep 1
wkname=`ls /etc/sysconfig/network-scripts/ | grep ifcfg-ens | cut -d'-' -f2`
#获取IP
echo "获取IP"
sleep 1
ipname=`ip -f inet a show dev $wkname | awk "/inet/{print $2}" | awk '{print $2}' | cut -d'/' -f1`
#删除原有的网卡配置文件
echo "删除原有的网卡配置文件"
sleep 1
rm -rf /etc/sysconfig/network-scripts/ifcfg-$wkname
#设置判断选择网关
echo "桥接模式选择1"
echo "NAT模式选择2"
echo "自动获取默认网关3"
read -p "请输入你的网关:[1|2|3] " wgsname
case $wgsname in
1)
wgname=10.12.153.254
;;
2)
wgname=192.168.100.2
;;
3) yum -y install net-tools &>/dev/null
wgname=`route -n | grep '^0.0.0.0' | awk '{print $2}'`
;;
*)
echo "序列号输入错误,已退出"
echo "请重新运行程序"
exit 9
esac
sleep 1
#设置判断开启DNS
read -p "是否开启DNS:[y|n] " dnsname
case $dnsname in
y)
dnsa=DNS1=114.114.114.114
dnsb=DNS2=8.8.8.8
;;
n)
dnsa=#DNS1=114.114.114.114
dnsb=#DNS2=8.8.8.8
;;
*)
echo "序列号输入错误,已退出"
echo "请重新运行程序"
exit 9
esac
sleep 1
#创建新的网卡配置文件
cd /etc/sysconfig/network-scripts/
cat >ifcfg-$wkname <<EOF
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
NAME="$wkname"
DEVICE="$wkname"
ONBOOT="yes"
IPADDR=$ipname
PREFIX=24
GATEWAY=$wgname
$dnsa
$dnsb
EOF
cd /root
#重启网络服务
echo "重启网络服务"
systemctl restart network
#结束配置
echo "========================================"
echo " "
echo -e " ${SHAN} 本次配置结束! ${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo -e " ${SHAN} 欢迎下次使用! ${RES} "
echo " "
echo "========================================"
#调用函数yumpz yum仓库函数
yumpz
#下载传文件服务
sleep 1
echo "开始下载配置命令包并同步网络时间..."
sleep 1
echo "下载时间根据网络的不同速度也不同,请耐心等待..."
yum -y install lrzsz &>/dev/null
#校准时间
yum -y install ntpdate &>/dev/null
ntpdate time.windows.com &>/dev/null
#下载cowsay
yum -y install cowsay &>/dev/null
#下载扩展tab补全包
yum -y install bash-completion &>/dev/null
#下载vim编辑器
yum -y install vim &>/dev/null
#下载wget下载工具
yum -y install wget &>/dev/null
#下载网络工具包
yum -y install net-tools &>/dev/null
echo "下载结束 同步网络时间成功"
#开机设置提示 定义变量nameeJC
echo "开始设置开机提示..."
sleep 1
read -p "请输入你想要设置的开机欢迎词" nameeJC
cd /root/
echo "开始生成开机提示文件..."
cat >>kj.sh<<EOF
#!/usr/bin/bash
#查看cpu负载
uptime
#内存使用
free -m
#磁盘空间
df -Th
#看日历
cal
#登录欢迎
cowsay -f tux "$nameeJC"
#结束
echo "欢迎回来"
EOF
echo "sh /root/kj.sh" >> /etc/bashrc
echo "开机提示设置成功..."
sleep 1
echo "======================================="
echo " "
echo -e " ${SHAN} 配置结束即将重启... ${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo -e " ${SHAN} 欢迎下次使用! ${RES} "
echo " "
echo "========================================"
#重启程序结束
reboot
}
function fwset(){
echo "开始关闭防火墙..."
sleep 1
systemctl disable firewalld &>/dev/null
echo "防火墙已关闭..."
sleep 1
#关闭selinux
echo "开始关闭selinux..."
sleep 1
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
echo "selinux已关闭..."
sleep 1
echo "请在稍后重启服务器 否则关闭的服务不会生效"
sleep 2
}
function hostTS(){
echo "开始设置开机提示..."
sleep 1
read -p "请输入你想要设置的开机欢迎词" TSname
cd /root/
echo "开始生成开机提示文件..."
cat >>kj.sh<<EOF
#!/usr/bin/bash
#查看cpu负载
uptime
#内存使用
free -m
#磁盘空间
df -Th
#看日历
cal
#登录欢迎
cowsay -f tux "$TSname"
#结束
echo "欢迎回来" "
EOF
echo "sh /root/kj.sh" >> /etc/bashrc
echo "开机提示设置成功:$TSname"
}
function hostnames(){
echo "开始修改主机名..."
sleep 1
read -p "请输入你想修改的主机名" nameht
hostnamectl set-hostname $nameht
echo "主机名修改完毕,设置为$nameht"
sleep 1
}
function yumpz(){
clear
echo "欢迎使用yum仓库程序"
sleep 1
cat <<EOF
==============
1.局域网仓库
2.阿里仓库
==============
EOF
read -p "请选择连接阿里仓库还是局域网仓库[输入序号]" pzcurl
case $pzcurl in
1) echo "开始配置yum源文件..."
sleep 1
read -p "请输入你想连接的yum仓库ip地址,回车默认连接1号仓库" yumpzss
yumipone="10.12.153.1"
yumpzss=${yumpzss:-$yumipone}
rm -f /etc/yum.repos.d/* &>/dev/null || rm -rf /etc/yum.repos.d/* && echo "检测到/etc/yum.repos.d/下有目录,已删除"
cd /etc/yum.repos.d/
echo "开始创建yum源仓库文件..."
cat >>jc.repo<<EOF
[base]
name=base
baseurl=http://$yumpzss/base
gpgcheck=0
enable=1
[epel]
name=epel
baseurl=http://$yumpzss/epel
gpgcheck=0
enable=1
[extras]
name=extras
baseurl=http://$yumpzss/extras
enable=1
gpgcheck=0
[updates]
name=updates
baseurl=http://$yumpzss/updates
gpgcheck=0
enable=1
[remi-safe]
name=remi-safe
baseurl=http://$yumpzss/remi-safe
gpgcheck=0
enable=1
[mysql57]
name=mysql57
baseurl=http://$yumpzss/mysql57
gpgcheck=0
enable=1
EOF
;;
2) echo "开始配置yum源文件..."
sleep 1
echo "开始清理环境..."
rm -f /etc/yum.repos.d/* &>/dev/null || rm -rf /etc/yum.repos.d/* && echo "检测到/etc/yum.repos.d/下有目录,已删除"
#阿里源基础包下载
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#阿里包加强包下载
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
echo "源文件下载完成!"
esac
sleep 1
echo "配置yum源文件结束..."
sleep 1
#启动动画
echo "即将开始配置yum缓存..."
sleep 1
#清理缓存
echo "开始清理本机yum缓存..."
yum clean all &>/dev/null
echo "清理完毕..."
sleep 1
echo "开始生成本地缓存..."
yum makecache &>/dev/null
echo "缓存生成完毕..."
#列出yum包数
sleep 1
echo "即将检索本次安装yun包总数..."
yum repolist
sleep 3
}
function gdIPD(){
clear
SHAN='\E[33;5m' #黄色闪烁警示
RES='\E[0m' # 清除颜色
echo "======================================="
echo " "
echo -e " ${SHAN} 欢迎使用固定IP程序 ${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo " "
echo "========================================"
echo "正在配置网卡,请稍后..."
sleep 1
#获取当前网卡配置文件
echo "获取当前网卡配置文件"
sleep 1
#wkname=`ls /etc/sysconfig/network-scripts/ | grep ifcfg-ens | cut -d'-' -f2`
wkname=`ls /etc/sysconfig/network-scripts/ | awk '/ifcfg/{print}' | cut -d- -f2 | head -1`
#获取IP
echo "获取IP"
sleep 1
ipname=`ip -f inet a show dev $wkname | awk "/inet/{print $2}" | awk '{print $2}' | cut -d'/' -f1`
#删除原有的网卡配置文件
echo "删除原有的网卡配置文件"
sleep 1
rm -rf /etc/sysconfig/network-scripts/ifcfg-$wkname
#设置判断选择网关
echo "桥接模式选择1"
echo "NAT模式选择2"
echo "自动获取默认网关3"
read -p "请输入你的网关:[1|2|3] " wgsname
case $wgsname in
1)
wgname=10.12.153.254
;;
2)
wgname=192.168.100.2
;;
3) yum -y install net-tools &>/dev/null
wgname=`route -n | grep '^0.0.0.0' | awk '{print $2}'`
;;
*)
echo "序列号输入错误,已退出"
echo "请重新运行程序"
exit 9
esac
sleep 1
#设置判断开启DNS
read -p "是否开启DNS:[y|n] " dnsname
case $dnsname in
y)
dnsa=DNS1=114.114.114.114
dnsb=DNS2=8.8.8.8
;;
n)
dnsa=#DNS1=114.114.114.114
dnsb=#DNS2=8.8.8.8
esac
sleep 1
#创建新的网卡配置文件
cd /etc/sysconfig/network-scripts/
cat >ifcfg-$wkname <<EOF
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
NAME="$wkname"
DEVICE="$wkname"
ONBOOT="yes"
IPADDR=$ipname
PREFIX=24
GATEWAY=$wgname
$dnsa
$dnsb
EOF
cd /root
#重启网络服务
echo "重启网络服务"
systemctl restart network
#结束配置
echo "======================================="
echo " "
echo -e " ${SHAN} 本次配置结束! ${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo -e " ${SHAN} 欢迎下次使用! ${RES} "
echo " "
echo "========================================"
}
function systemset(){
clear
cat<<EOF
=============================
1.固定ip
2.校准时间
3.连接yum仓库
4.设置主机名
5.设置开机提示
6.关闭防火墙关闭selinux
7.一键布置环境[功能整合自动]
8.返回主菜单
9.退出程序
=============================
EOF
read -p "请输入序列号" setname
case $setname in
1) gdIPD
systemset
;;
2) echo "开始校准时间..."
yum -y install ntpdate &>/dev/null
ntpdate time.windows.com &>/dev/null
sjs=`date`
echo "时间校准成功"
echo "当前时间为:"$sjs
sleep 3
systemset
;;
3) yumpz
systemset
;;
4) hostnames
systemset
;;
5) hostTS
systemset
;;
6) fwset
systemset
;;
7) JCset
;;
8) menus
;;
9) clear
cat <<EOF
===============
"已退出程序!"
===============
EOF
exit 0
;;
*)
echo ==============================
echo 输入错误的序列号请重新运行程序
esac
echo ==============================
cat <<EOF
1.继续查询
2.退出程序
EOF
read -p "请输入序列号" numks
case $numks in
1) systemset
;;
2) clear
echo "已退出"
;;
*) clear
echo ==========================
echo 序列号输入错误 已结束运行!
echo ==========================
exit 9
esac
echo "========================================"
echo " "
echo -e " ${SHAN} 欢迎下次使用${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo " "
echo "========================================"
exit 0
}
function systemft(){
clear
cat <<EOF
================
1.系统信息查询
2.系统功能设置
3.返回主菜单
4.退出桌面管家
================
EOF
read -p "请输入序列号" systemname
case $systemname in
1) information
;;
2) systemset
;;
3) menus
;;
4) clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*) echo ==============================
echo 输入错误的序列号请重新运行程序
esac
echo ==============================
cat <<EOF
1.继续查询
2.退出程序
EOF
read -p "请输入序列号" numka
case $numka in
1) systemft
;;
2)
clear
echo ========
echo "已退出"
echo ========
;;
*) clear
echo ==========================
echo 序列号输入错误 已结束运行!
echo ==========================
exit 9
esac
echo "========================================"
echo " "
echo -e " ${SHAN} 欢迎下次使用${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo " "
echo "========================================"
exit 0
}
function information(){
clear
SHAN='\E[33;5m' #黄色闪烁警示
RES='\E[0m' # 清除颜色
echo "*================================"
echo " "
echo -e " ${SHAN} 欢迎使用信息查询工具箱${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected] "
echo ""
echo "================================="
cat <<EOF
=============================
1.剩余空闲内存查询
2.根目录使用的情况
3.当前登录的用户
4.本机ip查询(终端)
5.客户端IP查询(win端设备)
6.查询网络情况
7.返回主菜单
8.退出桌面管家
=============================
EOF
read -p "请输入序列号" num
case $num in
1) echo ================================================
echo 剩余空闲内存:`free -h | awk '/^Mem/{print $4}'`
;;
2) echo ================================================
echo 总空间:`df -Th | awk '/\/$/{print $3}'`
echo 已用空间:`df -Th | awk '/\/$/{print $4}'`
echo 可用空间:`df -Th | awk '/\/$/{print $5}'`
;;
3) echo ================================================
echo 当前登录的用户:`echo $USER`
;;
4) echo ================================================
echo 本机ip查询[终端]:`ip a | grep inet | tail -2 | head -1 | awk '{print $2}' | cut -d'/' -f1`
;;
5) echo ================================================
echo 客户端IP查询[win端设备]:`w | grep root | tail -1 | awk '{print $3}'`
;;
6) read -p "请输入你的ip地址,回车默认测试本机ip!" ipnum
ipnmus=`ip a | awk '/inet/{print}' | head -3 | tail -1 | awk '{print $2}' | cut -d/ -f1`
ipnum=${ipnum:-$ipnmus}
ping -W1 -c3 $ipnum &>/dev/null && echo "网络通畅,测试结束" || echo "网络未连接,请检查配置文件"
;;
7) menus
;;
8) clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo ==============================
echo 输入错误的序列号请重新运行程序
esac
echo ==============================
cat <<EOF
1.继续查询
2.退出程序
EOF
read -p "请输入序列号" numkb
case $numkb in
1) information
;;
2)
clear
echo ========
echo "已退出"
echo ========
;;
*) clear
echo ===========================
echo 序列号输入错误 已结束运行!
echo ===========================
exit 9
esac
echo "========================================"
echo ""
echo -e " ${SHAN} 欢迎下次使用${RES} "
echo " CSDN: M乔木 "
echo " 邮箱: [email protected]"
echo " "
echo "========================================"
exit 0
}
function wbcg(){
echo "LNMP"
clear
cat<<EOF
================
1.Nginx
2.MySql
3.PHP
4.Apache
5.关联phpNginx
6.返回主菜单
7.退出桌面管家
================
EOF
read -p "请输入序号" wbcgid
case $wbcgid in
1)
NGfunct
;;
2)
MySqlfunct
;;
3)
PHPfunct
;;
4)
Apachefunct
;;
5)
phpintnginx
;;
6)
menus
;;
7)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
echo =================================
echo 输入错误的序列号请重新运行程序
esac
echo =================================
cat <<EOF
1.继续查询
2.退出程序
EOF
read -p "请输入序列号" numwzgn
case $numwzgn in
1) wbcg
;;
2)
clear
echo "已退出"
;;
*) clear
echo ==========================
echo 序列号输入错误 已结束运行!
echo ==========================
exit 9
esac
echo "========================================="
echo ""
echo -e " ${SHAN} 欢迎下次使用${RES}"
echo " CSDN: M乔木"
echo " 邮箱: [email protected]"
echo ""
echo "=========================================="
exit 0
}
function DBback(){
echo "开始备份数据库..."
read -p "请输入你的数据库的用户名" dbname
read -p "请输入你的数据库密码" dbpasswd
mkdir /DBbake
mysqldump -u$dbname -p$dbpasswd -A >/DBbake/"`date +%F-%T`DBbake".sql
echo "数据库备份完成!存储目录为:/DBbake,请到该目录下查看"
exit 0
}
function passwdbcm(){
clear
echo "====================="
echo "开始生成随机安全密码..."
echo "====================="
nja=`uuidgen | cut -d- -f1`
njb=`uuidgen | cut -d- -f2`
njc=$RANDOM@
njd=G$njb$nja$njc
sleep 1
echo "===================================="
echo "随机安全密码为:$njd"
echo "===================================="
echo "随机安全密码为:$njd 创建时间为:`date +%F-%T`" >/sjpass.md
sleep 1
echo "==================================================="
echo "随机安全密码已生成,已存储到路径:/sjpass.md中,请妥善保管"
echo "==================================================="
sleep 3
}
function appstore(){
clear
cat<<EOF
========================
应用商店
========================
1.vim文本编辑器
2.ntpdate校准时间工具
3.cowsay奶牛说
4.tab补全包
5.wget下载工具
6.网络工具包
7.lrzsz工具
8.返回主菜单
9.退出桌面管家
========================
EOF
read -p "请输入序号" appnum
case $appnum in
1) echo "正在下载vim文本编辑器..."
yum -y install vim &>/dev/null
echo "安装成功已退出"
;;
2) echo "开始下载ntpdate校准时间工具,并校准时间..."
yum -y install ntpdate $>/dev/null
ntpdate time.windows.com &>/dev/null
echo "安装成功已退出"
;;
3) echo "开始下载cowsay..."
yum -y install cowsay &>/dev/null
echo "安装成功已退出"
;;
4) echo "开始下载tab补全包"
yum -y install bash-completion &>/dev/null
echo "安装成功已退出"
;;
5) echo "开始下载wget工具..."
yum -y install wget &>/dev/null
echo "安装成功已退出"
;;
6) echo "开始下载网络工具包..."
yum -y install net-tools &>/dev/null
echo "安装成功已退出"
;;
7) echo "正在上下传文件工具.."
yum -y install lrzsz &>/dev/null
echo "安装成功已退出"
;;
8) menus
;;
9) clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
clear
echo "==========================="
echo "该序列号软件还未开发,敬请期待"
echo "已退出程序"
echo "==========================="
esac
exit 2
}
function menus(){
clear
SHAN='\E[33;5m' #黄色闪烁警示
RES='\E[0m' # 清除颜色
echo "======================"
echo -e " ${SHAN}欢迎使用 QiaoMuOS 1.0${RES}"
cat <<EOF
======================
1. 系统功能
2. LNMP部署
3. 堡垒机
4. 数据库备份
5. 应用商店
6. 小程序
7. 网络适配
8. 联络作者
9. 退出程序
======================
EOF
read -p "请输入序列号" nova
case $nova in
1)
systemft
;;
2)
wbcg
;;
3)
jqhfun
;;
4)
DBback
;;
5)
appstore
;;
6)
onekey
;;
7)
qhnetw
;;
8)
zz_ll
;;
9)
clear
cat <<EOF
==============
"已退出程序!"
==============
EOF
exit 0
;;
*)
clear
cat <<EOF
=============================
"序列号输入错误,功能暂未开发"
"已退出程序!"
=============================
EOF
exit 9
esac
}
#====================================================
#调用显示主菜单 menus
menus