linux:-----------------------------------------
1-关闭selinux。
[root@backup ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
[root@backup ~]# grep SELINUX=disabled /etc/selinux/config
[root@backup ~]# setenforce 0
[root@backup ~]# getenforce
Permissive
2-关闭iptables。(最好关闭2次)
[root@backup ~]# /etc/init.d/iptables stop
[root@backup ~]# /etc/init.d/iptables stop
[root@backup ~]# chkconfig iptables off
3-精简开机自启动服务。
[root@backup ~]# export LANG=en
[root@backup ~]# chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"off"}'|bash
[root@backup ~]# 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
4-通过sudo提权普通用户管理。(暂不)
useradd oldboy
echo 123456|passwd --stdin oldboy
\cp /etc/sudoers /etc/sudoers.ori
echo "oldboy ALL=(ALL) NOPASSWD: ALL " >>/etc/sudoers
tail -1 /etc/sudoers
visudo -c
5-调整中文字符集。(可有可无)
echo $LANG #查看系统字符集是否正确
en_US.UTF-8
export LANG=en_US.utf8 #临时生效,解决中文乱码
echo "LANG=en_US.utf8" >/etc/sysconfig/i18n #永久生效
source /etc/sysconfig/i18n #立即让配置生效
6-时间同步。
[root@backup ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1
7-加大文件描述符大小。
查看文件描述符大小:
[root@backup ~]# ulimit -n
1024
[root@backup ~]# echo '* - nofile 65535' >>/etc/security/limits.conf
[root@backup ~]# tail -1 /etc/security/limits.conf
* - nofile 65535
8-内核优化。
适合apache,nginx等多种web应用,特殊的业务也可能需要略作调整。
vim /etc/sysctl.conf
使配置文件生效:sysctl -p
9-去除系统及内核版本登录前的屏幕显示。
>/etc/redhat-release
>/etc/issue
10-锁定关键文件。
chattr +i /etc/passwd
chattr +i /etc/inittab
chattr +i /etc/group
chattr +i /etc/shadow
chattr +i /etc/gshadow
使用chattr命令后,为了安全我们需要将其改名
/bin/mv /usr/bin/chattr /usr/bin/aaa(任意名称)
11-更新yum源为国内源及安装必要软件。
yum install lrzsz ntpdate sysstat nmap tree dos2unix nc telnet gcc gcc-c++ -y
lrzsz是一个上传下载的软件
sysstat是用来检测系统性能及效率的工具
nginx:-----------------------------------------
隐藏版本号:http标签,server_tokens off;
更改默认用户:http标签,user nginx nginx;
开启高效文件传输模式:sendfile on;
配置gzip压缩:主要作用是提高网页打开速度,节约网站带宽成本,减轻服务器压力
配置expires缓存:主要作用同上
禁止非法域名解析访问公司网站
图片与目录防盗链
防爬虫优化
mysql:-----------------------------------------
1、启动程序设置700,属主和属组为mysql。
2、为MySQL超级用户root设置密码。
3、登录时尽量不要在命令行暴露密码,备份脚本如果有密码,设置700,
属主和属组为mysql或root。
4、删除默认存在的test库。
5、删除无用的用户,只保留:
root 127.0.0.1
root localhost
6、授权用户对应的主机不要用%,权限不要给all,最小化授权,从库只给 select。
7、清理mysql操作日志文件 ~/.mysql_history。
8、禁止设置外网IP。
9、防sql注入:SQL注入就是把SQL命令插入到Web表单,然后提交到所在页面请求查询字符串,从而达到欺骗服务器执行恶意的SQL命令。它是利用已有的应用程序,将SQL语句插入到数据库执行,执行一些并非按照设计者意图的SQL语句。
产生原因:程序没有细致过滤用户输入的数据。
通俗理解,就是本来我只有我能操作数据库,本来只是让你输入内容就走,而你却输入命令,从而在我不知情的情况下操作数据库。
PHP:-----------------------------------------
1、安装缓存加速器xcache。
作用:节省PHP引擎重复编译的时间,降低服务器负载,减少CPU和内存开销,加速性能可以达到2-10倍。
2、php.ini参数调优。
(1)关闭危险函数:
disable_functions = system,passthru,exec,shell_exec,popen,phpinfo
(2)关闭PHP版本信息在http头中的泄漏:expose_php = Off