CentOS7初始化

#修改主机名
hostnamectl set-hostname test.server.com
#修改主机列表
cat <<EOF >> /etc/hosts
192.168.2.120 test.server.com
EOF
 
#修改IP地址
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
BOOTPROTO=static
IPADDR=192.168.x.x
GATEWAY=192.168.x.x
NETMASK=255.255.255.0
DNS1=192.168.x.x
ONBOOT=yes
EOF
systemctl restart network.service
 
#关闭防火墙
systemctl stop firewalld.service && systemctl disable firewalld.service
 
#关闭SELinux
setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
 
#修改系统日志记录格式
sed -i "s/\$ActionFileDefaultTemplate*/#&/" /etc/rsyslog.conf
sed -i '29a\$template CustomFormat,"%$NOW% %TIMESTAMP:8:15% %HOSTNAME% %syslogtag% %msg%\\n"' /etc/rsyslog.conf
sed -i '30a\$ActionFileDefaultTemplate CustomFormat' /etc/rsyslog.conf && systemctl restart rsyslog

#优化ssh
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
systemctl restart sshd

#安装相关应用
yum install -y wget curl bash-completion vim tree lsof gcc gcc-c++ make  man-pages net-tools java-1.8.0-openjdk-devel.x86_64 lrzsz sysstat psmisc
 
#个性化配置
cat <<EOF | tee /etc/profile.d/trent.sh
PS1='\[\e[1;32m\][\u@\h \w]\$ \[\e[0m\]'
HISTSIZE=10000
HISTTIMEFORMAT="%F %T "
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64
export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export PATH=$PATH:\$JAVA_HOME/bin
EOF
source /etc/profile.d/trent.sh
 
#设置yum源
cd /etc/yum.repos.d/
rename repo repo.bak *
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum clean plugins && yum makecache
 
#同步时间
yum -y install ntpdate && timedatectl set-timezone Asia/Shanghai && ntpdate ntp2.aliyun.com && hwclock --systohc
 
#优化网络配置
vi /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1  
#表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;  
net.ipv4.tcp_tw_reuse = 1  
#表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;  
net.ipv4.tcp_tw_recycle = 1  
#表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。  
net.ipv4.tcp_fin_timeout = 30  
#表示如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。  
net.ipv4.tcp_keepalive_time = 1200   
#表示当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时,改为20分钟。  
net.ipv4.ip_local_port_range = 1024    65000   
#表示用于向外连接的端口范围。缺省情况下很小:32768到61000,改为1024到65000。  
net.ipv4.tcp_max_tw_buckets = 5000  
#表示系统同时保持TIME_WAIT套接字的最大数量
 
#配置文件描述符
cat <<EOF >> /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft noproc 65536
* hard noproc 65536
EOF

posted @ 2019-09-21 11:48  BicycleBoy  阅读(260)  评论(0编辑  收藏  举报