1、添加一个用户

[root@oldboy ~]# useradd oldboy
[root@oldboy ~]# id oldboy
uid=500(oldboy) gid=500 (oldboy) groups=500(oldboy)
[root@oldboy ~]# echo 123456lpasswd --stdin oldboy
Changing password for user oldboy.
passwd: all authentication tokens updated successfully.

2、加到sudo管理, oldboy就相当于管理员

[root@oldboy ~]# visudo
[root@oldboy ~]# grep -w oldboy /etc/sudoers
oldboy ALL=(ALL) NOPASSWD: ALL 远程连接直接用oldboy
弃用root登录,改用oidboy用户登录。
[oldboy@oldboy ~]$ whoami
oldboy
[oldboy@oldboy ~]$ sudo su -
[root@oldboy ~]# whoami
root

3、关闭防火墙

centos6
临时关闭: /etc/init.d/iptables stop
永久关闭: chkconfig iptables off
关闭后检查: /etc/init.d/iptables status
chkconfig --list iptables centos7
临时关闭:systemctl stop firewalld.service
永久关闭: systemctl disable firewalld.service
关闭后检查: systemctl is-active firewalld.service

4、优化SSH远程连接

 备份/etc/ssh/ssh_config
cp /etc/ssh/ssh_config{,.bak} vim /etc/ssh/ssh_config
###by xly#2018-11-24##
Port 52113 #设置10000以上的端口
PermitRootLogin no #禁止root远程登录
PermitEmptyPasswords no #禁止空密码登录
UseDNS no #不使用DNS解析
GSSAPIAuthentication no #Xshell连接慢的解决配置
###by xly#2018-11-24## 把监听网段改掉,即0.0.0.0改为内网网段,例如10.0.0.0
grep -i listen /etc/ssh/ssh_config

5、关闭SELinux

①永久生效,需要重启计算机
更改配置文件/etc/selinux/config
vim /etc/selinux/config把SELINUX=enforcing改成SELINUX=disable或者
sed -i 's#SELINUX=enforcing#SELINUX=disable#g' /etc/selinux/config ②临时生效
设置:setenforce 0
查看:getenforce 结果为Permissive

6、设定运行级别为3

设置运行级别:grep 3:initdefault  /etc/inittab
查看运行级别:runlevel

7、 精简开机系统自启动

linux系统要开启的开机自启动服务:sshd、rsyslog、network、crond、sysstat
chkconfig --list|grep "3:on" 首先查看有哪些服务开机自启动
思路:
关掉不需要的
chkconfig --list|grep "3:on"|egrep -v "sshd|rsyslog|network|cron|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash 优化:
chkconfig --list|grep "3:on"|grep -vE "sshd|rsyslog|network|cron|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash 关闭所有,开启需要的
全关:chkconfig --list|grep "3:on"|awk '{print "chkconfig",$1,"off"}'|bash
开需要的:chkconfig --list|egrep "sshd|rsyslog|network|cron|sysstat"|awk '{print "chkconfig",$1,"on"}'|bash

8、修改linux服务器字符集

centos6
修改/etc/sysconfig/i18n
vim /etc/sysconfig/i18n把LANG="zh_CN.UTF-8"放进去
查看结果:cat /etc/sysconfig/i18n
使之生效:source /etc/sysconfig/i18n或者. /etc/sysconfig/i18n centos7
修改 /etc/locale.conf
vim /etc/locale.conf 把 LANG="zh_CN.UTF-8"放进去
查看结果:cat /etc/locale.conf
使之生效:source /etc/locale.conf或者. /etc/locale.conf

9、设置Linux服务器时间同步

①验证时间同步服务器是否可用
/usr/sbin/ntpdate ntp2.aliyun.com ②设置定时任务
echo 'time sync by liyang at 2019-3-30' >>/var/spool/cron/root
echo '*/5 * * * * /usr/sbin/ntpdate ntp2.aliyun.com >/dev/null 2>&1' >>/var/spool/cron/root centos7
/usr/bin/timedatectl
# 安装
yum install chrony
# 启用
systemctl start chronyd
systemctl enable chronyd
# 设置亚洲时区
timedatectl set-timezone Asia/Shanghai
# 启用NTP同步
timedatectl set-ntp yes

