基本架构:
环境定义:(Centos6.4 64位 内核2.6.32-358 APACHE2.4.9 NGINX:1.7.0 PHP:5.5.11)
Nginx Proxy:172.28.95.121
WEB-A1:172.28.95.122 #hostname:LAP(LINUX Apache PHP)
WEB-A2:172.28.95.123 #hostname:LNP(LINUX Nginx PHP)
MySQL:172.28.95.117 #hostname:Mysql(Mysql)
NFS:172.28.95.124 #hostname:PIC-SHARE(主要做图片共享)
Backup:172.28.95.125 #hostname:Backup SourceByrd's Weblog-https://note.t4x.org/project/basic-architecture-diagram/
备份服务器:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
NGINX编译配置: /usr/sbin/useradd ebwpe -s /sbin/nologin –M ./configure --user=ebwpe --group=ebwpe --prefix=/byrd/server/nginx-1.7.0 --with-http_stub_status_module --with-http_ssl_module APACHE编译配置: ./configure --prefix=/byrd/server/httpd-2.4.9 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite [root@lamp httpd]# egrep -v "^.*#|^$" /usr/local/apache/conf/httpd.conf |nl 30 ServerName 127.0.0.1:80 71 AddType application/x-httpd-php .php .phtml 72 AddType application/x-httpd-php-source .phps MYsql编译配置: cmake . -DCMAKE_INSTALL_PREFIX=/byrd/server/mysql-5.6.16 -DMYSQL_DATADIR=/byrd/server/mysql-5.6.16/data -DMYSQL_UNIX_ADDR=/byrd/server/mysql-5.6.16/tmp/mysql.sock -DMYSQL_USER=mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 PHP编译参数:FOR APACHE ./configure --enable-opcache --prefix=/byrd/server/php-5.5.11 --with-apxs2=/usr/local/apache/bin/apxs --with-xmlrpc --with-openssl --with-zlib --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv/ --enable-short-tags --enable-sockets --enable-soap --enable-mbstring --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir PHP编译参数:FOR NGINX ./configure --enable-opcache --prefix=/byrd/server/php-5.5.11 --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=ebwpe --with-fpm-group=ebwpe --enable-ftp 优化APACHE(172.28.95.122) [root@LAP byrd]# mkdir -p /var/site/www /var/site/blog /var/site/bbs #创建网站目录 [root@LAP byrd]# /usr/sbin/useradd ebwpe -s /sbin/nologin –M #建立web用户 [root@LAP byrd]# sed -i 's#User daemon#User ebwpe#g' /usr/local/apache/conf/httpd.conf [root@LAP byrd]# sed -i 's#Group daemon#Group ebwpe#g' /usr/local/apache/conf/httpd.conf [root@LAP byrd]# cd /byrd/tools/httpd-2.4.9/modules/metadata [root@LAP metadata]# /usr/local/apache/bin/apxs -c -i -a mod_expires.c #安装缓存模块 [root@LAP metadata]# cd /byrd/tools/httpd-2.4.9/modules/filters/ [root@LAP filters]# /usr/local/apache/bin/apxs -c -i -a mod_deflate.c #安装压缩模块 ##压缩模块报错解决方法: 办法1.需要在 LoadModule deflate_module modules/mod_deflate.so 的前面加载zlib.so 如32操作系统增加以下内容: LoadFile /usr/lib/libz.so LoadModule deflate_module modules/mod_deflate.so 如64操作系统增加以下内容: LoadFile /usr/lib64/libz.so LoadModule deflate_module modules/mod_deflate.so 办法2:vi /usr/local/apache2/bin/apr-config 修改LDFLAGS=" " 为 LDFLAGS="-lz" 然后再apxs -ica mod_deflate.c ###压缩模块END [root@LAP filters]# cd /byrd/tools/httpd-2.4.9/modules/mappers/ [root@LAP mappers]# /usr/local/apache/bin/apxs -c -i -a mod_rewrite.c #重写模块 [root@LAP byrd]# cd /byrd/tools/ [root@LAP tools]# wget http://cronolog.org/download/cronolog-1.6.2.tar.gz [root@LAP tools]# tar zxf cronolog-1.6.2.tar.gz [root@LAP tools]# cd cronolog-1.6.2 [root@LAP cronolog-1.6.2]# ./configure [root@LAP cronolog-1.6.2]# make && make install [root@LAP blog]# sed -i 's#DirectoryIndex index.html#DirectoryIndex index.html index.php#g' /usr/local/apache/conf/httpd.conf 优化NGINX(172.28.95.122) [root@LNP nginx-1.7.0]# pwd #仅为演示 /byrd/tools/nginx-1.7.0 #程序安装目录 [root@LNP nginx-1.7.0]# ./configure --user=wbwpe --group=ebwpe --prefix=/byrd/server/nginx-1.7.0 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module #原有基础新增加模块 [root@LNP nginx-1.7.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginxbackup #备份 [root@LNP nginx-1.7.0]# \cp ./objs/nginx /usr/local/nginx/sbin/ #新编辑的copy过去 优化PHP:(172.28.95.122) [root@LAP mappers]# echo 'export LC_ALL=C' >>/etc/profile #支持perl [root@LAP mappers]# . /etc/profile [root@LAP mappers]# cd /byrd/tools [root@LAP tools]# wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz [root@LAP tools]# tar zxf xcache-3.1.0.tar.gz [root@LAP tools]# cd xcache-3.1.0 [root@LAP xcache-3.1.0]# /usr/local/php/bin/phpize [root@LAP xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config [root@LAP xcache-3.1.0]# make && make install [root@LAP xcache-3.1.0]# cd .. [root@LAP tools]# wget http://pecl.php.net/get/memcache-3.0.8.tgz [root@LAP tools]# tar zxf memcache-3.0.8.tgz [root@LAP tools]# cd memcache-3.0.8 [root@LAP memcache-3.0.8]# /usr/local/php/bin/phpize [root@LAP memcache-3.0.8]# ./configure --with-php-config=/usr/local/php/bin/php-config [root@LAP memcache-3.0.8]# make && make install [root@LAP memcache-3.0.8]# ll /byrd/server/php-5.5.11/lib/php/extensions/no-debug-zts-20121212/ -rwxr-xr-x. 1 root root 452006 May 19 23:57 memcache.so -rwxr-xr-x. 1 root root 495367 May 19 20:04 opcache.so -rwxr-xr-x. 1 root root 592565 May 19 23:55 xcache.so [root@LAP memcache-3.0.8]# cp /usr/local/php/lib/php.ini /usr/local/php/lib/php.ini.backup [root@LAP memcache-3.0.8]# sed -i 's#; extension_dir = "./"#extension_dir = "/byrd/server/php-5.5.11/lib/php/extensions/no-debug-zts-20121212/"#g' /usr/local/php/lib/php.ini [root@LAP memcache-3.0.8]# echo 'extension = memcache.so' >>/usr/local/php/lib/php.ini [root@LAP memcache-3.0.8]# cat >> /usr/local/php/lib/php.ini <<BYRD ;BY:BYRD zend_extension = opcache.so opcache.memory_consumption = 128 opcache.interned_strings_buffer = 8 opcache.max_accelerated_files = 4000 opcache.revalidate_freq = 60 opcache.fast_shutdown = 1 opcache.enable_cli = 1 ;BY:BYRD BYRD [root@LAP memcache-3.0.8]# cat /byrd/tools/xcache-3.1.0/xcache.ini>>/usr/local/php/lib/php.ini [root@LAP memcache-3.0.8]# /usr/local/php/bin/php -v PHP 5.5.11 (cli) (built: May 19 2014 20:04:31) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with XCache v3.1.0, Copyright (c) 2005-2013, by mOo with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies with XCache Cacher v3.1.0, Copyright (c) 2005-2013, by mOo 数据库配置: [root@Mysql ~]# /usr/local/mysql/bin/mysql -uroot -p'admin' mysql> show databases; mysql> create database www default character set utf8 collate utf8_general_ci; mysql> create database blog; mysql> create database bbs; mysql> create user 'www'@'172.28.95.%' identified by 'admin'; mysql> create user 'bbs'@'172.28.95.%' identified by 'admin'; mysql> create user 'blog'@'172.28.95.%' identified by 'admin'; mysql> grant all on bbs.* to 'bbs'@'172.28.95.%' identified by 'admin'; mysql> grant all on www.* to 'www'@'172.28.95.%' identified by 'admin'; mysql> grant all on blog.* to 'blog'@'172.28.95.%' identified by 'admin'; mysql> flush privileges; mysql> select user,host from mysql.user; +------+-------------+ | root | 127.0.0.1 | | bbs | 172.28.95.% | | blog | 172.28.95.% | | www | 172.28.95.% | 配置:LAP虚拟主机(172.28.95.122) [root@LAP byrd]# egrep -v "#|^$" /usr/local/apache/conf/httpd.conf #过滤空行、注释 [root@LAP byrd]# sed -i 's#\#Include conf/extra/httpd-vhosts.conf#Include conf/extra/httpd-vhosts.conf#g' /usr/local/apache/conf/httpd.conf #开启虚拟主机 [root@LAP ~]# egrep -v "#|^$" /usr/local/apache/conf/extra/httpd-vhosts.conf DocumentRoot "/var/site" <Directory "/var/site/www"> AllowOverride None Options None Require all granted </Directory> <VirtualHost *:80> ServerAdmin admin@t4x.org DocumentRoot "/var/site/www" ServerName note.t4x.org ServerAlias t4x.org ErrorLog "/var/site/logs/note.t4x.org-error_log" CustomLog "|/usr/local/sbin/cronolog /var/site/logs/access_note.t4x.org%Y%m%d.log" combined <ifmodule mod_deflate.c> DeflateCompressionLevel 9 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/plain text/xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/css SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary </ifmodule> <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 120 month" ExpiresByType text/html "access plus 120 month" ExpiresByType text/plain "access plus 240 month" ExpiresByType image/gif "access plus 240 month" ExpiresByType image/x-icon "access plus 240 month" </IfModule> </VirtualHost> <Directory "/var/site/bbs"> AllowOverride None Options None Require all granted </Directory> <VirtualHost *:80> ServerAdmin admin@t4x.org DocumentRoot "/var/site/bbs" ServerName bbs.t4x.org ServerAlias shequ.t4x.org ErrorLog "/var/site/logs/bbs.t4x.org.org-error_log" CustomLog "|/usr/local/sbin/cronolog /var/site/logs/access_bbs_t4x_org%Y%m%d.log" combined <ifmodule mod_deflate.c> DeflateCompressionLevel 9 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/plain text/xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/css SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary </ifmodule> <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 120 month" ExpiresByType text/html "access plus 120 month" ExpiresByType text/plain "access plus 240 month" ExpiresByType image/gif "access plus 240 month" ExpiresByType image/x-icon "access plus 240 month" </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3&%1 </IfModule> </VirtualHost> <Directory "/var/site/blog"> Options FollowSymLinks AllowOverride All Require all granted </Directory> <VirtualHost *:80> ServerAdmin admin@t4x.org DocumentRoot "/var/site/blog" ServerName blog.t4x.org ServerAlias boke.t4x.org ErrorLog "/var/site/logs/blog.t4x.org-error_log" CustomLog "|/usr/local/sbin/cronolog /var/site/logs/access_blog_t4x_org%Y%m%d.log" combined <ifmodule mod_deflate.c> DeflateCompressionLevel 9 SetOutputFilter DEFLATE AddOutputFilterByType DEFLATE text/html text/plain text/xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE text/css SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary </ifmodule> <IfModule mod_expires.c> ExpiresActive On ExpiresDefault "access plus 120 month" ExpiresByType text/html "access plus 120 month" ExpiresByType text/plain "access plus 240 month" ExpiresByType image/gif "access plus 240 month" ExpiresByType image/x-icon "access plus 240 month" </IfModule> </VirtualHost> [root@LAP cronolog-1.6.2]# /usr/local/apache/bin/apachectl -t Syntax OK [root@LAP cronolog-1.6.2]# mkdir /var/site/www /var/site/blog /var/site/bbs /var/site/logs –p [root@LAP cronolog-1.6.2]# /usr/local/apache/bin/apachectl -k graceful [root@LAP cronolog-1.6.2]# cd /var/site/www/ [root@LAP www]# wget http://updatenew.dedecms.com/base-v57/package/DedeCMS-V5.7-UTF8-SP1.tar.gz [root@LAP www]# tar zxf DedeCMS-V5.7-UTF8-SP1.tar.gz [root@LAP www]# mv DedeCMS-V5.7-UTF8-SP1/uploads/* . [root@LAP www]# cd ../bbs/ [root@LAP bbs]# wget http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip [root@LAP bbs]# yum install unzip –y [root@LAP bbs]# unzip Discuz_X3.1_SC_UTF8.zip [root@LAP bbs]# mv upload/* . [root@LAP bbs]# cd ../blog/ [root@LAP blog]# wget http://wordpress.org/latest.tar.gz [root@LAP blog]# tar zxf latest.tar.gz [root@LAP blog]# mv wordpress/* . [root@LAP blog]# chown ebwpe.ebwpe /var/site/www [root@LAP blog]# vim wp-config.php [root@LAP blog]# chown -R ebwpe.ebwpe /var/site/bbs/config [root@LAP blog]# chown -R ebwpe.ebwpe /var/site/bbs/data [root@LAP blog]# chown -R ebwpe.ebwpe /var/site/bbs/uc_* NGINX配置: [root@LNP ~]# mkdir /usr/local/nginx/conf/extra [root@LNP ~]# egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf >/usr/local/nginx/conf/extra/nginx-vhost.conf [root@LNP ~]# egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf >/usr/local/nginx/conf/111 [root@LNP ~]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.backup [root@LNP ~]# mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.backup1 [root@LNP ~]# mv /usr/local/nginx/conf/111 /usr/local/nginx/conf/nginx.conf [root@LNP conf]# cat nginx.conf #默认配置 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; } [root@LNP conf]# cat extra/nginx-vhost.conf #默认配置 server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } ###########################################PHP同上########################################### 唯一不同之处: [root@LAP memcache-3.0.8]# sed -i 's#; extension_dir = "./"#/byrd/server/php-5.5.11/lib/php/extensions/no-debug-non-zts-20121212/"#g' /usr/local/php/lib/php.ini APACHE: /byrd/server/php-5.5.11/lib/php/extensions/no-debug-zts-20121212/ NGINX: /byrd/server/php-5.5.11/lib/php/extensions/no-debug-non-zts-20121212/ [root@LNP conf]# mkdir /var/site/www /var/site/blog /var/site/bbs –p [root@LNP conf]# vim /etc/ssh/sshd_config Port 32987 #PermitRootLogin no PermitEmptyPasswords no UseDNS no #Denyusers root #BY:BYRD ########################切换到LAP服务器copy网站程序到LNP服务器############################### [root@LAP blog]# scp -P32987 -rp . root@172.28.95.123:/var/site/blog/ [root@LAP blog]# cd ../bbs/ [root@LAP bbs]# scp -P32987 -rp . root@172.28.95.123:/var/site/bbs/ [root@LAP bbs]# cd ../www/ [root@LAP www]# scp -P32987 -rp . root@172.28.95.123:/var/site/www/ ##########################################NGINX完全配置########################################## [root@LNP conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; include extra/*.conf; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 9; gzip_types text/plain application/javascript text/css application/xml; } [root@LNP extra]# cat nginx-bbs.conf server { listen 80; server_name bbs.t4x.org; location / { root /var/site/bbs; index index.html index.htm index.php; include /usr/local/nginx/conf/wordpress.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 3650d; } location ~ .*\.(js|css)?$ { expires 30d; } # location ~ ^/(images|js|css|static)/ { # expires 10y; # } } location ~ \.php { root /var/site/bbs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/site/bbs$fastcgi_script_name; include fastcgi.conf; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/site/bbs; } } [root@LNP conf]# cat /usr/local/nginx/conf/wordpress.conf location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } [root@LNP conf]# cat /usr/local/nginx/conf/discuzx.conf rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last; rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last; rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last; rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last; if (!-e $request_filename) { return 404; } ###########################################PHP同上########################################### 唯一不同之处: [root@LNP extra]# sed -i 's#; extension_dir = "./"#/byrd/server/php-5.5.11/lib/php/extensions/no-debug-non-zts-20121212/"#g' /usr/local/php/lib/php.ini APACHE: /byrd/server/php-5.5.11/lib/php/extensions/no-debug-zts-20121212/ NGINX: /byrd/server/php-5.5.11/lib/php/extensions/no-debug-non-zts-20121212/ [root@LNP extra]# /usr/local/php/bin/php -v PHP 5.5.11 (cli) (built: May 20 2014 11:30:24) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with XCache v3.1.0, Copyright (c) 2005-2013, by mOo with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies with XCache Cacher v3.1.0, Copyright (c) 2005-2013, by mOo 备注:记得修改nginx网站目录权限,权限参考apache设置! 负载服务器配置: [root@Load-Server ~]# cat /usr/local/nginx/conf/nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream note.t4x.org { server 172.28.95.122:80; server 172.28.95.123:80; } upstream bbs.t4x.org { server 172.28.95.122:80; server 172.28.95.123:80; } upstream blog.t4x.org { server 172.28.95.122:80; server 172.28.95.123:80; } server{ listen 80; server_name note.t4x.org; location / { proxy_pass http://note.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server{ listen 80; server_name bbs.t4x.org; location / { proxy_pass http://bbs.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server{ listen 80; server_name blog.t4x.org; location / { proxy_pass http://blog.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } 负载服务器配置修正版本: user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; tcp_nopush on; keepalive_timeout 0; tcp_nodelay on; sendfile on; # keepalive_timeout 65; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; ##cache## proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /tmp/temp_dir; proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g; ##end## gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css application/xml; gzip_disable "MSIE [1-6]\."; log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' ; access_log /var/log/nginx/access.log main; upstream note.t4x.org { server 1.1.1.101:80; server 1.1.1.102:80; } server{ listen 80; server_name note.t4x.org; location / { proxy_cache cache_one; proxy_cache_valid 200 304 3d; proxy_cache_key $host$uri$is_args$args; proxy_redirect off; proxy_pass http://note.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; expires 10d; } # location ~ /purge(/.*) { #--add-module=../ngx_cache_purge-2.3 # allow 127.0.0.1; # allow 192.168.116.0/24 # deny all; # proxy_cache_purge cache1 $host$1$is_args$args; # } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_cache cache_one; proxy_cache_valid 200 304 12h; proxy_cache_key $host$uri$is_args$args; proxy_redirect off; proxy_pass http://note.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; expires 3650d; } location ~ .*\.(js|css|html|text)?$ { proxy_cache cache_one; proxy_cache_valid 200 304 12h; proxy_cache_key $host$uri$is_args$args; proxy_redirect off; proxy_pass http://note.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; expires 30d; } location ~ .*\.(php)(.*) { proxy_pass http://note.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } ##########################################伪静态跳过########################################## #####################到此nginx proxy+web1+web2搭建完成。######################## 负载均衡后: http://bbs.t4x.org/data/attachment/forum/201405/21/100636x777dhzsaacd7m1a.jpg ##############我通过nginx上传图片,传到了apache服务器,如果分配到nginx会提示404############## #########################################配置NFS SERVER######################################### [root@PIC-SHARE ~]# rpm -aq nfs-utils rpcbind [root@PIC-SHARE ~]# yum install nfs-utils –y [root@PIC-SHARE ~]# mkdir /share/bbs/data/attachment /share/blog /share/www –p [root@PIC-SHARE ~]# /usr/sbin/useradd ebwpe -s /sbin/nologin -M [root@PIC-SHARE ~]# chown -R ebwpe.ebwpe /share [root@PIC-SHARE ~]# tail -1 /etc/passwd ebwpe:x:501:501::/home/ebwpe:/sbin/nologin [root@PIC-SHARE ~]# cat /etc/exports # NFS SERVER CONFIG /share/bbs/data/attachment 172.28.95.0/20(rw,all_squash,anonuid=501,anongid=501) /share/blog 172.28.95.0/20(rw,all_squash,anonuid=501,anongid=501) /share/www 172.28.95.122/32(rw,all_squash,anonuid=501,anongid=501) /share/www 172.28.95.123/32(rw,all_squash,anonuid=501,anongid=501) [root@PIC-SHARE ~]# /etc/init.d/rpcbind start [ OK ] [root@PIC-SHARE ~]# /etc/init.d/nfs start #########################################配置NFS CLIENT######################################### [root@LNP extra]# yum install nfs-utils –y [root@LAP ~]#yum install nfs-utils –y [root@LAP ~]#yum install nfs-utils-lib mount: wrong fs type, bad option, bad superblock on 192.168.199.194:/share/bbs/data/attachment, missing codepage or helper program, or other error (for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program) In some cases useful info is found in syslog - try dmesg | tail or so [root@LAP ~]# showmount -e 172.28.95.124 clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host) #124没有关闭防火墙 [root@LAP ~]# showmount -e 172.28.95.124 Export list for 172.28.95.124: /share/www 172.28.95.123/32,172.28.95.122/32 /share/blog 172.28.95.0/20 /share/bbs/data/attachment 172.28.95.0/20 [root@LAP 21]# cp -ap /var/site/bbs/ /tmp [root@LAP 21]# mount -t nfs 172.28.95.124:/share/bbs/data/attachment /var/site/bbs/data/attachment/ ######挂载是成功了,但是/var/site/bbs/data/attachment目录的内容没有了,因此挂载前要确认内容###### [root@LAP attachment]# pwd /var/site/bbs/data/attachment [root@LAP attachment]# cp -ap /tmp/bbs/data/attachment/* . [root@LNP extra]# cp -ap /var/site/bbs /tmp [root@LNP extra]# mount -t nfs 172.28.95.124:/share/bbs/data/attachment /var/site/bbs/data/attachment/ ################################################################################################ [root@LAP ~]# ll /var/site/bbs/data/attachment/forum/201405/21 total 320 -rw-r--r--. 1 ebwpe ebwpe 241354 May 21 10:06 100636x777dhzsaacd7m1a.jpg -rw-r--r--. 1 ebwpe ebwpe 84865 May 21 11:09 110947bndtjjdanpnjrutp.jpg ################################################################################################## [root@LNP ~]# ll /var/site/bbs/data/attachment/forum/201405/21 total 320 -rw-r--r--. 1 ebwpe ebwpe 241354 May 21 10:06 100636x777dhzsaacd7m1a.jpg -rw-r--r--. 1 ebwpe ebwpe 84865 May 21 11:09 110947bndtjjdanpnjrutp.jpg ########################################博客、主站以此类推####################################### ##############################到此NFS搭建完成。################################# 分发配置: ##########################################前期定义说明########################################## PIC-SHARE:172.28.95.124作为分发中心服务器 LAP:172.28.95.122 接收分发内容 LNP:172.28.95.123 接收分发内容 Backup:172.28.95.125 接收分发内容 Mysq:172.28.95.117 接受分发内容 建立分发用户: fenfa Visudo 服务端权限:fenfa ALL=(ALL) NOPASSWD: /usr/bin/scp, /usr/bin/ssh, /usr/bin/rsync, /bin/cp, /bin/tar, /bin/sh, /usr/local/mysql/bin/mysqldump Visudo中定义:Defaults:fenfa !requiretty ############################################定义结束############################################ [root@PIC-SHARE ~]# su - fenfa [fenfa@PIC-SHARE ~]$ ssh-keygen -t dsa [fenfa@PIC-SHARE ~]$ ssh-copy-id -i /home/fenfa/.ssh/id_dsa.pub "-p 32987 fenfa@172.28.95.122" [fenfa@PIC-SHARE ~]$ ssh-copy-id -i /home/fenfa/.ssh/id_dsa.pub "-p 32987 fenfa@172.28.95.123" [fenfa@PIC-SHARE ~]$ ssh-copy-id -i /home/fenfa/.ssh/id_dsa.pub "-p 32987 fenfa@172.28.95.125" [fenfa@PIC-SHARE ~]$ ssh-copy-id -i /home/fenfa/.ssh/id_dsa.pub "-p 32987 fenfa@172.28.95.117" [fenfa@PIC-SHARE ~]$ scp -P32987 -p /etc/hosts fenfa@172.28.95.125:/tmp [fenfa@PIC-SHARE ~]$ ssh -p32987 -t fenfa@172.28.95.125 sudo cp /tmp/hosts /etc [fenfa@PIC-SHARE ~]$ ssh -p32987 -t fenfa@172.28.95.125 rm -f /tmp/hosts [fenfa@PIC-SHARE ~]$ su - Password: [root@PIC-SHARE ~]# mkdir /byrd/script –p [fenfa@PIC-SHARE ~]$ cat /byrd/script/scp_ssh.sh #!/bin/sh #This script for scp ssh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH scp -P32987 -p /etc/hosts fenfa@172.28.95.117:/tmp >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.117 sudo /bin/cp /tmp/hosts /etc >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.117 /bin/rm -f /tmp/hosts >/dev/null 2>&1 scp -P32987 -p /etc/hosts fenfa@172.28.95.122:/tmp >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.122 sudo /bin/cp /tmp/hosts /etc >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.122 /bin/rm -f /tmp/hosts >/dev/null 2>&1 scp -P32987 -p /etc/hosts fenfa@172.28.95.123:/tmp >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.123 sudo /bin/cp /tmp/hosts /etc >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.123 /bin/rm -f /tmp/hosts >/dev/null 2>&1 scp -P32987 -p /etc/hosts fenfa@172.28.95.125:/tmp >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.125 sudo /bin/cp /tmp/hosts /etc >/dev/null 2>&1 ssh -tt -p32987 fenfa@172.28.95.125 /bin/rm -f /tmp/hosts >/dev/null 2>&1 /dev/null 2>&1 不会提示: hosts 100% 184 0.2KB/s 00:00 Connection to 172.28.95.125 closed. Connection to 172.28.95.125 closed. [fenfa@PIC-SHARE ~]$ crontab -l #This is scp_ssh config 23 01 * * * /bin/sh /byrd/script/scp_ssh.sh >/dev/null 2>&1 ##############################到此分发搭建完成。################################# Rsync配置: #############################################服务端############################################# [root@Backup ~]# yum install rsync –y [root@Backup ~]# cat /etc/rsyncd.conf # configuration file for rsync in daemon mode # Document: Byrd AT:2014-04-22 Verson1.00 uid = rsync gid = rsync use chroot = no max connections = 200 timeout = 300 syslog facility = local5 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log [site] path = /backup/site/ ignore errors read only = false list = false hosts allow = 172.28.80.0/20 auth users = rsync_backup, susan comment = CVS repository (requires authentication) secrets file = /etc/rsyncd.secrets [mysql] path = /backup/mysql/ ignore errors read only = false list = false hosts allow = 172.28.80.0/20 auth users = rsync_backup, susan comment = CVS repository (requires authentication) secrets file = /etc/rsyncd.secrets [realtimerync] path = /backup/realtimerync/ ignore errors read only = false list = false hosts allow = 172.28.80.0/20 auth users = rsync_backup, susan comment = CVS repository (requires authentication) secrets file = /etc/rsyncd.secrets [root@Backup ~]# mkdir /backup/site /backup/mysql /backup/realtimerync –p [root@Backup ~]# cat /etc/rsyncd.secrets rsync_backup:123456 [root@Backup ~]# chmod 600 /etc/rsyncd.secrets [root@Backup ~]# useradd rsync -s /sbin/nologin –M [root@Backup site]# chown -R rsync.rsync /backup [root@Backup ~]# rsync --daemon [root@Backup ~]# netstat -tunlp|grep rsync tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2133/rsync tcp 0 0 :::873 :::* LISTEN 2133/rsync #############################################客户端############################################# [root@LAP ~]# echo "123456">/etc/rsync.password [root@LAP ~]# chmod 600 /etc/rsync.password [root@LNP ~]# echo "123456">/etc/rsync.password [root@LNP ~]# chmod 600 /etc/rsync.password [root@PIC-SHARE ~]# echo "123456">/etc/rsync.password [root@PIC-SHARE ~]# chmod 600 /etc/rsync.password [root@Mysql ~]# echo "123456">/etc/rsync.password [root@Mysql ~]# chmod 600 /etc/rsync.password ############################################网站备份############################################ [root@LAP ~]# tar jcf /backupsite/site`date +%y-%m-%d-%H-%M-%S`.tar.bz2 /var/site [fenfa@LAP ~]$ sudo rsync -avz /backupsite/ rsync://rsync_backup@172.28.95.125/site --password-file=/etc/rsync.password ##########################################网站备份脚本########################################## [fenfa@LAP ~]$ cat /byrd/script/site.sh #!/bin/sh #This script for XXXXXXX PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH cd /var/ sudo tar jcf /backupsite/apache`date +%y-%m-%d-%H-%M-%S`.tar.bz2 /var/site>/dev/null 2>&1 && \ sudo rsync -avz /backupsite/ rsync://rsync_backup@172.28.95.125/site --password-file=/etc/rsync.password >/dev/null 2>&1 [fenfa@LAP ~]$ crontab -l #web backup config */5 * * * * /bin/sh /byrd/script/site.sh >/dev/null 2>&1 [fenfa@LNP ~]$ cat /byrd/script/nginx.sh #!/bin/sh #This script for XXXXXXX PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH sudo tar jcf /backup/nginx`date +%y-%m-%d-%H-%M-%S`.tar.bz2 /var/site >/dev/null 2>&1 && \ sudo rsync -avz /backup/ rsync://rsync_backup@172.28.95.125/site --password-file=/etc/rsync.password >/dev/null 2>&1 [fenfa@LNP ~]$ crontab -l */1 * * * * /bin/sh /byrd/script/nginx.sh >/dev/null 2>&1 [root@Backup site]# ll total 230336 -rw-r--r--. 1 rsync rsync 44116143 May 22 10:44 apache14-05-22-10-44-01.tar.bz2 -rw-r--r--. 1 rsync rsync 15712256 May 22 10:49 nginx14-05-22-10-49-01.tar.bz2 #########################################数据库备份脚本######################################### [root@Mysql ~]# mkdir /backup [fenfa@Mysql ~]$ cat /byrd/script/tar_mysql_backup.sh #!/bin/sh #This script for XXXXXXX PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH sudo /usr/local/mysql/bin/mysqldump -uroot -p'admin' -A -B | gzip >/backupmysql/mysql`date +%y-%m-%d-%H-%M-%S`.gz >/dev/null 2>&1 && \ sudo rsync -avz /backup/ rsync_backup@172.28.95.125::mysql --password-file=/etc/rsync.password >/dev/null 2>&1 [fenfa@Mysql ~]$ crontab -l # Backup Mysql Database */2 * * * * /bin/sh /byrd/script/tar_mysql_backup.sh >/dev/null 2>&1 ################################数据备份到此结束################################ Rsync+inotify: [root@PIC-SHARE ~]# yum install wget gcc gcc-c++ -y [root@PIC-SHARE ~]# mkdir /byrd/tools [root@PIC-SHARE tools]# wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz [root@PIC-SHARE tools]# tar zxf inotify-tools-3.14.tar.gz [root@PIC-SHARE tools]# cd inotify-tools-3.14 [root@PIC-SHARE inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify-tools-3.14 [root@PIC-SHARE inotify-tools-3.14]# make && make install [root@PIC-SHARE inotify-tools-3.14]# yum install rsync –y [root@PIC-SHARE inotify-tools-3.14]# ll /etc/rsync.password -rw-------. 1 root root 7 May 21 14:02 /etc/rsync.password [root@PIC-SHARE inotify-tools-3.14]# sh /byrd/script/inotify.sh & [root@PIC-SHARE ~]# cat /byrd/script/inotify.sh #!/bin/bash host01=172.28.95.125 src=/share/ dst=realtimerync user=rsync_backup rsync_passfile=/etc/rsync.password inotify_home=/usr/local/inotify-tools-3.14/ #judge if [ ! -e "$src" ] \ || [ ! -e "{rsync_passfile}" ] \ || [ ! -e "${inotify_home}/bin/inotifywait" ] \ || [ ! -e "/usr/bin/rsync" ]; then echo "Check File and Folder" exit 9 fi ${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e close_write,delete,create,attrib $src \ | while read file do cd $src && sudo rsync -avz -R --delete ./ --timeout=100 $user@$host01::$dst --password-file={rsync_passfile} >/dev/null 2>&1 done exit 0 做测试看看是否实时同步: http://bbs.t4x.org/data/attachment/forum/201405/22/143947n166vtt36mvxc2tm.jpg 新上传的图片 [root@Backup ~]# ll /backup/realtimerync/bbs/data/attachment/forum/201405/22/ total 236 -rw-r--r--. 1 rsync rsync 241354 May 22 14:39 143947n166vtt36mvxc2tm.jpg [root@PIC-SHARE share]# ll /share/bbs/data/attachment/forum/201405/22/ total 236 -rw-r--r--. 1 ebwpe ebwpe 241354 May 22 14:39 143947n166vtt36mvxc2tm.jpg http://bbs.t4x.org/data/attachment/forum/201405/22/144507q3svq3v909vppvle.jpg [root@Backup ~]# ll /backup/realtimerync/bbs/data/attachment/forum/201405/22/ total 320 -rw-r--r--. 1 rsync rsync 241354 May 22 14:39 143947n166vtt36mvxc2tm.jpg -rw-r--r--. 1 rsync rsync 84865 May 22 14:45 144507q3svq3v909vppvle.jpg [root@PIC-SHARE share]# ll /share/bbs/data/attachment/forum/201405/22/ total 320 -rw-r--r--. 1 ebwpe ebwpe 241354 May 22 14:39 143947n166vtt36mvxc2tm.jpg -rw-r--r--. 1 ebwpe ebwpe 84865 May 22 14:45 144507q3svq3v909vppvle.jpg #################################实时同步完成################################## 发送SA:(此处操作由薛保库提供帮助,特此感谢!) 参考:http://storysky.blog.51cto.com/628458/293005 yum install vim wget zlib-devel gcc gcc-c++ -y [root@Backup tools]# http://jaist.dl.sourceforge.net/project/msmtp/msmtp/1.4.32/msmtp-1.4.32.tar.bz2 [root@Backup tools]# tar jxf msmtp-1.4.32.tar.bz2 [root@Backup tools]# cd msmtp-1.4.32 [root@Backup msmtp-1.4.32]# ./configure --prefix=/usr/local/msmtp [root@Backup msmtp-1.4.32]# make && make install [root@Backup msmtp-1.4.32]# mkdir /usr/local/msmtp/etc [root@Backup msmtp-1.4.32]# cd /usr/local/msmtp/etc [root@Backup etc]# cat msmtprc account default host smtp.163.com from imbyrd@163.com auth login port 25 user imbyrd@163.com password admin tls off syslog on logfile /var/log/msmtp.log [root@Backup etc]# chmod 600 /usr/local/msmtp/etc/msmtprc [root@Backup etc]# yum install mutt –y root@Backup etc]# /usr/local/msmtp/bin/msmtp imbyrd@qq.com hello,wo test [root@Backup etc]# cat >> /etc/Muttrc <<BYRD #BY:BYRD set sendmail="/usr/local/msmtp/bin/msmtp" set use_from=yes set realname="imbyrd@163.com" set editor="vim" #BY:BYRD BYRD [root@Backup etc]# echo "内容"|mutt -s "标题" 804115546@qq.com [root@Backup backup]# echo "`ls -lh /backup/site/`"|mutt -s "网站备份成功通知" 804115546@qq.com [root@Backup backup]# echo "`ls -lh /backup/mysql/`"|mutt -s "数据库备份成功通知" 804115546@qq.com #########################################定时发送任务######################################### [root@Backup backup]# cat /byrd/script/mail.sh #!/bin/sh #This script for XXXXXXX PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH echo "`ls -lh /backup/site/`"|mutt -s "网站备份成功通知" 804115546@qq.com echo "`ls -lh /backup/mysql/`"|mutt -s "数据库备份成功通知" 804115546@qq.com [root@Backup backup]# crontab -l # mail */1 * * * * /bin/sh /byrd/script/mail.sh >/dev/null 2>&1 ################################发送邮件通知完成################################# 文件的完整性检测:(此处操作由薛保库提供帮助,特此感谢!)[以一台web和backup做演示] fenfa ALL=(ALL) NOPASSWD: /usr/bin/scp, /usr/bin/ssh, /usr/bin/rsync, /bin/cp, /bin/tar, /bin/sh, /usr/bin/md5sum [root@LAP ~]# mkdir /backup/site -p [root@LAP ~]# chown -R fenfa.fenfa /backup [fenfa@LAP ~]$ cat /byrd/script/site.sh #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH sudo tar jcf /backup/site/apache`date +%y-%m-%d-%H-%M-%S`.tar.bz2 /var/site>/dev/null 2>&1 && \ md5sum /backup/site/apache* >/backup/site/apachemd5.txt && \ sudo rsync -avz /backup/site/ rsync://rsync_backup@172.28.95.125/site --password-file=/etc/rsync.password >/dev/null 2>&1 [fenfa@LAP ~]$ crontab -l 2 2 * * * /bin/sh /byrd/script/site.sh >/dev/null 2>&1 #################################################################################################### [root@Backup site]# cat /byrd/script/mail.sh #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH md5sum /backup/site/apache*>/backup/site/backupapache.txt && \ echo "`diff /backup/site/backupapache.txt /backup/site/apachemd5.txt`"|mutt -s "Web Site Backup Successful" 804115546@qq.com [root@Backup site]# crontab -l # mail 10 3 * * * /bin/sh /byrd/script/mail.sh >/dev/null 2>&1 |
问题:
0 1 2 |
Setting up watches. Beware: since -r was given, this may take a while! Failed to watch /; upper limit on inotify watches reached! Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'. |
解决方法:
0 1 2 3 4 |
# cat /proc/sys/fs/inotify/max_user_watches 8192 # echo 16000 > /proc/sys/fs/inotify/max_user_watches # cat /proc/sys/fs/inotify/max_user_watches 16000 |
inotify
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#!/bin/bash # Author:Byrd # Version:0.2 # Site:note.t4x.org # Contact:root#t4x.org # Create Time: 2017/11/27/11:28 IP=( 1.1.1.1 ) src=/web/site/img dst=img user=rsync_backup rsync_passfile=/etc/rsync.password inotify_home=/usr/local/inotify #judge if [ ! -e "$src" ] \ || [ ! -e "{rsync_passfile}" ] \ || [ ! -e "${inotify_home}/bin/inotifywait" ] \ || [ ! -e "/usr/bin/rsync" ]; then echo "Check File and Folder" exit 9 fi ${inotify_home}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%Xe %w%f %w%f' -e close_write,delete,create,attrib,move $src | while read file do echo $file --- change_file() { INO_EVENT=$(echo $file | awk '{print $1}') INO_FILE=$(echo $file | awk '{print $2}'| cut -b 15-) } change_file for ((i=0;i<${#IP[*]};i++)) do if [ $INO_EVENT = 'CREATE' ] || [ $INO_EVENT = 'CLOSE_WRITEXCLOSE' ] || [ $INO_EVENT = 'CREATEXISDIR' ] || [ $INO_EVENT = 'MOVED_TO' ]; then cd $src && rsync -avz --port=29873 -R ./$INO_FILE --timeout=100 $user@${IP[$i]}::$dst --password-file={rsync_passfile} >/dev/null 2>&1 elif [ $INO_EVENT == 'ATTRIB' ]; then if [ -d $INO_FILE ]; then cd $src && rsync -avz --port=29873 -R ./$INO_FILE --timeout=100 $user@${IP[$i]}::$dst --password-file={rsync_passfile} >/dev/null 2>&1 fi elif [ $INO_EVENT == 'DELETE' ]; then if [ -d $INO_FILE ]; then cd $src && rsync -avz --delete --port=29873 -R ./$INO_FILE --timeout=100 $user@${IP[$i]}::$dst --password-file={rsync_passfile} >/dev/null 2>&1 fi else cd $src && rsync -avz --port=29873 -R ./ --timeout=100 $user@${IP[$i]}::$dst --password-file={rsync_passfile} >/dev/null 2>&1 fi #cd $src && rsync -avz --port=29873 -R ./ --timeout=100 $user@${IP[$i]}::$dst --password-file={rsync_passfile} #cd $src && rsync -avz --port=29873 -R ./ --timeout=100 $user@${IP[$i]}::$dst --password-file={rsync_passfile} >/dev/null 2>&1 done done exit 0 |
申明:本文由BYRD原创(基于Centos6.4 X64),未经许可禁止转载!
权限:http://note.t4x.org/project/visudo-user-rights-management-scheme/
服务:http://note.t4x.org/system/configure-httpd-mysql-php/
认证:http://note.t4x.org/system/centos-ssh-dsa/
扩展:http://note.t4x.org/system/opcache-xcache-memcache/SourceByrd's Weblog-https://note.t4x.org/project/basic-architecture-diagram/ SourceByrd's Weblog-https://note.t4x.org/project/basic-architecture-diagram/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!