当前位置: 首页 > news >正文

Linux模板机优化实操

  1. 防火墙,selinux
  • 防火墙关闭
点击查看代码
systemctl stop firewalld 
systemctl disable  firewalld#ubuntu系统
systemctl  disable  ufw 
systemctl  stop   ufw
  • 防火墙检查
点击查看代码
systemctl status firewalld
  • selinux关闭
点击查看代码
setenforce  0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g'  /etc/selinux/config
  • selinux检查
点击查看代码
[root@oldboy-muban ~]# grep disabled /etc/selinux/config 
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
[root@oldboy-muban ~]# getenforce 
Permissive  #或是是disabled都是关闭
  1. yum与apt源与安装常用工具
  • 配置centos
点击查看代码
#配置base源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#增加epel源
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
#安装常用工具
yum install -y vim tree wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils nethogs expect ntpdate
yum install -y sl cowsay
  • 麒麟
点击查看代码
#增加epel源
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
#安装麒麟常用软件
yum install -y vim tree wget bash-completion lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bind-utils nethogs expect ntpdate
  • ubuntu 22.04
点击查看代码
cp  /etc/apt/sources.list{,.bak}cat  >/etc/apt/sources.list<<EOFdeb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOFapt update#安装常用工具
apt install -y tree vim   telnet  lrzsz   nmap  ncat  ntpdate
  1. ssh远程连接加速
点击查看代码
#关闭ssh远程连接反向解析功能,加速ssh远程连接.
#修改ssh服务端配置文件
#1.注释掉已有的配置
sed -i '/^GSSAPIAuthentication/s@^@#@g' /etc/ssh/sshd_config
#2.关闭对应功能
cat >>/etc/ssh/sshd_config<<EOF
UseDNS no
GSSAPIAuthentication no
#关闭dns反向解析  ip-->域名
#kylin系统默认允许root远程登陆,ubuntu系统默认root用户不能远程登录
#PermitRootLogin yes
EOF
#3.重启sshd
systemctl restart sshd
#ubuntu的命令为systemctl restart ssh
#4.检查
egrep '^(PermitRootLogin|GSSAPIAuthentication|UseDNS)' /etc/ssh/sshd_config#结果有2个no即可.
  1. 时间同步
点击查看代码
cat >/var/spool/cron/root<<EOF
*/3 * * * * /sbin/ntpdate ntp.aliyun.com  >/dev/null  2>&1
EOF#ubuntu
select-editor
#选2,vim.basic
  1. 配置命令行颜色
点击查看代码
echo "export PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \w\[\e[0m\]]\$ '" >> /etc/profile
  1. 配置rm的别名
