sudo yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake sudo yum -y install wget httpd-tools vim
iptables -L #查看已有规则 iptables -F #清空已有规则 iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT #容许本地回环接口(即运行本机访问本机) iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #容许已创建的或相关连的通行 iptables -A OUTPUT -j ACCEPT #容许全部本机向外的访问 iptables -A INPUT -p tcp --dport 22 -j ACCEPT #容许访问22端口 iptables -A INPUT -p tcp --dport 80 -j ACCEPT #容许访问80端口 iptables -A INPUT -p tcp --dport 21 -j ACCEPT #容许ftp服务的21端口 iptables -A INPUT -p tcp --dport 20 -j ACCEPT #容许fTP服务的20端口 iptables -A INPUT -j reject #禁止其余未容许的规则访问 iptables -A FORWARD -j REJECT #禁止其余未容许的规则访问 iptables -A INPUT -p tcp --dport 80 -m limit --limit 25/minute --limit-burst 100 -j ACCEPT #DoS攻击防范 #基于udp的dns服务开启端口 iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT #流量转发均衡 iptables -A PREROUTING -i eth0 -p tcp --dport 80 -m state --state NEW -m nth --counter 0 --every 3 --packet 0 -j DNAT --to-destination 192.168.1.101:80 iptables -A PREROUTING -i eth0 -p tcp --dport 80 -m state --state NEW -m nth --counter 0 --every 3 --packet 0 -j DNAT --to-destination 192.168.1.102:80 iptables -A PREROUTING -i eth0 -p tcp --dport 80 -m state --state NEW -m nth --counter 0 --every 3 --packet 0 -j DNAT --to-destination 192.168.1.103:80 #将丢弃包状况记入日志 iptables -N LOGGING iptables -A INPUT -j LOGGING iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7 iptables -A LOGGING -j DROP service iptables start #启动 service iptables restart #重启 service iptables save #保存 service iptables stop #中止 service iptables status #查询状态
getenforce #查看SELinux是否禁止,Disable为禁止
关闭SELinux:linux
临时关闭,不用重启机器:nginx
setenforce 0 #设置SELinux成为permissive模式,setenforce 1设置SELinux 成为enforcing模式
修改配置文件并重启机器:c++
sudo vim /etc/selinux/config SELINUX=disabled
sudo vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 sudo yum install nginx
sudo yum install httpd-tools #前面安装则不用再次安装 ab -n 2000 -c 20 http://127.0.0.1