firewall
2018-02-25
# vim /etc/hosts.allow sshd:192.168.100.0/255.255.255.0 允许局域网内所有机器访问服务器上的sshd进程 sshd:60.28.160.244 允许外网的60.28.160.244访问这个服务器上的sshd进程 sshd:11.8.,12.1.,18.3.:allow 设置网段 # vim /etc/hosts.deny sshd:all #禁止所有
# who 查看当前在线用户 root pts/0 2018-02-25 14:28 (202.104.129.62) root pts/1 2018-02-25 15:20 (202.104.129.62) root pts/3 2018-02-25 16:20 (117.136.39.89) 查看mysql状态 mysql>status; 查看mysql当前在线进程用户 # mysqladmin -h152.101.169.49 -uroot -phkcd1862#* processlist mysql>show processlist; +----------+-----------------+----------------------+-----+---------+------+-----------------------------+ | Id | User | Host | db | Command | Time | State | +----------+-----------------+----------------------+-----+---------+------+-----------------------------+ | 40253385 | root | 202.104.129.62:36240 | why | Sleep | 2006 | | | 40256504 | event_scheduler | localhost | | Daemon | 622 | Waiting for next activation | | 40256704 | root | CentOS6.5:57425 | wcn | Sleep | 11 | | | 40256722 | root | CentOS6.5:57440 | | Query | 0 | init | +----------+-----------------+----------------------+-----+---------+------+-----------------------------+ 查看mysql数据文件所在的目录 mysql>show variables like '%datadir%'; 设置sshd允许登录IP # vim /etc/hosts.allow sshd:202.104.129.62 查看执行计划 mysql> explain select * from students where id in (2,3);
设置mysql日志
开启日志模式 # 1、设置 SET GLOBAL log_output = 'TABLE'; SET GLOBAL general_log = 'ON'; # 2、查询 SELECT * from mysql.general_log ORDER BY event_time DESC ----------------------- mysql有以下几种日志: 错误日志: -log-err 查询日志: -log 慢查询日志: -log-slow-queries 更新日志: -log-update 二进制日志: -log-bin 是否启用了日志 mysql>show variables like 'log_%'; 怎样知道当前的日志 mysql> show master status; 顯示二進制日志數目 mysql> show master logs; 看二进制日志文件用mysqlbinlog shell>mysqlbinlog mail-bin.000001 | tail # vim /etc/my.cnf # 在[mysqld] 中輸入 #log log-error=/usr/local/mysql/log/error.log log=/usr/local/mysql/log/mysql.log long_query_time=2 log-slow-queries= /usr/local/mysql/log/slowquery.log
MySQL profile 分析执行开销
开启 profile: set @@profiling=1; 查看profile是否开启 select @@profiling; 1为开启,0为关闭 开启后只对当前session有效。 show profiles show profile for query n show profile cpu for query 1;#查看cpu消耗 show profile block io for query 1;#查看io消耗 show profile memory for query 1;#查看cpu 也可以一起写 show profile cpu ,block io for query 1
2017-10-23
禁止ip访问
cp /etc/sysconfig/iptables iptables -I INPUT -s 41.208.150.114 -j DROP service iptables save serivce iptables restart
1.打开22端口 iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT 2.保存设置 service iptables save 3.查看设置 iptables -L -n 4.service iptables restart iptables -I INPUT 3 -p tcp --dport 21 -j ACCEPT iptables -L -n --line-number 可以显示规则和相对应的编号 iptables -D INPUT 3 删除第三行 ----------------------------------------------- iptables -A INPUT -p tcp -s 192.168.1.2 -j DROP -A 就是添加新的规则 -p tcp -s 就是来源的意思,ip来源于192.168.1.2, -j 怎么做 我们拒绝它 这里应该是 DROP ------------------------------------------------ http://my.oschina.net/HankCN/blog/117796 iptables 从链、表开始理解 增加的开放3306端口的语句一定要在icmp-host-prohibited之前 iptables -I INPUT -p tcp --dport 3306 -j ACCEPT 可以直接编辑vim /etc/sysconfig/iptables文件 netstat常用参数: -a :all,表示列出所有的连接,服务监听,Socket资料 -t :tcp,列出tcp协议的服务 -u :udp,列出udp协议的服务 -n :port number, 用端口号来显示 -l :listening,列出当前监听服务 -p :program,列出服务程序的PID netstat -lnp 只列出当前的端口及进程 netstat -ano 列表并显示行号 iptables -L -n --line-number 插入一条规则(在第三行前) iptables -I INPUT 3 -p tcp --dport 21 -j ACCEPT 替换一条规则 iptables -R INPUT 1 -s 192.168.0.1 -j DROP 增加INPUT端口 iptables -A INPUT -p tcp --dport 21 -j ACCEPT iptables -A INPUT -p tcp --dport 20 -j ACCEPT 增加OUTPUT端口 iptables -A OUTPUT -p tcp --sport 21 -j ACCEPT iptables -A OUTPUT -p tcp --sport 20 -j ACCEPT 增加连续端口 iptables -A INPUT -p tcp --dport 30001:31000 -j ACCEPT iptables -A OUTPUT -p tcp --sport 30001:31000 -j ACCEPT 关闭端口号 iptables -A INPUT -p tcp --drop 端口号 -j DROP 删除端口设置 iptables -D INPUT 3 删除端口号3 禁用211.101.46.253地址的FTP连接 iptables -t nat -A PREROUTING -p tcp --dport 21 -d 211.101.46.253 -j DROP 删除某规则炼中的所有规则。 范例 iptables -F INPUT 改变端口设置后保存 service iptables save 重新启动防火墙 service iptables restart 查看哪些端口被打开 netstat -anp