-
安装常用工具:
yum -y install bash-completion bash-completion-extras vim net-tools.x86_64 yum-utils lsof unzip zip
-
关闭selinux
setenforce 0 vim /etc/selinux/config SELINUX=disabled getenforce
-
优化文件打开数
vim /etc/security/limits.conf root soft nofile 65536 root hard nofile 65536 root soft stack 32768 root hard stack 32768 * soft nofile 1024000 * hard nofile 1024000 * soft nproc unlimited * hard nproc unlimited * soft core unlimited * hard core unlimited * soft memlock unlimited * hard memlock unlimited
-
优化系统参数
vi /etc/sysctl.conf # see details in https://help.aliyun.com/knowledge_detail/39428.html # see details in https://help.aliyun.com/knowledge_detail/41334.html #仅在内存不足的情况下--当剩余空闲内存低于vm.min_free_kbytes limit时,使用交换空间。 vm.swappiness = 0 #单个进程可分配的最大文件数 fs.nr_open=2097152 #系统最大文件句柄数 #计算grep -r MemTotal /proc/meminfo | awk '{printf("%d",$2/10)}' fs.file-max=1048576 #backlog 设置 net.core.somaxconn=32768 net.ipv4.tcp_max_syn_backlog=16384 net.core.netdev_max_backlog=16384 #TCP Socket 读写 Buffer 设置 net.core.rmem_default=262144 net.core.wmem_default=262144 net.core.rmem_max=16777216 net.core.wmem_max=16777216 net.core.optmem_max=16777216 net.ipv4.neigh.default.gc_stale_time=120 #TIME-WAIT Socket 最大数量、回收与重用设置 net.ipv4.tcp_max_tw_buckets=1048576 net.ipv4.tcp_tw_reuse=1 # FIN-WAIT-2 Socket 超时设置 #net.ipv4.tcp_fin_timeout=30 #解决大量state=TIME_WAIT问题 net.ipv4.tcp_tw_recycle=0 net.ipv4.tcp_timestamps=0 net.ipv4.conf.all.accept_redirects=0 #net.ipv4.ip_local_port_range = 1024 65000 #TCP 连接追踪设置 net.nf_conntrack_max=1000000 net.netfilter.nf_conntrack_max=1000000 net.netfilter.nf_conntrack_tcp_timeout_time_wait=30 #开启动网络转发功能 net.ipv4.ip_forward = 1 #支持网桥过滤器 net.bridge.bridge-nf-call-iptables = 1 net.bridge.bridge-nf-call-ip6tables = 1 sysctl -p
-
卸载安装自带jdk,安装jdk
tar并mv到/usr/local/下 vim /etc/profile export JAVA_HOME=/opt/jdk1.8.0_201 export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/ export PATH=$PATH:$JAVA_HOME/bin source /etc/profile 检测:java -version
-
添加防火墙快捷脚本
chmod +x /sh/FirewallRule.sh 放开ssh:12300端口 执行:/sh/FirewallRule.sh
-
修改链接不需要核实dns、ssh连接端口
vim /etc/ssh/sshd_config 把UseDNS yes,改为UseDNS no Port 12300 systemctl restart sshd
-
修改服务器名
hostnamectl set-hostname appfor32
-
加入定时优化内存机制
chmod +x /sh/MemoryCleanup.sh crontab -e -uroot 0 * * * * /sh/MemoryCleanup.sh &
-
加入SSH防御机制
mkdir /sh/SSHdefense chmod +x /sh/SSHdefense/SSHdefense.sh crontab -e -uroot 0 * * * * /sh/SSHdefense/SSHdefense.sh > /dev/null 2>&1 &
-
#关闭root登入,以密钥形式登入
(内网服务器可不执行该操作,会增加服务器管理成本;暴露在外网的服务器需要操作)
#新建公匙及私匙 ssh-keygen -t rsa #一定要给私匙设置密码 #此时在/root/.ssh/目录下生成了2个文件,id_rsa为私钥,id_rsa.pub为公钥。 #私钥自己下载到本地电脑妥善保存。 将公钥导入到authorized_keys cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys #启用私匙登录 vim /etc/ssh/sshd_config #私匙登录 RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys #禁用root账户口令密码登录 PasswordAuthentication no systemctl restart sshd
-
查看当前有多少用户
cat /etc/passwd #无用用户删除 #一般安装好系统的服务器最好不要动,安装系统完成后不要乱添加用户就可以了
重启系统:reboot
-
指定时间
yum -y install chrony systemctl restart chronyd date
喜欢的亲可以关注点赞评论哦!以后每天都会更新的哦!本文为小编原创文章; 文章中用到的文件、安装包等可以加小编联系方式获得;
欢迎来交流小编联系方式VX:CXKLittleBrother 进入运维交流群