LVS+KeepaLived+Nginx SSL(二)

LVS+KeepaLived+Nginx SSL

LNMP安裝

 

  1. #!/bin/bash 
  2. #auto install lnmp 
  3. #By L 
  4. #改編自linuxtone 
  5.  
  6. #Create user for The LNMP 
  7. userdel -r www ; useradd -M -s /sbin/nologin   www 
  8. userdel -r mysql ; useradd -M -s /sbin/nologin mysql 
  9.  
  10. #init var 
  11. NGINX_HOME="/opt/nginx" 
  12. NGINX_VERSION="nginx-1.0.8" 
  13. PCRE_VERSION="pcre-8.10" 
  14.  
  15. PHP_HOME="/opt/php" 
  16. PHP_VERSION="php-5.3.10" 
  17. LIBICONV_VERSION="libiconv-1.13.1" 
  18. LIBMCRYPT_VERSION="libmcrypt-2.5.8" 
  19. MHASH_VERSION="mhash-0.9.9.9" 
  20. MCRYPT_VERSION="mcrypt-2.6.8" 
  21.  
  22. MYSQL_HOME="/opt/mysql" 
  23. MYSQL_DATA_DIR="/data/mysql/3306/data" 
  24. MYSQL_CONFIG_DIR="/etc" 
  25. MYSQL_PORT="3306" 
  26. MYSQL_VERSION="mysql-5.5.15" 
  27. CMAKE_VERSION="cmake-2.8.4" 
  28.  
  29. #install the rpm bao 
  30. yum -y install dialog ntp vim-enhanced vixie-cron gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel net-snmp net-snmp-devel nss_ldap openldap-clients openldap-servers libtidy libtidy-devel 
  31.  
  32. #wget the packet 
  33. cat >> list.txt << EOF 
  34. http://docs.linuxtone.org/soft/lemp/packages/${PCRE_VERSION}.tar.gz 
  35. http://docs.linuxtone.org/soft/lemp/packages/${LIBICONV_VERSION}.tar.gz 
  36. http://docs.linuxtone.org/soft/lemp/packages/${LIBMCRYPT_VERSION}.tar.gz 
  37. http://docs.linuxtone.org/soft/lemp/packages/${MCRYPT_VERSION}.tar.gz 
  38. http://docs.linuxtone.org/soft/lemp/packages/${MHASH_VERSION}.tar.gz 
  39. http://www.cmake.org/files/v2.8/${CMAKE_VERSION}.tar.gz 
  40. http://files.directadmin.com/services/all/mysql/${MYSQL_VERSION}.tar.gz 
  41. http://nginx.org/download/${NGINX_VERSION}.tar.gz 
  42. http://ftp.wayne.edu/php/${PHP_VERSION}.tar.gz 
  43. EOF 
  44. wget -i list.txt 
  45.  
  46. #install the mysql 
  47.  
  48. tar zvxf ${CMAKE_VERSION}.tar.gz 
  49. cd ${CMAKE_VERSION} 
  50. ./configure && make  && make install 
  51. cd ../ 
  52.  
  53. tar zxvf ${MYSQL_VERSION}.tar.gz 
  54. cd ${MYSQL_VERSION} 
  55. cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_HOME} -DMYSQL_DATADIR=${MYSQL_DATA_DIR} -DSYSCONFDIR=${MYSQL_CONFIG_DIR} -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=${MYSQL_PORT} -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=yes  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on 
  56. gmake 
  57. make install 
  58.  
  59. #init mysql 
  60. mkdir -p ${MYSQL_DATA_DIR}  
  61. cp -f support-files/mysql.server /etc/init.d/mysqld 
  62. chmod 755 /etc/init.d/mysqld 
  63. chkconfig --add mysqld 
  64. chkconfig mysqld on 
  65. cp support-files/my-medium.cnf ${MYSQL_CONFIG_DIR}/my.cnf 
  66.  
  67. #init the lib file 
  68. echo "$MYSQL_HOME/lib" >>/etc/ld.so.conf 
  69. /sbin/ldconfig 
  70.  
  71. #link the command 
  72. rm -rf /usr/bin/mysql* &> /dev/null 
  73. ln -s ${MYSQL_HOME}/bin/* /usr/bin/ 
  74.  
  75. #init mysql database 
  76. ${MYSQL_HOME}/scripts/mysql_install_db --basedir=${MYSQL_HOME} --datadir=${MYSQL_DATA_DIR} --user=mysql 
  77. cd ../ 
  78.  
  79. #install nginx 
  80. tar zvxf ${PCRE_VERSION}.tar.gz 
  81. cd ${PCRE_VERSION} 
  82. ./configure && make  && make install 
  83. cd ../ 
  84.  
  85. tar zvxf ${NGINX_VERSION}.tar.gz 
  86. cd ${NGINX_VERSION} 
  87. ./configure --user=www --group=www --prefix=${NGINX_HOME} --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_gzip_static_module 
  88.  
  89. make  &&  make install 
  90. cd ../ 
  91. #install php-support 
  92. tar zxvf ${LIBICONV_VERSION}.tar.gz  
  93. cd ${LIBICONV_VERSION}  
  94. ./configure --prefix=/usr/local  
  95. make  &&  make install  
  96. cd ../ 
  97.  
  98. tar zxvf ${LIBMCRYPT_VERSION}.tar.gz  
  99. cd ${LIBMCRYPT_VERSION}  
  100. ./configure --prefix=/usr  
  101. make   && make install  
  102. cd libltdl/  
  103. ./configure --enable-ltdl-install  
  104. make  && make install  
  105. cd ../../ 
  106.  
  107. tar zxvf ${MHASH_VERSION}.tar.gz  
  108. cd ${MHASH_VERSION}  
  109. ./configure --prefix=/usr  
  110. make  && make install  
  111. ldconfig  
  112. cd ../ 
  113.  
  114. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la 
  115. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so 
  116. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 
  117. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 
  118. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a 
  119. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la 
  120. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so 
  121. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 
  122. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 
  123. /sbin/ldconfig 
  124.  
  125.  
  126. tar zxvf ${MCRYPT_VERSION}.tar.gz  
  127. cd ${MCRYPT_VERSION}  
  128. ./configure --prefix=/usr  
  129. make   && make install  
  130. cd ../ 
  131.  
  132. echo "/usr/lib" >> /etc/ld.so.conf 
  133. echo "/usr/local/lib" >> /etc/ld.so.conf 
  134. /sbin/ldconfig 
  135.  
  136. #install php 
  137. tar zxvf ${PHP_VERSION}.tar.gz 
  138. cd ${PHP_VERSION} 
  139. ./configure --prefix=${PHP_HOME} --with-config-file-path=${PHP_HOME}/etc --with-mysql=${MYSQL_HOME} --with-mysqli=${MYSQL_HOME}/bin/mysql_config --with-pdo-mysql=${MYSQL_HOME} --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-pdo-sqlite --enable-pdo --with-bz2 --with-gettext --with-snmp --with-libxml-dir --enable-xml --disable-rpath --disable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear 
  140. make ZEND_EXTRA_LIBS='-liconv' 
  141. make install 
  142. cp php.ini-production ${PHP_HOME}/etc/php.ini 
  143. cd ../ 
  144. echo "" 

配置Nginx

  1. user  www www; 
  2.  
  3. worker_processes 8; 
  4.  
  5. error_log  /data/web_logs/nginx_error.log  crit; 
  6.  
  7. pid        /opt/nginx/nginx.pid; 
  8.  
  9. #Specifies the value for maximum file descriptors that can be opened by this process. 
  10. worker_rlimit_nofile 65535; 
  11.  
  12. events 
  13.   use epoll; 
  14.   worker_connections 65535; 
  15.  
  16. http 
  17.   include       mime.types; 
  18.   default_type  application/octet-stream; 
  19.  
  20.   #charset  gb2312; 
  21.   server_names_hash_bucket_size 128; 
  22.   client_header_buffer_size 32k; 
  23.   large_client_header_buffers 4 32k; 
  24.   client_max_body_size 8m; 
  25.        
  26.   sendfile on; 
  27.   tcp_nopush     on; 
  28.  
  29.   keepalive_timeout 60; 
  30.  
  31.   tcp_nodelay on; 
  32.  
  33.   fastcgi_connect_timeout 300; 
  34.   fastcgi_send_timeout 300; 
  35.   fastcgi_read_timeout 300; 
  36.   fastcgi_buffer_size 64k; 
  37.   fastcgi_buffers 4 64k; 
  38.   fastcgi_busy_buffers_size 128k; 
  39.   fastcgi_temp_file_write_size 128k; 
  40.  
  41.   gzip on; 
  42.   gzip_min_length  1k; 
  43.   gzip_buffers     4 16k; 
  44.   gzip_http_version 1.0; 
  45.   gzip_comp_level 2; 
  46.   gzip_types       text/plain application/x-javascript text/css application/xml; 
  47.   gzip_vary on; 
  48.     log_format  main '$remote_addr - $remote_user [$time_local] "$request" ' 
  49.                '$status $body_bytes_sent "$http_referer" ' 
  50.                '"$http_user_agent" $http_x_forwarded_for'; 
  51.   include /opt/nginx/conf/sites-enabled/*; 

關於Nginx配置文件的解釋可以去看:

http://liuyu.blog.51cto.com/183345/294118

Keepalived_timeout 的詳細解釋可以去看:
http://www.perfgeeks.com/?p=673

PHP-fpm啓動腳本:

 

  1. #!/bin/bash 
  2. PID='/opt/php/logs/php-fpm.pid' 
  3. FPM='/opt/php/sbin/php-fpm' 
  4.  
  5. case $1 in 
  6.     start) 
  7.  
  8.         echo  "Starting php_fpm.... "     
  9.  
  10.         sleep 1 
  11.  
  12.         if [ -f $PID ];then 
  13.             echo  'The PID file has been exists' 
  14.             exit 1 
  15.         fi 
  16.  
  17.         $FPM 
  18.  
  19.         if [ $? -eq 0  ];then 
  20.             echo  'done' 
  21.         else 
  22.             exit 1 
  23.         fi 
  24.  
  25.     ;; 
  26.      
  27.     stop) 
  28.  
  29.         echo  "Shutting down php_fpm " 
  30.  
  31.         sleep 1 
  32.  
  33.         if [ ! -r $PID ] ; then 
  34.         echo "warning, no pid file found - php-fpm is not running ?" 
  35.         exit 1 
  36.         fi 
  37.  
  38.         kill -TERM `cat $PID` 
  39.  
  40.     ;; 
  41.  
  42.     restart) 
  43.  
  44.         $0 stop 
  45.         $0 start 
  46.     ;; 
  47.  
  48.     reload) 
  49.  
  50.     echo  "Reload service php-fpm " 
  51.  
  52.         sleep 1 
  53.  
  54.     if [ ! -r $PID ] ; then 
  55.         echo "warning, no pid file found - php-fpm is not running ?" 
  56.         exit 1 
  57.     fi 
  58.  
  59.     kill -USR2 `cat $PID` 
  60.  
  61.     echo " done" 
  62.     ;; 
  63.     *) 
  64.         echo "Usage: $0 {start|stop|restart|reload|}" 
  65.             exit 1 
  66.     ;; 
  67.   
  68.  esac 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章