1、修改yum源
http://mirrors.aliyun.com/
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
安装epel源
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
2、时间同步
[root@localhost ~]# ntpdate ntp1.aliyun.com 17 Jan 23:31:52 ntpdate[6104]: step time server 182.92.12.11 offset 3.869849 sec
添加到定时任务
[root@localhost ~]# crontab -e */5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1 ;/sbin/hwclock -w
3、关闭防火墙
[root@localhost ~]# /etc/init.d/iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost ~]# chkconfig iptables off
4、关闭Selinux
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
修改完需要重启才能生效,可以命令修改
[root@localhost ~]# setenforce 0 [root@localhost ~]# getenforce Permissive
5、精简开机启动
保留5个必须:sshd|rsyslog|network|crond|sysstat
sshd
远程连接Linux服务器时需要用到这个服务器程序,所以必须要开启,否则将无法连接Linux服务器。
rsyslog
是操作系统提供的一种机制,系统的守护程序通常会使用rsyslog将各种信息记录系统日志文件中,Centos6以前服务器的名字为syslog
network
系统启动时,若想激活/关闭各个网络接口,则应(必须)考虑开启。
crond
该服务用于周期性地执行系统及用户配置的任务计划。有要周期性执行的任务,任要开启,此服务几乎是生产场景必须要用的一个软件。
sysstat
sysstat是一个软件包,包含检测系统性能及效率的一组工具,这些工具对于系统性能数据很有帮助,比如CPU使用率,硬盘和网络吞吐数据等,这些数据的分析,有利于判断系统运行是否正常,所以它是提高系统运行效率、安全运行服务器的助手。
[root@localhost ~]# for i in `chkconfig --list|grep 3:on|grep -Ev "sysstat|sshd|rsyslog|crond|network"|awk '{print $1}'`;do chkconfig $i off;done
查看
[root@localhost ~]# chkconfig --list|grep 3:on crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off
6、ssh配置
ssh_config和sshd_config都是ssh服务器的配置文件,二者区别在于,前者是针对客户端的配置文件,后者则是针对服务端的配置文件。
编辑文件前先拷贝
# cp sshd_config sshd_config.bak.20160223
主要修改内容:
"Port"设置sshd监听的端口号。默认为22
13 行:Port 12321
"ListenAddress”设置sshd服务器绑定的IP地址。ip地址为本机网卡需要监听的ip地址。
15 行:ListenAddress 192.168.88.100
设置是否允许root通过ssh登录。这个选项从安全角度来讲应设成"no",默认为开启状态,改为no之后依旧可以用普通用户su – root切换到root用户。
42 行:PermitRootLogin no
如果不想用户密码登录修改此处
66 行:PasswordAuthentication no
关闭 SSH 的 DNS 反解析(ssh访问慢的解决方法)
122 行:UseDNS no
GSSAPIAuthentication参数是用于Kerberos验证的,而对于绝大多数人来说,不可能使用这种验证机制,(ssh访问很慢的解决方法)。
80行: GSSAPIAuthentication no 81 行:#GSSAPIAuthentication yes
修改后重启sshd服务
[root@localhost ~]# /etc/init.d/sshd reload
Reloading sshd: [ OK ]
ssh连接排障
1、测试IP是否通
通
C:\Users\wxianj>ping 192.168.88.8 正在 Ping 192.168.88.8 具有 32 字节的数据: 来自 192.168.88.8 的回复: 字节=32 时间<1ms TTL=64
不通
C:\Users\wxianj>ping 192.168.88.8 正在 Ping 192.168.88.8 具有 32 字节的数据: 来自 192.168.88.1 的回复: 无法访问目标主机。
不正常原因:可能是物理网络问题,服务器IP配置、防火墙问题
2、看服务是否正常(telnet)
telenet安装-->控制面板-->程序和功能-->启动或关闭windows功能-->勾选Telnet客户端
正常
C:\Users\wxianj>telnet 192.168.88.8 22 SSH-2.0-OpenSSH_5.3
不正常
C:\Users\wxianj>telnet 192.168.88.8 22 正在连接192.168.88.8...无法打开到主机的连接。 在端口 22: 连接失败
不正常原因:服务器端防火墙阻挡、服务器端口没开放
检查服务
[root@localhost ~]# netstat -nlpt|grep sshd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6264/sshd tcp 0 0 :::22 :::* LISTEN 6264/sshd
检查服务端防火墙
[root@localhost ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
检查selinux
[root@localhost ~]# getenforce
Permissive