Linux系统优化
来源:互联网 发布:数据建模经典教程 pdf 编辑:程序博客网 时间:2024/06/04 20:01
⑴登录系统:不使用root登录,通过sudo授权管理,使用普通用户登录。
useradd adminecho 123456|passwd --stdin admin\cp /etc/sudoers /etc/sudoers.oriecho "oldboy ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoerstail -1 /etc/sudoersvisudo -c
⑵禁止SSH远程:更改默认的远程连接SSH服务及禁止root远程连接。
vi /etc/ssh/sshd_config...Port 8284 #以前这个前面是有 # 号的,而且默认是 22 ,修改一下就ok了#重启 service sshd restart#检测netstat -an #看看端口号是否改成功
⑶时间同步:定时自动更新服务器时间。
echo '#time sync by lidao at 2017-03-08' >>/var/spool/cron/rootecho '*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1' >>/var/spool/cron/rootcrontab -l
⑷配置yum更新源,从国内更新下载安装rpm包。**
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup &&\wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repomv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backupmv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backupwget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
⑸关闭selinux及iptables(iptables工作场景如有wan ip,一般要打开,高并发除外)
#关闭selinuxsed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/configgrep SELINUX=disabled /etc/selinux/config setenforce 0getenforce#关闭iptables/etc/init.d/iptables stop/etc/init.d/iptables stopchkconfig iptables off
⑹调整文件描述符数量,进程及文件的打开都会消耗文件描述符。
echo '* - nofile 65535 ' >>/etc/security/limits.conf tail -1 /etc/security/limits.conf
⑺定时自动清理/var/spool/clientmquene/目录垃圾文件,防止节点被占满(c6.4默认没有sendmail,因此可以不配。)
⑻精简开机启动服务(crond、sshd、network、rsyslog)
export LANG=enchkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash
⑼Linux内核参数优化/etc/sysctl.conf,执行sysct -p生效。更改字符集,支持中文,但是还是建议使用英文,防止乱码问题出现
----------#内核参数优化cat >>/etc/sysctl.conf<<EOFnet.ipv4.tcp_fin_timeout = 2net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_syncookies = 1net.ipv4.tcp_keepalive_time = 600net.ipv4.ip_local_port_range = 4000 65000net.ipv4.tcp_max_syn_backlog = 16384net.ipv4.tcp_max_tw_buckets = 36000net.ipv4.route.gc_timeout = 100net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.core.somaxconn = 16384net.core.netdev_max_backlog = 16384net.ipv4.tcp_max_orphans = 16384#以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理。net.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_max = 25000000net.netfilter.nf_conntrack_tcp_timeout_established = 180net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120EOFsysctl -p----------#字符集cp /etc/sysconfig/i18n /etc/sysconfig/i18n.oriecho 'LANG="en_US.UTF-8"' >/etc/sysconfig/i18n source /etc/sysconfig/i18necho $LANG
(10)锁定关键系统文件(chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/inittab 处理以上内容后,把chatter改名,就更安全了。)
(11)清空/etc/issue,去除系统及内核版本登陆前的屏幕显示。
(12)命令行高亮显示
cat >>/etc/profile<<`EOF`PS1='\[\e[32;1m\][\u@\h \W]\$\[\e[0m\]'`EOF`source /etc/profile
(12)命令行详细显示(时间 用户等格式)
在/etc/profile的最后添加如下部分:
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` export HISTTIMEFORMAT="[%F %T][`whoami`][${USER_IP}] "
重载:source /etc/profile
阅读全文
0 0
- Linux系统性能优化
- 优化Linux系统性能
- Linux通用系统优化
- Linux系统优化
- Linux系统优化
- Linux系统优化思路
- linux 系统优化
- linux系统优化
- linux系统优化
- Linux通用系统优化
- 如何优化linux系统?
- linux 系统优化参考
- linux 系统硬件优化
- Linux系统优化
- Linux系统优化
- Linux 系统参数优化
- Linux 6.5系统优化
- Linux系统优化
- 手动调试wifi方法总结
- malloc calloc free
- jQuery与Zepto的异同
- 关于知识图谱的一些见解
- Spring+SpringMVC+MyBatis
- Linux系统优化
- spring cloud config client 报错
- Make工程管理器简介
- Array in R
- 汉字编码
- CCF Markdown(Java)
- 文章标题
- 4. Median of Two Sorted Arrays
- 第十九课(二) 使用存储过程