10、命令行安全

echo 'export TIMEOUT=300'  >>/etc/profile
echo 'export HISTSIZE=5' >>/etc/profile
echo 'export HISTFILESIZE=5' >>/etc/profile tail -3 /etc/profile
source /etc/profile 使配置文件生效

11、锁定关键系统文件

加锁
chattr +i /etc/passwd /etc/shadow /etc/group /etc/inittab /etc/fstab /etc/sudoers
查看加锁的文件
lsattr 还可以把chattr命令移走:mv /usr/bin/chattr /opt/oldboy
想用的时候移回来:mv /opt/oldboy /usr/bin/chattr

12、清除多余的系统账号

可以选择不优化,加框的是有用的

13、为grup菜单加密码

[root@oldboy ~]# /sbin/grub-md5-crypt
Password:
Retype password:
$1s.Fv.q/$eCasAokskqxvw0ow37hJr1 vi /etc/grub.conf
password --md5 $1s.Fv.q/$eCasAokskqxvw0ow37hJr1
注意:password要加在aplashimage和title之间,否则可能无法生效

14、隐藏版本信息

查看文件信息:cat  /etc/issue
清除文件信息:>/etc/issue.net >/etc/issue

15、禁止 Linux系统被ping

[rootooldboy ~]# echo "net.ipv4.icmp_echo_ignore_all=1"  >> /etc/sysctl.conf
[rootooldboy ~]#sysctl -p 自己也没办法调试了,Iptables指定内网可以Ping,外网不能ping.

16、调整linux系统文件描述符数量

①文件永久生效
echo ‘* - nofile 65535’ >>/etc/security/limits.conf
tail -1 /etc/security/limits.conf ②临时生效
ulimit -SHn 65535 可以追加到/etc/rc.local每次开机自启动
echo >>/etc/rc.local<<EOF
#-S user the 'soft' resource limit
#-H user the 'hard' resource limit
#-n the maximum number of open file derscriptors
ulimit -SHn 65535
#-s the maximum stack size
ulimit -s 65535
EOF

17、linux服务器内核参数优化

vim /etc/sysctl.conf添加如下内容:
net.ipv4.tcp_fin_timeout = 2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.ip_local_port_range = 4000 65000
net.ipv4.tcp_max_syn backlog = 16384
net.ipv4.tcp_ max_ tw_buckets = 36000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 16384
net.core.netdev_max_backlog = 16384
net.ipv4.tcp_max_orphans = 16384
#以下参数是对iptables防火墙的优化,防火墙不开会提示,可以忽略不理.
net.nf_conntrack_max = 25000000
net.netfilter.nf_conntrack_max = 259909 I
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tco_timeout_fin_wait = 120
执行svsctl-p生效

18、升级具有典型漏洞的软件版本

首先查看先关软件版本号:
rpm -qa openssl openssh bash
升级已知漏洞的软件版本到最新
yum install openssl openssh bash -y
yum update

19、定时清理邮件服务临时目录垃圾文件

①手动清理的方法如下:
find /var/spool/postfix/maildrop/ -type f|xargs rm -f ②定时清理的方法:做定时任务
写个脚本:
echo "find /var/spool/postfix/maildrop/ -type f|xargs rm -f" >/server/scripts/del_file.sh
做定时任务
echo "00 00 * * * /bin/sh /server/scripts/del_file.sh >/dev/null 2>&1" >>/var/spoll/cron/root
查看做好的定时任务
corntab -l

20、hosts解析

都是内网IP

21.配置yum仓库

rm -f /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

22.安装基础软件包

yum install net-tools vim tree htop iftop \
iotop lrzsz sl wget unzip telnet nmap nc psmisc \
dos2unix bash-completion bash-completion-extra sysstat \
rsync nfs-utils httpd-tools -y

