{"id":1006,"date":"2009-11-29T19:28:00","date_gmt":"2009-11-29T11:28:00","guid":{"rendered":"\/?p=1006"},"modified":"2009-11-29T19:28:00","modified_gmt":"2009-11-29T19:28:00","slug":"1006","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/linux\/1006.html","title":{"rendered":"CentOS+Nginx+PHP+Mysql+\u5b89\u5168\u6307\u5357\u5168\u73af\u5883\u642d\u5efa\u7b14\u8bb0\uff08\u4e8c\uff09"},"content":{"rendered":"

– \u670d\u52a1\u5668\u7684\u5b89\u5168\u8bbe\u7f6e\u53ca\u5176\u4ed6 <\/strong><\/p>\n

\u4e3b\u8981\u5185\u5bb9\uff1a
[\u8bbe\u7f6eNgnix\u53ef\u63d0\u4f9bAVI\u3001MP3\u7b49\u7684\u4e0b\u8f7d]
[\u8bbe\u7f6e\u7f51\u7ad9\u5e76\u53d1\u6570\u9650\u5236]
[\u8bbe\u7f6enginx\u7a0b\u5e8f\u9650\u5236\u76841M\u4e0a\u4f20\u95ee\u9898]
[\u4f18\u5316PHP]
[\u4f18\u5316mysql]
[mysql\u7684\u5b89\u5168\u8bbe\u7f6e]
[\u7cfb\u7edf\u6574\u4f53\u5b89\u5168\u8c03\u6574]<\/p>\n

[\u8bbe\u7f6eNgnix\u53ef\u63d0\u4f9bAVI\u3001MP3\u7b49\u7684\u4e0b\u8f7d]<\/strong><\/p>\n

# vi \/usr\/local\/webserver\/nginx\/conf\/mime.types
\u2191 \u7f16\u8f91mime.types\u6587\u4ef6
\u5c06\u9700\u8981\u63d0\u4f9b\u4e0b\u8f7d\u7684\u683c\u5f0f\u524d\u7684\u6587\u4ef6\u7c7b\u578b\u4fee\u6539\u4e3a"application\/octet-stream"
# vi \/usr\/local\/webserver\/nginx\/conf\/mime.types.default
\u2191 \u7f16\u8f91mime.types.default\u6587\u4ef6
\u5c06\u9700\u8981\u63d0\u4f9b\u4e0b\u8f7d\u7684\u683c\u5f0f\u524d\u7684\u6587\u4ef6\u7c7b\u578b\u4fee\u6539\u4e3a"application\/octet-stream"<\/p>\n

[\u8bbe\u7f6e\u7f51\u7ad9\u5e76\u53d1\u6570\u9650\u5236]
<\/strong>\u5df2\u5728\u914d\u7f6enginx.conf\u6587\u4ef6\u65f6\u52a0\u5165\u5e76\u53d1\u6570\u9650\u5236\uff0c\u5177\u4f53\u53c2\u89c1\u5b98\u65b9\u7ef4\u57fa\u767e\u79d1(http:\/\/wiki.codemongers.com\/NginxChsHttpLimit_zoneModule)"httplimit_zonemodule<\/a> "\u90e8\u5206<\/p>\n

[\u8bbe\u7f6enginx\u7a0b\u5e8f\u9650\u5236\u76841M\u4e0a\u4f20\u95ee\u9898]
<\/strong>\u5df2\u5728\u914d\u7f6enginx.conf\u6587\u4ef6\u65f6\u53d6\u6d881M\u4e0a\u4f20\u9650\u5236\uff0c\u5177\u4f53\u53c2\u89c1nginx.conf\u6587\u4ef6\u5185\u6ce8\u91ca<\/p>\n

[\u4f18\u5316PHP]<\/strong>
\u5177\u4f53\u53c2\u89c1(
http:\/\/www.cnprint.org\/bbs\/blogs\/1\/blog312.html)"php<\/a> \u4f18\u5316\u8bbe\u7f6e"\u90e8\u5206
\u6b64\u5904\u4ec5\u8bbe\u7f6e\u90e8\u5206\u5fc5\u8981\u5185\u5bb9<\/p>\n

# vi \/usr\/local\/webserver\/php\/etc\/php.ini
\u2191 \u7f16\u8f91php.ini\u6587\u4ef6<\/p>\n

1.\u5c06"disable_functions ="
\u4fee\u6539\u4e3a "disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status"
\u2191**\u8fd9\u6761\u5efa\u8bae\u5728\u7f51\u7ad9\u5efa\u6210\u4e4b\u540e\u4fee\u6539**\u8be5\u9009\u9879\u53ef\u4ee5\u8bbe\u7f6e\u54ea\u4e9bPHP\u51fd\u6570\u662f\u7981\u6b62\u4f7f\u7528\u7684\uff0cPHP\u4e2d\u6709\u4e00\u4e9b\u51fd\u6570\u7684\u98ce\u9669\u6027\u8fd8\u662f\u76f8\u5f53\u5927\u7684\uff0c\u53ef\u4ee5\u76f4\u63a5\u6267\u884c\u4e00\u4e9b\u7cfb\u7edf\u7ea7\u811a\u672c\u547d\u4ee4\uff0c\u5982\u679c\u5141\u8bb8\u8fd9\u4e9b\u51fd\u6570\u6267\u884c\uff0c\u5f53PHP\u7a0b\u5e8f\u51fa\u73b0\u6f0f\u6d1e\u65f6\uff0c\u635f\u5931\u662f\u975e\u5e38\u4e25\u91cd\u7684\uff01
\u9700\u6ce8\u610f\uff1a\u5982\u679c\u60a8\u7684\u670d\u52a1\u5668\u4e2d\u542b\u6709\u4e00\u4e9b\u7cfb\u7edf\u72b6\u6001\u68c0\u6d4b\u7684PHP\u7a0b\u5e8f\uff0c\u5219\u4e0d\u8981\u7981\u7528shell_exec,proc_open,proc_get_status\u7b49\u51fd\u6570\u3002<\/p>\n

2.\u5c06"upload_max_filesize = 2M"
\u4fee\u6539\u4e3a "upload_max_filesize = 50M"
\u2191\u8be5\u9009\u9879\u8bbe\u5b9aPHP\u6240\u80fd\u5141\u8bb8\u6700\u5927\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\uff0c\u9ed8\u8ba4\u4e3a2MB\u3002\u6839\u636e\u5b9e\u9645\u5e94\u7528\u9700\u6c42\uff0c\u53ef\u4ee5\u9002\u5f53\u589e\u5927\u8be5\u8bbe\u7f6e\u3002<\/p>\n

[\u4f18\u5316mysql]<\/strong>
\u5177\u4f53\u53c2\u89c1(
http:\/\/www.cnprint.org\/bbs\/blogs\/1\/blog312.html)"mysql<\/a> \u4f18\u5316\u53ca\u5b89\u5168\u8bbe\u7f6e"\u90e8\u5206
\u6b64\u5904\u4ec5\u8bbe\u7f6e\u90e8\u5206\u5fc5\u8981\u5185\u5bb9<\/p>\n

# vi \/usr\/local\/webserver\/mysql\/my.cnf \u2191 \u7f16\u8f91my.cnf\u6587\u4ef6<\/p>\n

1.\u5c06"table_cache = 64"
\u4fee\u6539\u4e3a "table_cache = 512"
\u2191\u6307\u5b9a\u8868\u9ad8\u901f\u7f13\u5b58\u7684\u5927\u5c0f\u3002\u6bcf\u5f53MySQL\u8bbf\u95ee\u4e00\u4e2a\u8868\u65f6\uff0c\u5982\u679c\u5728\u8868\u7f13\u51b2\u533a\u4e2d\u8fd8\u6709\u7a7a\u95f4\uff0c\u8be5\u8868\u5c31\u88ab\u6253\u5f00\u5e76\u653e\u5165\u5176\u4e2d\uff0c\u8fd9\u6837\u53ef\u4ee5\u66f4\u5feb\u5730\u8bbf\u95ee\u8868\u5185\u5bb9\u3002\u901a\u8fc7\u68c0\u67e5\u5cf0\u503c\u65f6\u95f4\u7684\u72b6\u6001\u503cOpen_tables\u548cOpened_tables\uff0c\u53ef\u4ee5\u51b3\u5b9a\u662f\u5426\u9700\u8981\u589e\u52a0table_cache\u7684\u503c\u3002\u5982\u679c\u60a8\u53d1\u73b0open_tables\u7b49\u4e8e table_cache\uff0c\u5e76\u4e14opened_tables\u5728\u4e0d\u65ad\u589e\u957f\uff0c\u90a3\u4e48\u60a8\u5c31\u9700\u8981\u589e\u52a0table_cache\u7684\u503c\u4e86\uff08\u4e0a\u8ff0\u72b6\u6001\u503c\u53ef\u4ee5\u4f7f\u7528show status like ‘Open_tables’\u83b7\u5f97\uff09\u3002\u6ce8\u610f\uff0c\u4e0d\u80fd\u76f2\u76ee\u5730\u628atable_cache\u8bbe\u7f6e\u6210\u5f88\u5927\u7684\u503c\u3002\u5982\u679c\u8bbe\u7f6e\u5f97\u592a\u9ad8\uff0c\u53ef\u80fd\u4f1a\u9020\u6210\u6587\u4ef6\u63cf\u8ff0\u7b26\u4e0d\u8db3\uff0c\u4ece\u800c\u9020\u6210\u6027\u80fd\u4e0d\u7a33\u5b9a\u6216\u8005\u8fde\u63a5\u5931\u8d25\u3002<\/p>\n

2.\u5c06"sort_buffer_size = 512k"
\u4fee\u6539\u4e3a "sort_buffer_size = 2M"
\u2191\u6bcf\u4e2a\u7ebf\u7a0b\u6392\u5e8f\u6240\u9700\u7684\u7f13\u51b2<\/p>\n

3.\u5c06"read_buffer_size = 128k"
\u4fee\u6539\u4e3a "read_buffer_size = 2M"
\u2191\u5f53\u4e00\u4e2a\u67e5\u8be2\u4e0d\u65ad\u5730\u626b\u63cf\u67d0\u4e00\u4e2a\u8868\uff0cMySQL\u4f1a\u4e3a\u5b83\u5206\u914d\u4e00\u6bb5\u5185\u5b58\u7f13\u51b2\u533a\u3002read_buffer_size\u53d8\u91cf\u63a7\u5236\u8fd9\u4e00\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u3002\u5982\u679c\u60a8\u8ba4\u4e3a\u8fde\u7eed\u626b\u63cf\u8fdb\u884c\u5f97\u592a\u6162\uff0c\u53ef\u4ee5\u901a\u8fc7\u589e\u52a0\u8be5\u53d8\u91cf\u503c\u4ee5\u53ca\u5185\u5b58\u7f13\u51b2\u533a\u5927\u5c0f\u63d0\u9ad8\u5176\u6027\u80fd\u3002<\/p>\n

4.\u5c06"read_rnd_buffer_size = 512k"
\u4fee\u6539\u4e3a "read_rnd_buffer_size = 4M"
\u2191\u52a0\u901f\u6392\u5e8f\u64cd\u4f5c\u540e\u7684\u8bfb\u6570\u636e\uff0c\u63d0\u9ad8\u8bfb\u5206\u7c7b\u884c\u7684\u901f\u5ea6\u3002\u5982\u679c\u6b63\u5bf9\u8fdc\u8fdc\u5927\u4e8e\u53ef\u7528\u5185\u5b58\u7684\u8868\u6267\u884cGROUP BY\u6216ORDER BY\u64cd\u4f5c\uff0c\u5e94\u589e\u52a0read_rnd_buffer_size\u7684\u503c\u4ee5\u52a0\u901f\u6392\u5e8f\u64cd\u4f5c\u540e\u9762\u7684\u884c\u8bfb\u53d6\u3002\u4ecd\u7136\u4e0d\u660e\u767d\u8fd9\u4e2a\u9009\u9879\u7684\u7528\u5904\u2026<\/p>\n

5.\u5c06"myisam_sort_buffer_size = 8M"
\u4fee\u6539\u4e3a "myisam_sort_buffer_size = 32M"
\u2191\u7528\u4e8eREPAIR TABLE\u3002\u4e0d\u660e\u767d\u8fd9\u4e2a\u9009\u9879\u7684\u7528\u5904\uff0c\u767e\u5ea6\u4e0a\u627e\u5230\u7684\u8bbe\u7f6e\u65b9\u5411\u4e5f\u662f\u4e94\u82b1\u516b\u95e8\uff0c\u6709128M\u300164M\u300132M\u7b49\uff0c\u6298\u4e2d\u9009\u4e00\u4e2a\u3002<\/p>\n

[mysql\u7684\u5b89\u5168\u8bbe\u7f6e]
<\/strong>\u5177\u4f53\u53c2\u89c1(
http:\/\/www.cnprint.org\/bbs\/blogs\/1\/blog312.html)"Mysql<\/a> \u7684\u5b89\u5168\u8bbe\u7f6e"\u90e8\u5206
\u6b64\u5904\u4ec5\u8bbe\u7f6e\u90e8\u5206\u5fc5\u8981\u5185\u5bb9<\/p>\n

**iptables\u4e2d\u8bbe\u7f6e**\u5173\u95ed\u8fdc\u7a0b\u8fde\u63a5\uff0c\u53733306\u7aef\u53e3\u3002\u8fd9\u662fMySQL\u7684\u9ed8\u8ba4\u76d1\u542c\u7aef\u53e3\u3002\u7531\u4e8e\u6b64\u5904MySQL\u53ea\u670d\u52a1\u4e8e\u672c\u5730\u811a\u672c\uff0c\u6240\u4ee5\u4e0d\u9700\u8981\u8fdc\u7a0b\u8fde\u63a5\u3002\u5c3d\u7ba1MySQL\u5185\u5efa\u7684\u5b89\u5168\u673a\u5236\u5f88\u4e25\u683c\uff0c\u4f46\u76d1\u542c\u4e00\u4e2aTCP\u7aef\u53e3\u4ecd\u7136\u662f\u5371\u9669\u7684\u884c\u4e3a\uff0c\u56e0\u4e3a\u5982\u679cMySQL\u7a0b\u5e8f\u672c\u8eab\u6709\u95ee\u9898\uff0c\u90a3\u4e48\u672a\u6388\u6743\u7684\u8bbf\u95ee\u5b8c\u5168\u53ef\u4ee5\u7ed5\u8fc7 MySQL\u7684\u5185\u5efa\u5b89\u5168\u673a\u5236\u3002\uff08\u60a8\u5fc5\u987b\u786e\u5b9a\uff0c\u60a8\u662f\u5426\u771f\u7684\u4e0d\u9700\u8981\u8fdc\u7a0b\u8fde\u63a5mysql\uff09<\/p>\n

[\u7cfb\u7edf\u6574\u4f53\u5b89\u5168\u8c03\u6574]<\/strong><\/p>\n

1\u3001**\u6700\u540e\u8bbe\u7f6e**RHEL\u6216Red Had Enterprise Linux 5.X \u7684\u7528\u6237\u8981\u9996\u5148\u8981\u6253\u5f00SElinux\uff0c\u65b9\u6cd5\u662f\u4fee\u6539\/etc\/selinux\/config\u6587\u4ef6\u4e2d\u7684SELINUX="" \u4e3aenforcing \u3002\u5b83\u53ef\u4ee5\u4fdd\u8bc1\u60a8\u7684\u7cfb\u7edf\u4e0d\u4f1a\u975e\u6b63\u5e38\u7684\u5d29\u6e83\u3002\u6709\u4e9b\u4eba\u8ba4\u4e3a\u5e94\u8be5\u5173\u95ed\uff0c\u6211\u5f3a\u70c8\u4e0d\u63a8\u8350\uff0c\u5f53\u7136\u53ea\u662f\u5c06RHEL\u7528\u6765\u73a9\u73a9\uff0c\u4e0d\u662f\u7528\u4e8e\u5b9e\u9645\u670d\u52a1\u5668\u5219\u65e0\u6240\u8c13\u4e86\u3002
2\u3001**\u6700\u540e\u8bbe\u7f6e**\u542f\u7528iptables \u9632\u706b\u5899\uff0c\u5bf9\u589e\u52a0\u7cfb\u7edf\u5b89\u5168\u6709\u8bb8\u591a\u597d\u5904\u3002\u8bbe\u7f6e\u597d\u9632\u706b\u5899\u7684\u89c4\u5219\u3002
iptables\u8981\u6c42\uff1a
* \u5c4f\u853d\u6240\u6709\u7aef\u53e3
* \u628aSSH\u7684\u7f3a\u7701\u7aef\u53e3\u8bbe\u7f6e\u4e3a56565
* \u628a56565\u300180\u30013306\u7aef\u53e3\u6253\u5f00
* \u628a3306\u7aef\u53e3\u8bbe\u7f6e\u4e3a\u53ea\u5141\u8bb8\u672c\u673a\u8bbf\u95ee<\/p>\n

Iptables\u89c4\u5219\uff1a
# vi \/usr\/local\/webserver\/fw.sh
\u5c06\u4ee5\u4e0b\u811a\u672c\u547d\u4ee4\u7c98\u8d34\u5230 fw.sh \u6587\u4ef6\u4e2d
#!\/bin\/bash
# Stop iptables service
\/sbin\/service iptables stop
# Inital chains default policy
\/sbin\/iptables -F -t filter
\/sbin\/iptables -P INPUT DROP
\/sbin\/iptables -P OUTPUT ACCEPT
# Enable Native Network Transfer
\/sbin\/iptables -A INPUT -i lo -j ACCEPT
# Accept Established Connections
\/sbin\/iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
# ICMP Control
\/sbin\/iptables -A INPUT -p icmp -m limit –limit 1\/s –limit-burst 10 -j ACCEPT
# WWW Service
\/sbin\/iptables -A INPUT -p tcp –dport 80 -j ACCEPT
# SSH Service
\/sbin\/iptables -A INPUT -p tcp –dport 56565 -j ACCEPT
# Anti DDOS
\/sbin\/iptables -I INPUT -p tcp –syn -m ttl –ttl-eq 117 -j DROP
\/sbin\/iptables -I INPUT -p tcp –syn -m length –length :40 -j DROP
# mysql 3306 Accept
\/sbin\/iptables -A INPUT -p tcp -s 127.0.0.1 –dport 3306 -j ACCEPT
\/sbin\/iptables -A OUTPUT -p tcp -s 127.0.0.1 –dport 3306 -j ACCEPT
# Start iptables service
\/sbin\/service iptables start<\/p>\n

\u4fdd\u5b58\u540e\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4
# chmod 755 \/usr\/local\/webserver\/fw.sh
# echo ‘\/usr\/local\/webserver\/fw.sh’ >> \/etc\/rc.d\/rc.local
# \/usr\/local\/webserver\/fw.sh<\/p>\n

3\u3001\u6267\u884csetup\u5173\u95ed\u90a3\u4e9b\u4e0d\u9700\u8981\u7684\u670d\u52a1,\u5c11\u5f00\u4e00\u4e2a\u670d\u52a1\uff0c\u5c31\u5c11\u4e00\u4e2a\u5371\u9669\uff0c\u5df2\u5728< \u7cfb\u7edf\u5b89\u88c5\u540e\u7684\u521d\u59cb\u73af\u5883\u8bbe\u7f6e >\u4e2d\u8bbe\u7f6e
4\u3001\u7981\u6b62Control-Alt-Delete\u952e\u76d8\u5173\u95ed\u547d\u4ee4
\u5728"\/etc\/inittab"\u6587\u4ef6\u4e2d\u6ce8\u91ca\u6389\u4e0b\u9762\u8fd9\u884c\uff08\u4f7f\u7528#\uff09\uff1a
# vi \/etc\/inittab
\u5c06"ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now" \u4fee\u6539\u4e3a\uff1a "#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now"
\u4e3a\u4e86\u4f7f\u8fd9\u9879\u6539\u52a8\u8d77\u4f5c\u7528\uff0c\u8f93\u5165\u4e0b\u9762\u8fd9\u4e2a\u547d\u4ee4\uff1a
# \/sbin\/init q
5\u3001\u7ed9"\/etc\/rc.d\/init.d"\u4e0bscript\u6587\u4ef6\u8bbe\u7f6e\u6743\u9650
\u7ed9\u6267\u884c\u6216\u5173\u95ed\u542f\u52a8\u65f6\u6267\u884c\u7684\u7a0b\u5e8f\u7684script\u6587\u4ef6\u8bbe\u7f6e\u6743\u9650\u3002
# chmod -R 700 \/etc\/rc.d\/init.d\/*
\u8fd9\u8868\u793a\u53ea\u6709root\u624d\u5141\u8bb8\u8bfb\u3001\u5199\u3001\u6267\u884c\u8be5\u76ee\u5f55\u4e0b\u7684script\u6587\u4ef6\u3002
6\u3001\u4f7f"\/etc\/services"\u6587\u4ef6\u514d\u75ab
\u4f7f"\/etc\/services"\u6587\u4ef6\u514d\u75ab\uff0c\u9632\u6b62\u672a\u7ecf\u8bb8\u53ef\u7684\u5220\u9664\u6216\u6dfb\u52a0\u670d\u52a1\uff1a
#chattr +i \/etc\/services
7.\u963b\u6b62\u60a8\u7684\u7cfb\u7edf\u54cd\u5e94\u4efb\u4f55\u4ece\u5916\u90e8\/\u5185\u90e8\u6765\u7684ping\u8bf7\u6c42\u3002
\u65e2\u7136\u6ca1\u6709\u4eba\u80fdping\u901a\u60a8\u7684\u673a\u5668\u5e76\u6536\u5230\u54cd\u5e94\uff0c\u60a8\u53ef\u4ee5\u5927\u5927\u589e\u5f3a\u60a8\u7684\u7ad9\u70b9\u7684\u5b89\u5168\u6027\u3002\u60a8\u53ef\u4ee5\u52a0\u4e0b\u9762\u7684\u4e00\u884c\u547d\u4ee4\u5230\/etc\/rc.d\/rc.local\uff0c\u4ee5\u4f7f\u6bcf\u6b21\u542f\u52a8\u540e\u81ea\u52a8\u8fd0\u884c\u3002
# vi \/etc\/rc.d\/rc.local
echo 1 > \/proc\/sys\/net\/ipv4\/icmp_echo_ignore_all
8\u3001\u5bf9\u60a8\u7684\u7cfb\u7edf\u4e0a\u6240\u6709\u7684\u7528\u6237\u8bbe\u7f6e\u8d44\u6e90\u9650\u5236\u53ef\u4ee5\u9632\u6b62DoS\u7c7b\u578b\u653b\u51fb\uff08denial of service attacks\uff09
\u5982\u6700\u5927\u8fdb\u7a0b\u6570\uff0c\u5185\u5b58\u6570\u91cf\u7b49\u3002\u4f8b\u5982\uff0c\u5bf9\u6240\u6709\u7528\u6237\u7684\u9650\u5236\u8c61\u4e0b\u9762\u8fd9\u6837\uff1a
# vi \/etc\/security\/limits.conf
\u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6240\u6709\u7528\u6237\u6bcf\u4e2a\u4f1a\u8bdd\u90fd\u9650\u5236\u5728 10 MB\uff0c\u5e76\u5141\u8bb8\u540c\u65f6\u6709\u56db\u4e2a\u767b\u5f55\u3002\u7b2c\u4e09\u884c\u7981\u7528\u4e86\u6bcf\u4e2a\u4eba\u7684\u5185\u6838\u8f6c\u50a8\u3002\u7b2c\u56db\u884c\u9664\u53bb\u4e86\u7528\u6237 bin \u7684\u6240\u6709\u9650\u5236\u3002
* hard rss 10000
* hard maxlogins 4
* hard core 0
bin –
\u6fc0\u6d3b\u8fd9\u4e9b\u9650\u5236
# vi \/etc\/pam.d\/login \u5e95\u90e8\u6dfb\u52a0\u4e00\u884c\uff1a session required \/lib\/security\/pam_limits.so\u3002
9\u3001\u7528chattr\u547d\u4ee4\u7ed9\u4e0b\u9762\u7684\u6587\u4ef6\u52a0\u4e0a\u4e0d\u53ef\u66f4\u6539\u5c5e\u6027\u3002
# chattr +i \/etc\/passwd
# chattr +i \/etc\/shadow
# chattr +i \/etc\/group
# chattr +i \/etc\/gshadow
**mysql\u6570\u636e\u5e93\u5bc6\u7801\u53d8\u66f4\u540e\u518d\u8bbe\u7f6e**\u6ce8\u610f\u6267\u884c\u8fd9\u4e2a\u64cd\u4f5c\u540e\uff0c\u4ee5root\u8eab\u4efd\u90fd\u4e0d\u80fd\u5411\u7cfb\u7edf\u589e\u52a0\u7528\u6237\u6216\u8005\u4fee\u6539\u5bc6\u7801\u4e86\u3002
\u5982\u679c\u6211\u4eec\u8981\u589e\u52a0\u7528\u6237\u6216\u8005\u4fee\u6539\u5bc6\u7801\u7684\u3002\u5e94\u8be5\u5148\u7528chattr -i \/etc\/passwd\u7b49\u547d\u4ee4\u89e3\u9664\u4e0d\u53ef\u5199\u8bbe\u7f6e\uff0c\u518d\u8fdb\u884c\u64cd\u4f5c\u3002
10\u3001\u4fee\u6539sshd\u7684\u7aef\u53e3:
\u4fee\u6539\u9632\u706b\u5899\u914d\u7f6e\uff0c\u5f00\u542f\u65b0\u7684\u8fdc\u7a0b\u7aef\u53e3(56565)
# vi \/etc\/sysconfig\/iptables<\/p>\n

\u4fee\u6539\/etc\/ssh\/sshd_config:
# vi \/etc\/ssh\/sshd_config
\u5c06\u91cc\u9762\u7684 Port \u6539\u4e3a 56565\uff0c(\u5177\u4f53\u7684\u7aef\u53e3\u968f\u610f\uff0c\u4e0d\u80fd\u548c\u5176\u4ed6\u7a0b\u5e8f\u7684\u7aef\u53e3\u51b2\u7a81)\u3002\u5e76\u6ce8\u91ca\u6389\u524d\u9762\u7684#\u53f7<\/p>\n

\u4f7fsshd\u670d\u52a1\u751f\u6548:
# pkill sshd
# service sshd start<\/p>\n

\u4fee\u6539\u9632\u706b\u5899\u914d\u7f6e\uff0c\u5173\u95ed\u65e7\u7684\u8fdc\u7a0b\u7aef\u53e3(22)
# vi \/etc\/sysconfig\/iptables
\u6ce8\u610f:\u4fee\u6539\u4e86\u9632\u706b\u5899\u914d\u7f6e\u6587\u4ef6\u540e\u4e0d\u5f97\u518d\u4f7f\u7528setup\u4fee\u6539\u9632\u706b\u5899\u8bbe\u7f6e\uff0c\u5426\u5219\u73b0\u5728\u7684\u8bbe\u7f6e\u4f1a\u5931\u6548
11\u3001 \u5185\u6838\u53c2\u6570\u8c03\u6574
\u7f16\u8f91sysctl.conf\u6587\u4ef6:
# vi \/etc\/sysctl.conf
\u4fee\u6539\u5982\u4e0b:
net.ipv4.conf.default.accept_source_route=0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_echo_ignore_all=1
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.ip_conntrack_max=65535
net.ipv4.tcp_syn_retries=1
net.ipv4.tcp_synack_retries=1
net.ipv4.route.gc_timeout=100
net.ipv4.tcp_max_syn_backlog=32768
net.ipv4.conf.default.rp_filter=0
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
kernel.shmmax = 134217728
\u67e5\u770b\u72b6\u6001:
# sysctl -p
12\u3001\u7ecf\u5e38\u68c0\u67e5\u7cfb\u7edf\u65e5\u5fd7\u3002\u7cfb\u7edf\u65e5\u5fd7\u4e3b\u8981\u4f4d\u4e8e\/var\/log\/\u76ee\u5f55\u4e0b\u3002\u9632\u60a3\u4e8e\u672a\u7136\u3002<\/p>\n

– \u6570\u636e\u81ea\u52a8\u5907\u4efd<\/strong><\/p>\n

\u4e3b\u8981\u5185\u5bb9\uff1a
[\u5b89\u88c5NCFTP\u8f6f\u4ef6\u4ee5\u652f\u6301\u81ea\u52a8\u4e0a\u4f20\u6570\u636e\u5e93\u5907\u4efd]
[\u6570\u636e\u5e93\u6bcf\u65e5\u5907\u4efd]
[\u6570\u636e\u5e93\u5373\u65f6\u5907\u4efd**\u6309\u9700\u64cd\u4f5c**]
[\u65e5\u5fd7\u5907\u4efd]<\/p>\n

[\u5b89\u88c5NCFTP\u8f6f\u4ef6\u4ee5\u652f\u6301\u81ea\u52a8\u4e0a\u4f20\u6570\u636e\u5e93\u5907\u4efd]<\/strong><\/p>\n

# cd \/software
# wget
ftp:\/\/ftp.ncftp.com\/ncftp\/ncftp-3.2.2-src.tar.gz<\/a>
# tar zxvf ncftp-3.2.2-src.tar.gz
# cd ncftp-3.2.2
# .\/configure –prefix=\/usr\/local\/webserver\/ncftp
# make && make install<\/p>\n

[\u6570\u636e\u5e93\u6bcf\u65e5\u5907\u4efd]<\/strong>
\u6bcf\u59294:00\uff0c\u5c06\u6570\u636e\u5e93\u62f7\u8d1d\u81f3\/backup\/day\u540e\u8fdb\u884c\u538b\u7f29\uff0c\u7136\u540e\u4e0a\u4f20\u81f3FTP\u670d\u52a1\u5668\u4e0a\uff0c\/backup\/day\/\u7559\u6709\u538b\u7f29\u6587\u4ef6\u4e00\u5929\u3002<\/p>\n

# vi \/usr\/local\/webserver\/backupd.sh<\/p>\n

\u2191 \u7f16\u8f91\u811a\u672c\/usr\/local\/webserver\/backupd.sh<\/p>\n

\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

#!\/bin\/bash
rm -rf \/backup\/day\/*
cd \/backup\/day\/
cp -rf \/usr\/local\/webserver\/mysql\/data\/(\u6b64\u5904\u4e3a\u6570\u636e\u5e93\u540d\u79f0)\/ \/backup\/day\/wp_db_$(date +%Y%m%d)
sleep 10
echo "ready to tar in 10s ."
tar zcvf `hostname`_wpdata_of_$(date +%Y%m%d).tar.gz wp_db_$(date +%Y%m%d)
sleep 10
echo "ready to upload in 10s ."
\/usr\/local\/webserver\/ncftp\/bin\/ncftpput -u backupd -p (FTP\u5bc6\u7801) (FTP\u670d\u52a1\u5668\u5730\u5740) \/ \/backup\/day\/`hostname`_wpdata_of_$(date +%Y%m%d).tar.gz
sleep 30
echo "upload done ."
rm -f `hostname`_wpdata_of_$(date +%Y%m%d).tar.gz
sleep 5
rm -rf wp_db_$(date +%Y%m%d)
clear<\/p>\n

\u4fdd\u5b58\uff0c\u5e76\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1\uff1a<\/p>\n

# crontab -e<\/p>\n

\u589e\u52a0\u4e00\u884c\uff1a<\/p>\n

00 4 * * * \/bin\/bash \/usr\/local\/webserver\/backupd.sh<\/p>\n

\u2191 \u6bcf\u5929\u51cc\u66684\u70b9\u5c06\u81ea\u52a8\u5907\u4efd\u6570\u636e\u5e93\u5e76\u4e0a\u4f20\u3002<\/p>\n

[\u6570\u636e\u5e93\u5373\u65f6\u5907\u4efd**\u6309\u9700\u64cd\u4f5c**]
<\/strong>\u6bcf\u96946\u5c0f\u65f6\uff0c\u5c06\u6570\u636e\u5e93\u62f7\u8d1d\u81f3\/backup\/hour\u76ee\u5f55\u8fdb\u884c\u5907\u4efd\uff0c\u7136\u540e\u5c06\u538b\u7f29\u6587\u4ef6\u4e0a\u4f20\u81f3FTP\u670d\u52a1\u5668\u4e0a\uff0c\/backup\/hour\/\u7559\u6709\u538b\u7f29\u6587\u4ef6\u4e00\u5929\u3002<\/p>\n

# vi \/usr\/local\/webserver\/backuph.sh<\/p>\n

\u2191 \u7f16\u8f91\u811a\u672c\/usr\/local\/webserver\/backuph.sh<\/p>\n

\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9:\uff1a<\/p>\n

#!\/bin\/bash
rm -rf \/backup\/hour\/*
cd \/backup\/hour\/
cp -rf \/usr\/local\/webserver\/mysql\/data\/(\u6570\u636e\u5e93\u540d\u79f0)\/ \/backup\/hour\/wp_db_$(date +%Y%m%d%H)
sleep 10
echo "ready to tar in 10s ."
tar zcvf `hostname`_wpdata_of_$(date +%Y%m%d%H).tar.gz wp_db_$(date +%Y%m%d%H)
sleep 10
echo "ready to upload in 10s ."
\/usr\/local\/webserver\/ncftp\/bin\/ncftpput -u backuph -p (FTP\u5bc6\u7801) (FTP\u670d\u52a1\u5668\u5730\u5740) \/ \/backup\/hour\/`hostname`_wpdata_of_$(date +%Y%m%d%H).tar.gz
sleep 30
echo "upload done ."
rm -f `hostname`_wpdata_of_$(date +%Y%m%d%H).tar.gz
sleep 5
rm -rf wp_db_$(date +%Y%m%d%H)
clear<\/p>\n

\u4fdd\u5b58\uff0c\u5e76\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1\uff1a<\/p>\n

# crontab -e<\/p>\n

\u589e\u52a0\u4e00\u884c\uff1a<\/p>\n

0 *\/6 * * * \/bin\/bash \/usr\/local\/webserver\/backuph.sh<\/p>\n

\u2191 \u6bcf6\u5c0f\u65f6\u5c06\u81ea\u52a8\u5907\u4efd\u6570\u636e\u5e93\u5e76\u4e0a\u4f20\u4e00\u6b21\u3002<\/p>\n

[\u65e5\u5fd7\u5907\u4efd]<\/strong>
\u6bcf\u592902:00\uff0c\u5c06\/logs\/\u4e0b\u524d\u4e00\u5929\u7684\u65e5\u5fd7\uff0c\u8fdb\u884c\u538b\u7f29\uff0c\u7136\u540e\u4e0a\u4f20\u81f3FTP\u670d\u52a1\u5668\u3002<\/p>\n

# vi \/usr\/local\/webserver\/logs.sh<\/p>\n

\u2191 \u7f16\u8f91\u811a\u672c\/usr\/local\/webserver\/logs.sh<\/p>\n

\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9:\uff1a<\/p>\n

#!\/bin\/bash
cd \/logs\/
mkdir logs_of_$(date -d "yesterday" +"%Y%m%d")
cp $(date -d "yesterday" +"%Y")\/$(date -d "yesterday" +"%m")\/access_$(date -d "yesterday" +"%Y%m%d").log \/logs\/logs_of_$(date -d "yesterday" +"%Y%m%d")
cp $(date -d "yesterday" +"%Y")\/$(date -d "yesterday" +"%m")\/nginx_error_$(date -d "yesterday" +"%Y%m%d").log \/logs\/logs_of_$(date -d "yesterday" +"%Y%m%d")
sleep 10
echo "ready to tar in 10s ."
tar zcvf `hostname`_logs_of_$(date -d "yesterday" +"%Y%m%d").tar.gz logs_of_$(date -d "yesterday" +"%Y%m%d")
sleep 10
echo "ready to upload in 10s ."
\/usr\/local\/webserver\/ncftp\/bin\/ncftpput -u logs -p (FTP\u5bc6\u7801) (FTP\u670d\u52a1\u5668\u5730\u5740) \/ \/logs\/`hostname`_logs_of_$(date -d "yesterday" +"%Y%m%d").tar.gz
sleep 30
echo "upload done ."
rm -f `hostname`_logs_of_$(date -d "yesterday" +"%Y%m%d").tar.gz
sleep 5
rm -rf logs_of_$(date -d "yesterday" +"%Y%m%d")
clear<\/p>\n

\u4fdd\u5b58\uff0c\u5e76\u8bbe\u7f6e\u8ba1\u5212\u4efb\u52a1:\uff1a<\/p>\n

# crontab -e<\/p>\n

\u589e\u52a0\u4e00\u884c\uff1a<\/p>\n

00 2 * * * \/bin\/bash \/usr\/local\/webserver\/logs.sh<\/p>\n

\u2191 \u6bcf\u5929\u51cc\u66682\u70b9\u5c06\u81ea\u52a8\u5907\u4efd\u65e5\u5fd7\u5e76\u4e0a\u4f20\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

– \u670d\u52a1\u5668\u7684\u5b89\u5168\u8bbe\u7f6e\u53ca\u5176\u4ed6 <\/strong><\/p>\n

\u4e3b\u8981\u5185\u5bb9\uff1a
[\u8bbe\u7f6eNgnix\u53ef\u63d0\u4f9bAVI\u3001MP3\u7b49\u7684\u4e0b\u8f7d]
[\u8bbe\u7f6e\u7f51\u7ad9\u5e76\u53d1\u6570\u9650\u5236]
[\u8bbe\u7f6enginx\u7a0b\u5e8f\u9650\u5236\u76841M\u4e0a\u4f20\u95ee\u9898]
[\u4f18\u5316PHP]
[\u4f18\u5316mysql]
[mysql\u7684\u5b89\u5168\u8bbe\u7f6e]
[\u7cfb\u7edf\u6574\u4f53\u5b89\u5168\u8c03\u6574]<\/p>\n

[\u8bbe\u7f6eNgnix\u53ef\u63d0\u4f9bAVI\u3001MP3\u7b49\u7684\u4e0b\u8f7d]<\/strong><\/p>\n

# vi \/usr\/local\/webserver\/nginx\/conf\/mime.types
\u2191 \u7f16\u8f91mime.types\u6587\u4ef6
\u5c06\u9700\u8981\u63d0\u4f9b\u4e0b\u8f7d\u7684\u683c\u5f0f\u524d\u7684\u6587\u4ef6\u7c7b\u578b\u4fee\u6539\u4e3a"application\/octet-stream"
# vi \/usr\/local\/webserver\/nginx\/co<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1006"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1006"}],"version-history":[{"count":0,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1006\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}