编辑
2023-03-17
运维
00
请注意,本文编写于 551 天前,最后修改于 492 天前,其中某些信息可能已经过时。
#!/bin/sh # 更新系统 function update_system() { yum update -y } # 更换阿里云源 function replace_yum() { mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all && yum makecache } # 禁用防火墙 function disable_firewall() { systemctl stop firewalld.service systemctl disable firewalld.service } # 禁用SELinux function disable_selinux() { sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config setenforce 0 } # 安装常用软件 function install_packages() { yum install -y vim net-tools wget curl lsof } # 主菜单 while true; do echo "1. 执行yum update" echo "2. 更换阿里云源" echo "3. 禁用防火墙" echo "4. 禁用SELinux" echo "5. 安装常用软件" echo "6. 执行全部" echo "7. 退出" read -p "请输入选项:" option case $option in 1 ) update_system;; 2 ) replace_yum;; 3 ) disable_firewall;; 4 ) disable_selinux;; 5 ) install_packages;; 6 ) update_system && replace_yum && disable_firewall && disable_selinux && install_packages;; 7 ) exit;; * ) echo "请输入正确的选项";; esac done
#!/bin/bash # 设置时区并同步时间 ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ntpd -q & # 禁用selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # 关闭防火墙 systemctl stop firewalld systemctl disable firewalld # 历史命令显示操作时间 echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/bashrc # SSH超时时间 echo "export TMOUT=600" >> /etc/profile # 禁止root远程登录 sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config # 禁止定时任务向发送邮件 sed -i 's/^MAILTO=root/MAILTO=""/g' /etc/crontab # 设置最大打开文件数 cat <<EOF >> /etc/security/limits.conf * soft nofile 65535 * hard nofile 65535 EOF # 系统内核优化 cat <<EOF >> /etc/sysctl.conf net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_tw_buckets = 20480 net.ipv4.tcp_max_syn_backlog = 20480 net.core.netdev_max_backlog = 262144 net.ipv4.tcp_fin_timeout = 20 EOF # 减少SWAP使用 echo "vm.swappiness = 0" >> /etc/sysctl.conf sysctl -p # 安装系统性能分析工具及其他 yum install -y gcc make autoconf vim sysstat net-tools iostat iftop # 获取MQ堆积量 QUEUE_NAME="example_queue" QUEUE_DEPTH=$(echo "dis qstatus($QUEUE_NAME) queue" | runmqsc | grep "CURDEPTH" | awk '{print $3}') echo "MQ堆积量:$QUEUE_DEPTH"
#!/usr/bin/bash echo "欢迎使用初始化jio本" read -p "是否安装epel源?Y/N:" an1 if [ $an1 = 'y' ] || [ $an1 = 'Y' ];then #安装epel源 echo "正在安装epel源,请耐心等待..." yum -y install epel-release &> /dev/null else break fi { read -p "是否需要配置base源?Y/N:" an2 if [ $an2 = 'y' ] || [ $an2 = 'Y' ];then #配置yum源 /bin/cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak sed -ri "s/\(mirrorlist=\)/#1/g" /etc/yum.repos.d/CentOS-Base.repo sed -ri "s/#\(baseurl=\)/1/g" /etc/yum.repos.d/CentOS-Base.repo else break fi } { read -p "是否需要配置epel源?Y/N:" an3 if [ $an3 = 'y' ] || [ $an3 = 'Y' ];then /bin/cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak sed -ri "s/\(mirrorlist=\)/#1/g" /etc/yum.repos.d/epel.repo sed -ri "s/.*\(baseurl=\)/1/g" /etc/yum.repos.d/epel.repo else break fi } read -p "是否清楚缓存并建立新的缓存?Y/N:" an4 if [ $an4 = 'y' ] || [ $an4 = 'Y' ];then echo "正在清理缓存并建立新的缓存,请稍后..." #清除缓存 yum clean all &> /dev/null #新建缓存 yum makecache &> /dev/null if [ $? -eq 0 ];then echo "缓存建立完成!" else echo "缓存建立失败,请检查网络或者日志文件!" fi else break fi #关闭防火墙 systemctl stop firewalld &> /dev/null systemctl disable firewalld &> /dev/null #关闭selinux setenforce 0 &> /dev/null sed -ri 's/\(SELINUX=\)enforcing/\1disabled' /etc/selinux/config &> /dev/null yum -y install vim wget lsfo &> /dev/null if [ $? -eq 0 ];then echo "常用工具安装完成,祝您使用愉快!" else echo "常用工具安装失败,请检查网络或日志" fi
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Gustav

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!