发布时间:2026-07-21阅读(1)
Linux有很多标准化的内容,这里总结了下用一键脚本来设置,下面的命令请看懂后再执行。
系统环境标准化
分区标准化
系统配置标准化
软件标准化
1、系统环境标准化 - 字符集
需求:字符集设置 en_US.utf8
一键优化脚本配置
Centos 7.x
#update system characterlocalectl set-locale LANG=en_US.utf8

注意 Centos 6 和 Centos 7 之间配置的差异
2、系统环境标准化 - 命令行
需求:配置shell,便于定位当前目录
一键优化脚本
#modify PS1echo export PS1="[ \033[01;33m\u\033[0;36m@\033[01;34m\h \033[01;31m\w\033[0m ]\033[0m \n#" >> /etc/profile

3、系统环境标准化 - 内核参数
需求:优化网卡 优化swap
一键优化脚本配置
#tune kernel parametrescat >> /etc/sysctl.conf << EOFnet.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.ip_local_port_range = 10000 65000net.ipv4.tcp_syncookies = 1net.ipv4.tcp_max_tw_buckets = 36000net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_keepalive_time = 600net.ipv4.tcp_fin_timeout = 30vm.swappiness=10vm.max_map_count = 262144EOF

4、系统环境标准化 - 系统参数
需求:打开文件描述符
一键优化脚本配置
#set the file limitcat >> /etc/security/limits.conf << EOF* soft nofile 65535* hard nofile 65535EOF

1、分区标准化 - 标准化分区
需求:
/boot 200M~1G/swap 1G~8G/ 剩余全部
/boot 200M~1G/swap >16G/ 40G/data(Oracle数据目录) 剩余全部
1、系统配置标准化 - YUM环境
需求:
一键优化脚本
假设没有内网repo,就配置阿里YUM源
#clean OS default repomkdir /etc/yum.repos.d/old && mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/#add repowget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repofunction_writelog_judgment "[add aliyun mirrors base]"
2、系统配置标准化 - 系统服务
需求:关闭无用服务
一键优化脚本
Centos 7.x
目前无优化方案
Centos 6.x
#set system start serviceLANG=enfor chkoff in `chkconfig --list|grep 3:on|awk {print $1}`;do chkconfig --level 3 $chkoff off;done for chkoff in crond network rsyslog sshd;do chkconfig --level 3 $chkoff on;done

3、系统配置标准化 - VIM
需求:VIM基础配置,并增加易读性
一键优化脚本(结尾拷贝到普通用户环境变量)
#modify vimrccat >> /root/.vimrc << EOFsyntax enablesyntax onset rulerset numberset cursorlineset cursorcolumnset hlsearchset incsearchset ignorecaseset nocompatibleset wildmenuset pasteset nowrapset expandtabset tabstop=2set shiftwidth=4set softtabstop=4set gcr=a:block-blinkon0set guioptions-=lset guioptions-=Lset guioptions-=rset guioptions-=Rhighlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONEhighlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONEEOFcp /root/.vimrc /home/oracle/

4、系统配置标准化 - 用户
需求:
一键优化脚本
#add default useruseradd hwb -u 2019echo hwb@)!& | passwd --stdin hwb && history -c #set sudo authorityecho "" >> /etc/sudoersecho "#set sudo authority" >> /etc/sudoersecho "hwb ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
5、系统配置标准化 - SSH
需求:
一键优化脚本
\cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date %F`sed -i s/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/ /etc/ssh/sshd_configsed -i s/#UseDNS yes/UseDNS no/ /etc/ssh/sshd_configsed -i s%#PermitRootLogin yes%PermitRootLogin no%g /etc/ssh/sshd_configsed -i s%#PermitEmptyPasswords no%PermitEmptyPasswords no%g /etc/ssh/sshd_config#sed -i s%#Port 22%Port 52020%g /etc/ssh/sshd_config
6、系统配置标准化 - 时间
需求
一键优化脚本
echo "* 4 * * * /usr/sbin/ntpdate ${ntp_server}> /dev/null 2>&1" >> /var/spool/cron/root
7、系统配置标准化 - Selinux
需求:关闭selinux
一键优化脚本
sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config

8、系统配置标准化 - 关闭ctrl alt del快捷键
需求:关闭ctrl alt del快捷键
一键优化脚本
centos 7.x
mv /usr/lib/systemd/system/ctrl-alt-del.target /usr/lib/systemd/system/ctrl-alt-del.target.bak
centos 6.x
mv /etc/init/control-alt-delete.conf /etc/init/control-alt-delete.conf.bak
1、软件标准化 - 常用软件包
需求:安装常用软件
一键优化脚本
yum -y install ntp wget tree telnet sysstat sysstat iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools nmap screen
2、软件标准化 - 升级软件包
需求:升级当前软件包
一键优化脚本
yum -y update
3、配套软件标准化 - 公钥(管理机免密钥)
需求:
一键优化脚本
wget http://xx.xx.xx.xx/ansible_key -O /tmp/ansible_keycat /tmp/ansible_key >> /home/hwb/.ssh/authorized_keysrm -f /tmp/ansible_key
篇幅有限,这块就先介绍到这了,如果大家想做公司标准化这一块,建议还是根据公司实际情况去具体设置,最后再根据需求统一写成一个shell脚本,这样一个标准化的脚本就建立起来了。后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注一下~

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图