Linux有很多标准化的内容,这里总结了下用一键脚本来设置,下面的命令请看懂后再执行。
系统环境标准化
分区标准化
系统配置标准化
软件标准化
1、系统环境标准化 - 字符集
需求:字符集设置 en_US.utf8
一键优化脚本配置
Centos 7.x
#update system character
localectl set-locale LANG=en_US.utf8
注意 Centos 6 和 Centos 7 之间配置的差异
2、系统环境标准化 - 命令行
需求:配置shell,便于定位当前目录
一键优化脚本
#modify PS1
echo '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 parametres
cat >> /etc/sysctl.conf << EOF
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_fin_timeout = 30
vm.swappiness=10
vm.max_map_count = 262144
EOF
4、系统环境标准化 - 系统参数
需求:打开文件描述符
一键优化脚本配置
#set the file limit
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
1、分区标准化 - 标准化分区
需求:
/boot 200M~1G
/swap 1G~8G
/ 剩余全部
/boot 200M~1G
/swap >16G
/ 40G
/data(Oracle数据目录) 剩余全部
1、系统配置标准化 - YUM环境
需求:
一键优化脚本
假设没有内网repo,就配置阿里YUM源
#clean OS default repo
mkdir /etc/yum.repos.d/old && mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/
#add repo
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
function_writelog_judgment "[add aliyun mirrors base]"
2、系统配置标准化 - 系统服务
需求:关闭无用服务
一键优化脚本
Centos 7.x
目前无优化方案
Centos 6.x
#set system start service
LANG=en
for 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 vimrc
cat >> /root/.vimrc << EOF
syntax enable
syntax on
set ruler
set number
set cursorline
set cursorcolumn
set hlsearch
set incsearch
set ignorecase
set nocompatible
set wildmenu
set paste
set nowrap
set expandtab
set tabstop=2
set shiftwidth=4
set softtabstop=4
set gcr=a:block-blinkon0
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
highlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
EOF
cp /root/.vimrc /home/oracle/
4、系统配置标准化 - 用户
需求:
一键优化脚本
#add default user
useradd hwb -u 2019
echo 'hwb@)!&' | passwd --stdin hwb && history -c
#set sudo authority
echo "" >> /etc/sudoers
echo "#set sudo authority" >> /etc/sudoers
echo "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_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's%#PermitRootLogin yes%PermitRootLogin no%g' /etc/ssh/sshd_config
sed -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_key
cat /tmp/ansible_key >> /home/hwb/.ssh/authorized_keys
rm -f /tmp/ansible_key
篇幅有限,这块就先介绍到这了,如果大家想做公司标准化这一块,建议还是根据公司实际情况去具体设置,最后再根据需求统一写成一个shell脚本,这样一个标准化的脚本就建立起来了。后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注一下~
留言与评论(共有 0 条评论) |