点击查看代码
#1.写入别名到/etc/profile中
alias rm='echo pls do not use rm'#2.回收站别名
cat > /server/scripts/recyle-rm.sh << EOF
#!/bin/bash
##############################################################
# File Name:recyle-rm.sh
# Version:V1.0
# Desc:
###############################################################1.vars
files="$@"
dir=/recyle/#2.判断
if [ $# -eq 0 ];thenecho "Help: $0 file dir ...."exit 
fi#3.创建临时目录
#后期可以加入判断 目录不存在则创建
mkdir -p $dir
tmp_dir=`mktemp -d -p ${dir}`#4.把文件,目录...移动到临时目录
#这里未来可以加入更多的判断.
mv -t ${tmp_dir} ${files}#5.文件,目录已经移动到回收站
echo "文件,目录已经移动到回收站:${tmp_dir}"
EOFalias rm='bash /server/scripts/recyle-rm.sh'#2.注释掉已有的rm别名
sed -i '/rm/s@^@#@g' ~/.bashrcsed -i 's@alias.*rm@#&@g' ~/.bashrc
#3.重新登录系统检查#其他别名
cat  >>/etc/profile<<EOF
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
EOF
  1. 修改ip和主机名的脚本
点击查看代码
#kylin
cat > /server/scripts/change.sh << EOF
#!/bin/bash
#author: wangzhi
#desc: change ip and hostname
#version: v7.0 fina
#sh   脚本  主机名  ip地址(新的ip)
eth0_name=ens33
eth1_name=ens34
eth0=/etc/sysconfig/network-scripts/ifcfg-$eth0_name
eth1=/etc/sysconfig/network-scripts/ifcfg-$eth1_name
bak=/backup/#0.backup network config
mkdir -p $bak  
\cp $eth0 $eth1 $bak#1.脚本参数个数
if [ $# -ne 2 ] ;thenecho "请输入2个参数"exit 1
fi#2.模板机ip地址(最后1位)
ip=`hostname -I |awk '{print $1}'|sed 's#.*\.##g'`
#3.新的ip
ip_new=`echo $2 |sed 's#^.*\.##g'`
#4.新的主机名
hostname=$1#5.修改ip
if [ -f $eth0 ];thensed -i "s#10.0.0.$ip#10.0.0.$ip_new#g" $eth0
elseecho "eth0网卡不存在,修改失败"
fiif [ -f $eth1 ];thensed -i "s#172.16.1.$ip#172.16.1.$ip_new#g" $eth1
elseecho "eth1网卡不存在,修改失败"
fiifdown $eth0_name && ifup $eth0_name
ifdown $eth1_name && ifup $eth1_name#6.修改主机名
hostnamectl set-hostname $hostname
EOF#ubuntu
cat > /server/scripts/changeip.sh << EOF
#!/bin/bash
#author: wangzhi
#desc: change ip and hostname
#version: v7.0 fina
#sh   脚本  主机名  ip地址(新的ip)net_config=/etc/netplan/00-installer-config.yaml #0.root?
[ $UID -ne 0 ] && {echo "pls run as root".exit 1
}#1.脚本参数个数
if [ $# -ne 2 ] ;thenecho "请输入2个参数"exit 2
fi#2.模板机ip地址(最后1位)
ip=`hostname -I |awk '{print $1}'|sed 's#.*\.##g'`
#3.新的ip
ip_new=`echo $2 |sed 's#^.*\.##g'`
#4.新的主机名
hostname=$1#5.修改ip
if [ -f $net_config ];thensed -i "s#10.0.0.$ip#10.0.0.$ip_new#g" $net_configsed -i "s#172.16.1.$ip#172.16.1.$ip_new#g" $net_config
elseecho "eth0网卡不存在,修改失败"
fi#6.生效
netplan apply
networkctl reload #7.修改主机名
hostnamectl set-hostname $hostname
EOF#配置脚本命令行运行
chmod  +x /server/scripts/changeip.sh
ln -s  /server/scripts/changeip.sh /bin/
  1. 配置hosts解析

  2. vimrc

点击查看代码
cat >> /etc/vimrc << EOF
set ignorecase 
autocmd BufNewFile *.py,*.cc,*.sh,*.java,*.bash exec ":call SetTitle()"func SetTitle()
if expand("%:e") =~ 'sh\|bash'
call setline(1, "#!/bin/bash")
call setline(2,"##############################################################")
call setline(3, "# File Name:".expand("%"))
call setline(4, "# Version:V1.0")
call setline(5,"##############################################################")endif
endfunc
EOF
  1. 释放被占用的内存 kdump
点击查看代码
#关闭kdump
#1.命令关闭
systemctl disable --now kdump#2.修改启动配置文件
sed  -i  's#crashkernel=1024M,high##g'   /boot/grub2/grub.cfg#3.重启linux系统
  1. 处理tmp
点击查看代码
systemctl mask tmp.mount
umount /tmp/
#重启检查结果
http://www.jsqmd.com/news/29280/

相关文章:

  • 渗透知识靶场实战
  • 第179-180天:横向移动篇入口切换SMB共享WMI管道DCOM组件Impacket套件CS插件
  • 游记 CSP-S2025
  • VRP基本配置命令
  • 2025 年 11 月 CBN 砂轮厂家最新推荐:结合剂迭代 + 精度优化,高耐用产品选购指南
  • Newton迭代法-----牛顿迭代法求解高次方函数的近似根
  • 2025 年 11 月 CBN 砂轮厂家最新推荐:磨料优化 + 工艺升级,高适配产品选购指南
  • 解码LVGL样式
  • 设备调试基础实验
  • 20231302邱之钊密码系统设计实验二一
  • 2025 年 11 月运动木地板厂家最新推荐,成分焕新与效能强化!—— 精准检测与稳定性能深度解析
  • 【软考】信安中级密码学专题
  • 算法 第二次作业
  • JavaScript异步编程:从回调地狱到优雅解决方案
  • 使用JavaScript和Node.js构建简单的RESTful API
  • JavaScript中的闭包:原理、应用与代码
  • 2025 年 11 月 PVC 地板厂家最新推荐,聚焦原料安全与功效稳定的专业产品解析
  • 2025 年 11 月 PVC 地板厂家最新推荐,聚焦原料合规与功效持久的专业产品解析
  • 2025 年 11 月 PVC 地板厂家最新推荐,聚焦成分安全与功效持续的优质产品解析
  • 2025 年 11 月 PVC 地板厂家最新推荐,聚焦原料品质与功效长效性的优质产品解析
  • React Hooks:提升前端开发效率的关键
  • 网络设备命令行
  • 基于BESO方法实现MBB梁一体化拓扑优化
  • 究极干货 —— 用最纯粹的语言,解析 DeepSeek OCR
  • 【图文详细】用HBuilder X写PHP并且能够在浏览器运行打开 - 昵
  • 可视化水表数据并实现用水量超标警报的技术方案
  • 11.2 —— (VP)2022icpc南京
  • 第二次软件工程作业
  • Edge---浏览器优化配置
  • 华为Matebook清灰之后扬声器没声音