centos系统优化

一、基本设置

1、修改服务主机名

hostnamectl set-hostname hs-app3.2

2、设置时区:

timedatectl set-timezone Asia/Shanghai

3、设置时间服务器并更新时钟

3.1 编辑chrony.conf配置

vim /etc/chrony.conf

server ntp.ntsc.ac.cn iburst 设置时间服务器,注释丢其他的

阿里云授时中心NTP服务器:ntp1.aliyun.com

国家授时中心NTP服务器:ntp.ntsc.ac.cn

3.2 设置开机自启和重启服务

systemctl enable chronyd ; systemctl restart chronyd

3.3 强制同步系统时钟

chronyc -a makestep 

3.4 查看时间同步源状态:

chronyc sources -v

3.5校准时间服务器

chronyc tracking

4、设置history记录全部操作记录

将下面这段内容添加到vim /etc/bashrc,并执行bash即可

# format history

# save in ~/.bashrc

USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`

export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  `whoami`@${USER_IP}: "

export HISTFILESIZE=1000000

export PROMPT_COMMAND="history -a; history -r;  $PROMPT_COMMAND"

shopt -s histappend

#bind '"\e[A": history-search-backward'

#bind '"\e[B": history-search-forward'

5、设置linux系统充许的最大tcp连接

ulimit -n 查看连接数,ulimit -n 10240临时修改

这里默认1024,不修改这里web服务器修改再大也没用。修改方法为:
cat > /etc/security/limits.conf <<EOF

* soft noproc 65536

* hard noproc 65536

* soft nofile 65536

* hard nofile 65536

EOF

echo > /etc/security/limits.d/20-nproc.conf

ulimit -n 65536

ulimit -u 65536

6、如果安装系统时为图形界,请改为开机为命令行界面

systemctl set-default multi-user.target

7、升级所有包、软件和系统内核

yum -y update

8、重启系统请使用

shutdown -r now命令

9、禁用ctrl+alt+det重启快捷键

rm -rf /usr/lib/systemd/system/ctrl-alt-del.target

init q

二、常用软件安装

1、安装上传下载命令

yum -y install lrzsz

2、安装htop系统性能查看工具

yum install epel-release -y

yum install htop -y

3、最小化安装的系统,请安补充安装以下命令:

yum -y install bash-completion----增加命令补全功能(重启生效)

yum -y install vim ------安装vim命令

yum -y install wget------安装wget命令

yum -y install lvm2 -----安装逻辑分区命令

yum -y install pciutils -----安装lspci命令

yum -y install unzip ----zip解压工具

yum -y install yum-utils -----安装yum-config-manager命令

yum -y install net-tools ------netstat、ifconfig、route命令安装

yum -y install bind-utils  ------host、dig、nslookup命令安装

yum -y install sysstat  系统资源监控工具包括:iostat、sart等工具

yum -y install rsync  安装系统文件同步命令

yum -y install gcc gcc-c++ 安装cc环境

三、网络设置

1、网络IP配置

nmcli con add type ethernet con-name eno1 ifname eno1  如果网络连接不存,请手动创建网络连接

nmcli conn modify eno1 ipv4.addresses 192.168.1.2/24 ipv4.gateway 192.168.1.1 ipv4.method manual connection.autoconnect yes

2、设定DNS服务为

nmcli connection modify eth0 ipv4.dns 116.228.111.118

nmcli connection modify eth0 +ipv4.dns 180.168.255.18

3、重启网卡

nmcli connection down eth0 && nmcli connection up

4、多网卡时开IP转发功能:

sysctl -w net.ipv4.ip_forward=1 临时生效

echo 'net.ipv4.ip_forward = 1'>>/etc/sysctl.conf

sysctl -p 使配置文件生效

sysctl net.ipv4.ip_forward 查看结果

四、操作系统层优化

1、物理内存优化

1.1设最大限度使用物理内存,然后才是swap空间

# sysctl vm.swappiness=0

# echo 'vm.swappiness=0' >>/etc/sysctl.conf  加入内容: vm.swappiness=0

1.2 充许分配所有的物理内存

#echo 'vm.overcommit_memory=1' >>/etc/sysctl.conf  加入内容: vm.overcommit_memory=1

1.3 忽略ICMP或广播请求

echo net.ipv4.icmp_echo_ignore_all = 1 >>/etc/sysctl.conf  #忽略ICMP及禁ping

echo net.ipv4.icmp_echo_ignore_broadcasts = 1 >>/etc/sysctl.conf #忽略广播请求

net.ipv4.tcp_syncookies = 1 #防范少量SYN攻击

1.4使配置文件生效

# sysctl -p 使配置文件生效

五、服务安全优化

1、ssh配置优化

1.1修改ssh配置

vim /etc/ssh/sshd_config
PermitRootLogin no ----阻止root用户登录;暂时不禁用)
Port 10028     -----统一修改端口暂时不禁用)
GSSAPIAuthentication 和UseDNS设置为no  ----加快ssh连接速度

#Subsystem sftp /usr/libexec/openssh/sftp-server #注释此项关闭sftp工作模式

1.2设置好后,重启sshd服务

systemctl restart sshd

1.3防火墙开放此端口

firewall-cmd --permanent --zone=public --add-port=10028/tcp

1.4 重新加载并显示防墙设定

firewall-cmd --reload && firewall-cmd --list-all

1.5设置ssh超时退出

echo "export TMOUT=600" >>/etc/profile  #设置ssh连接超时10分钟退

source /etc/profile

2、普通帐号创建设置

2.1 创建普通用户并设置密码

useradd hangshu
echo “hangshu-2019” | passwd --stdin hangshu

2.2 设置普通用具有root权限

# chmod 755 /etc/sudoers

# vim /etc/sudoers

在root  ALL=(ALL) ALL下面添加一行,如下:

hangshu    ALL=(ALL)       ALL

# source /etc/sudoers

2.3 设置首次登录需修改密码

chage -d 0 hangshu

2.4 设置30天要求创建新密码

chage -m 30 hangshu

[root@s_3_36 ~]# > /var/log/messages

3、清理服务器日志及命令记录

> /var/log/secure

> /var/log/lastlog

> /var/log/yum.log

> /var/log/wtmp

> /var/log/boot.log

> /var/log/maillog

> /var/log/dmesg

> /var/log/maillog

> /var/log/cron

> /var/log/grubby_prune_debug

> /root/.bash_history

history -c

  • 共享及端口安全

1、FTP要固定chroot目录。只能在当前目录。不随意切换目录

2、Mysql注意修改3306默认端口号。授权的时候不允许使用%号进行授权。

3、Mysql用户及IP授权请严格进行授权,除了DBA。其它开发人员不能知道JDBC文件对应的用户和密码。

4、大数据集群需和应用服务、不相关的中间件分开部署。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码哝小鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值