1、linux基础优化的更多相关文章

  1. Linux基础优化和安全重点小结

    Linux基础优化和安全重点小结 1.不用root管理,以普通用户的名义通过sudo管理授权(/etc/sudoers)        2.更改默认的ssh服务端口,禁止root用户远程连接,甚至监听 ...

  2. Linux基础优化(二)

    Linux基础优化(二) 一操作系统字符优化 避免出现中文乱码,UTF-8支持中文GBK-Xx支持中文 (一)查看默认编码 [root@centos7 ~]# echo $LANG en_US.UTF ...

  3. Linux 基础优化

    1.操作的最小化原则 1)安装系统最小化 一般情况下安装OS时,软件安装包组(Package Group)的选择: base--------------------------基本环境 editors ...

  4. Linux基础优化与安全归纳总结

    一名运维工程师在运维岗位上时间久了,就会发现Linux优化的重要性,同时会给运维工作带来很多的便利性.本人逐渐认识到了这一点,所以特意在工作闲暇之余,通过阅读Linux相关书籍及向同事.同行高手咨询, ...

  5. 18.linux基础优化

    1.linux系统的基础优化 (1)关闭selinux sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config 临时关闭 ...

  6. linux运维、架构之路-linux基础优化

    1.查看linux版本 cat /etc/redhat-release #CentOS release 6.9 (Final) ————>查看版本号 uname -m #x86_64 ————& ...

  7. linux基础优化

    [root@moban oldboy]# for oldboy in `chkconfig --list |grep "3:on" |awk '{print $1}' |grep ...

  8. Centos6.5 64linux系统基础优化(二)

    1  操作的最小化原则 1)安装系统最小化 2)开启程序服务最小化原则 3)操作最小化原则 4)登陆最小化原则;平时没有需求不用root登陆,要用普通登陆. 2  更改ssh服务默认端口及常规配置 # ...

  9. Linux实战教学笔记06:Linux系统基础优化

    第六节 Linux系统基础优化 标签(空格分隔):Linux实战教学笔记-陈思齐 第1章 基础环境 第2章 使用网易163镜像做yum源 默认国外的yum源速度很慢,所以换成国内的. 第一步:先备份 ...

随机推荐

  1. centos6密钥验证

    密钥验证: 公钥(服务器上)私钥(客户端)在远程登录软件上可生成SSH密钥对.在服务器上建目录.SSH 再在其中建文件authorized_keys,复制公钥到服务器上此文件中. (1)selinux ...

  2. 八十二:memcached之python操作memcached

    安装:pip install python-memcached 创建链接:mc = memcache.Client(['127.0.0.1:11211'], debug=True) 插入数据:mc.s ...

  3. 日期格式存入字符类型之后,再转回datetime类型报错

    背景 最近我们迁移了一批服务器,因我们在azure portal 上新开的VM暂时默认只有英文系统,所以我们在开设好的数据库服务器的时候,都会重置数据库字符排序成中文,避免出现中文乱码问题,重置参考路 ...

  4. 转-Uptime与数据中心等级认证

    1 数据中心等级认证 随着数据中心的蓬勃发展,越来越多的标准被制定出具.其中,Uptime Tier认证在业内是认同度最高的标准.以前,Uptime在中国的宣传很少,很多人对Uptime及其认证体系不 ...

  5. Mac下的Pycharm教程

    除非你是用记事本写代码,或者用vim写代码的大牛,那么推荐使用PyCharm编写Python代码. PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效 ...

  6. Bzoj2873 光之大陆

    https://blog.csdn.net/qq_39791208/article/details/79079117 有空来研究

  7. mint ui解决Navbar和Infinite scroll共存时的bug

    Navbar和Infinite scroll共同使用时会出现无限加载的问题,滑动也会出现乱加载. 只需要判断一下就可以了,代码: html: <mt-navbar v-model="s ...

  8. ajax提交表单包含文件

    需要用到  FormData. html: <form id="formPost"> name: <input name="name" /&g ...

  9. AKKA文档2.2(java)——术语,概念

    原文:http://doc.akka.io/docs/akka/2.3.6/general/terminology.html 译者:吴京润 本章我们试图建立一个通用的术语列表,用来定义有关并发和分布式 ...

  10. 第五周课程总结&试验报告三

    第五周课程总结 一.第五周课程总结 1.this关键字 this可用于任何实例方法内指向当前对象,也可指向对其调用当前方法的对象,或者在需要当前类型对象引用时使用.当一个类的属性(成员变量)名与访问该 ...