Integrated Installation of nginx + resin + memcached in CentOS

Source: Internet
Author: User
Tags openldap
Due to the requirements of the company's operating environment, nginx and resin integration are required. nginx is responsible for processing the static part and resin is responsible for processing the dynamic part of the system environment: CentOS5.6X64

Due to the requirements of the company's operating environment, nginx and resin integration are required. nginx is responsible for processing the static part and resin is responsible for processing the dynamic part.

System Environment: CentOS 5.6X64

# Install common components

  1. Yum-y install gcc-c ++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel libjpeg \
  2. Libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 \
  3. Glib2-devel bzip2 bzip2-devel ncurses-devel curl-devel e2fsprogs e2fsprogs-devel libidn-devel openldap \
  4. Openldap-devel openldap-clients openldap-servers nss_ldap expat-devel libtool-ltdl-devel bison

# ---------------------------- Use cmake to compile and install mysql ----------------------------------
# Using Tcmalloc to optimize nginx and mysql
# Install the libunwind library for the 64-bit operating system. Do not install the 32-bit operating system. The libunwind Library provides the basic stack trigger function for 64-bit CPU and operating system-based programs, these include the APIs used to import and output stack tracing, APIs used to program stack decoding, and APIs that support the C ++ exception handling mechanism.
/Opt
Wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
Tar-zxvf libunwind-0.99.tar.gz
./Configure
Make
Make install

Cd/opt
Tar-zxvf google-perftools-1.7.tar.gz
Cd google-perftools-1.7/
./Configure
Make; make install

Echo "/usr/local/lib">/etc/ld. so. conf. d/usr_local_lib.conf
/Sbin/ldconfig
Cd ../

Tar-zxvf cmake-2.8.4.tar.gz
Cd cmake-2.8.4
./Bootstrap
Gmake
Gmake install
Cd ../

/Usr/sbin/groupadd mysql
/Usr/sbin/useradd-g mysql-s/sbin/nologin
Mkdir-p/data/mysql/{data, binlog, relaylog, mysql}
Chown-R mysql: mysql/data/mysql
Cd/opt
Tar zxvf mysql-5.5.13.tar.gz
Cd mysql-5.5.13/
Rm-rf CMakeCache.txt
Cmake-DCMAKE_INSTALL_PREFIX =/usr/local/mysql \
-DMYSQL_UNIX_ADDR =/data/mysql. sock \
-DDEFAULT_CHARSET = utf8 \
-DDEFAULT_COLLATION = utf8_general_ci \
-DEXTRA_CHARSETS = all \
-DWITH_MYISAM_STORAGE_ENGINE = 1 \
-DWITH_INNOBASE_STORAGE_ENGINE = 1 \
-DWITH_READLINE = 1 \
-DENABLED_LOCAL_INFILE = 1 \
-DMYSQL_DATADIR =/data/mysql/data \
-DMYSQL_TCP_PORT = 3306
Make; make install
Chmod + w/usr/local/mysql
Chown-R mysql: mysql/usr/local/mysql
Ln-s/usr/local/mysql/lib/libmysqlclient. so.18/usr/lib/libmysqlclient. so.18

# Editing the mysql configuration file
Vi/etc/my. cnf

  1. [Client]
  2. Port = 3306
  3. Socket =/data/mysql. sock
  4.  
  5. [Mysqld]
  6. Character_set_server = utf8
  7. Collation-server = utf8_general_ci
  8. Replicate-ignore-db = mysql
  9. Replicate-ignore-db = test
  10. Replicate-ignore-db = information_schema
  11. User = mysql
  12. Port = 3306
  13. Socket =/data/mysql. sock
  14. Basedir =/usr/local/mysql
  15. Datadir =/data/mysql/data
  16. Log-error =/data/mysql/mysql_error.log
  17. Pid-file =/data/mysql. pid
  18. Open_files_limit = 10240
  19. Back_log = 600
  20. Max_connections = 5000
  21. Max_connect_errorrs = 6000
  22. Table_cache = 512
  23. External-locking = FALSE
  24. Max_allowed_packet = 32 M
  25. Sort_buffer_size = 6 M
  26. Join_buffer_size = 8 M
  27. Thread _ cache_size = 300
  28. Thread_concurrency = 8
  29. Query_cache_size = 512 M
  30. Query_cache_limit = 2 M
  31. Query_cache_min_res_unit = 2 k
  32. Default-storage-engine = MyISAM
  33. Thread_stack = 256 K
  34. Transaction_isolation = READ-COMMITTED
  35. Tmp_table_size = 256 M
  36. Max_heap_table_size = 256 M
  37. Long_query_time = 3
  38. Log-slave-updates
  39. Log-bin =/data/mysql/binlog
  40. Binlog_cache_size = 4 M
  41. Binlog_format = MIXED
  42. Max_binlog_cache_size = 8 M
  43. Max_binlog_size = 100 M
  44. Relay-log-index =/data/mysql/relaylog
  45. Relay-log-info-file =/data/mysql/relaylog
  46. Relay-log =/data/mysql/relaylog
  47. Expire_logs_days = 30
  48. Key_buffer_size = 384 M
  49. Read_buffer_size = 4 M
  50. Read_rnd_buffer_size = 16 M
  51. Bulk_insert_buffer_size = 64 M
  52. Myisam_sort_buffer_size = 128 M
  53. Myisam_max_sort_file_size = 100G
  54. Myisam_repair_threads = 1
  55. Myisam_recover
  56.  
  57. Interactive_timeout = 120
  58. Wait_timeout = 120
  59.  
  60. Skip_external_locking
  61. Skip-name-resolve
  62. # Master-connect-retry = 10
  63. Slave-skip-errors = 1396
  64.  
  65. # Master-host = 192.168.1.2
  66. # Master-user = username
  67. # Master-password = password
  68. # Master-ports = 3306
  69.  
  70. Server-id = 1
  71.  
  72. Skip-innodb
  73.  
  74. Log-slow-queries =/data/mysql/slow. log
  75. Long_query_time = 2
  76.  
  77. [Mysqldump]
  78. Quick
  79. Max_allowed_packet = 32 M

# Initializing mysql
/Usr/local/mysql/scripts/mysql_install_db -- basedir =/usr/local/mysql -- datadir =/data/mysql/data -- user = mysql

# Using TCMalloc to improve mysql performance in high concurrency
Vi/usr/local/mysql/bin/mysqld_safe

# In the next line of # executing mysqld_safe, add:
Export LD_PRELOAD =/usr/local/lib/libtcmalloc. so

# Use lsofCommandCheck whether tcmalloc is effective
/Usr/sbin/lsof-n | grep tcmalloc

# Setting the mysql Startup File
Cp support-files/mysql. server/etc/rc. d/init. d/mysqld
Vi/etc/rc. d/init. d/mysqld
Basedir =/usr/local/mysql
Datadir =/data/mysql/data

Chmod 700/etc/rc. d/init. d/mysqld
/Etc/rc. d/init. d/mysqld start
/Sbin/chkconfig -- add mysqld
/Sbin/chkconfig -- level 2345 mysqld on
Ln-s/usr/local/mysql/bin/mysql/sbin/mysql
Ln-s/usr/local/mysql/bin/mysqladmin/sbin/mysqladmin

# Set the root password (753951)
/Sbin/mysqladmin-u root password 753951
#/Usr/local/mysql/bin/mysqladmin-u root-p password 456 -- modify the password set by root

# Configure the library file search path
Echo "/usr/local/mysql/lib/mysql">/etc/ld. so. conf
/Sbin/ldconfig

# Add/usr/local/mysql/bin to the environment variable PATH.
Export PATH = $ PATH:/usr/local/mysql/bin

# Add a mysql management account
# Mysql-h localhost-u root-p753951
# Msqyl> use mysql;
# Msqyl> grant all on *. * to 'kerry' @ '192. 168.9.100 'identified by '123 ';
# Msqyl> flush privileges;
# Msqyl> exit;

# -------------------------- Install resin and JDK -------------------------#
Cd/opt
Music jdk-6u29-linux-x64.bin/usr/local/

# Setting Environment Variables

  1. Cat>/etc/profile <
  2. Export JAVA_HOME =/usr/local/jdk1.6.0 _ 25
  3. Export CLASS_PATH = $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib
  4. Export PATH = $ PATH: $ JAVA_HOME/bin
  5. EOF

Source/etc/profile

# View the java version
Java-version

Tar-zxvf resin-4.0.26.tar.gz
Cd resin-1, 4.0.26
./Configure -- prefix =/usr/local/resin
Make; make install

# Start resin
/Usr/local/resin/bin/resin. sh start

# Set resin startup
Cp-r init. d/resin/etc/init. d/resin
Chmod + x/etc/init. d/resin
/Sbin/chkconfig -- add resin
/Sbin/chkconfig -- level 2345 resin on

# ---------------------------- Install nginx ------------------------------#
Cd/opt
/Usr/sbin/groupadd www
/Usr/sbin/useradd-g www-s/sbin/nologin
Mkdir-p/data/www
Chmod + w/data/www
Chown-R www: www/data/www

Tar zxvf pcre-8.12.tar.gz
Cd pcre-8.12/
./Configure
Make; make install
Cd ../

Tar-zxvf nginx-1.0.13.tar.gz
Cd nginx-1.0.13
./Configure -- user = www -- group = www -- prefix =/usr/local/nginx -- with-http_stub_status_module -- with-http_ssl_module -- with-http_flv_module -- with-http_gzip_static_module -- with-google_perftools_module --
Make; make install
Cd ../

Mkdir-p/data/logs
Chmod + w/data/logs
Chown-R www: www/data/logs

# Editing the nginx configuration file
Mv/usr/local/nginx/conf/nginx. conf/usr/local/nginx/conf/nginx. conf. bak

  1. Cat>/usr/local/nginx/conf/nginx. conf <
  2. User www;
  3. Worker_processes 8;
  4. Error_log/usr/local/nginx/logs/nginx_error.log crit;
  5. Pid/usr/local/nginx. pid;
  6. # Use Tcmalloc to optimize nginx Performance
  7. Google_perftools_profiles/var/tmp/tcmalloc;
  8. # Specifies the value for maximum file descriptors that can be opened by this process.
  9. Worker_rlimit_nofile 65535;
  10. # Working mode and maximum number of connections
  11. Events
  12. {
  13. Use epoll;
  14. Worker_connections 65535;
  15. }
  16. # Set the http server and use its reverse proxy function to provide Load Balancing support
  17. Http
  18. {
  19. # Set the mime type
  20. Include mime. types;
  21. Default_type application/octet-stream;
  22. # Charset gb2312;
  23. # Set Request Buffer
  24. Server_names_hash_bucket_size 128;
  25. Client_header_buffer_size 32 k;
  26. Large_client_header_buffers 4 32 k;
  27. # Set the size limit of files that can be uploaded by the client
  28. Client_max_body_size 300 m;
  29. Sendfile on;
  30. Tcp_nopush on;
  31. Keepalive_timeout 60;
  32. Tcp_nodelay on;
  33. Server_tokens off;
  34. Client_body_buffer_size 512 k;
  35. Proxy_connect_timeout 5;
  36. Proxy_send_timeout 60;
  37. Proxy_read_timeout 5;
  38. Proxy_buffer_size 16 k;
  39. Proxy_buffers 4 64 k;
  40. Proxy_busy_buffers_size 128 k;
  41. Proxy_temp_file_write_size 128 k;
  42. # Fastcgi_connect_timeout 300;
  43. # Fastcgi_send_timeout 300;
  44. # Fastcgi_read_timeout 300;
  45. # Fastcgi_buffer_size 64 k;
  46. # Fastcgi_buffers 4 64 k;
  47. # Fastcgi_busy_buffers_size 128 k;
  48. # Fastcgi_temp_file_write_size 128 k;
  49. Gzip on;
  50. Gzip_min_length 1 k;
  51. Gzip_buffers 4 16 k;
  52. Gzip_http_version 1.1;
  53. Gzip_comp_level 2;
  54. Gzip_types text/plain application/x-javascript text/css application/xml;
  55. Gzip_vary on;
  56.  
  57. # Limit_zone crawler $ binary_remote_addr 10 m;
  58.  
  59. ### Prohibit Website access through ip addresses
  60. Server {
  61. Server_name _;
  62. Return 404;
  63. }
  64. Server
  65. {
  66. Listen 80;
  67. Server_name www.king.com;
  68. Index index.html index.htm index. jsp index. do; # sets the default homepage address for access.
  69. Root/data/www/web001/; # set the path for storing website resources
  70. # Limit_conn crawler 20;
  71. If (-d $ request_filename)
  72. {
  73. Rewrite ^/(. *) ([^/]) $ http: // $ host/$1 $2/permanent;
  74. }
  75. # All jsp pages are handled by resin
  76. Location ~ \. (Jsp | jspx | do )? $ {
  77. Proxy_set_header Host $ host;
  78. Proxy_set_header X-Real-IP $ remote_addr;
  79. Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
  80. Proxy_pass http: // 127.0.0.1: 8080; # redirect to resin
  81. }
  82. Location ~ . *\. (Htm | html | gif | jpg | jpeg | png | bmp | swf | ioc | rar | zip | txt | flv | mid | doc | ppt | pdf | xls | mp3 | wma) $ # Set direct access to static files without passing through resin
  83. {
  84. Expires 30d;
  85. }
  86. Location ~ . * \. (Js | css )? $
  87. {
  88. Expires 1 h;
  89. }
  90.  
  91. # Define the write format of access logs
  92. Log_format wwwlog '$ remote_addr-$ remote_user [$ time_local] "$ request "'
  93. '$ Status $ body_bytes_sent "$ http_referer "'
  94. '"$ Http_user_agent" $ http_x_forwarded_for ';
  95. Access_log/data/logs/www_nginx.log wwwlog; # set the path for storing access logs
  96. }
  97. Server
  98. {
  99. Listen 80;
  100. Server_name status.www.kerry.com;
  101. Location /{
  102. Stub_status on;
  103. Access_log off;
  104. }
  105. }
  106. }
  107. EOF

# Add a STARTUP script
Vi/etc/init. d/nginx

  1. #! /Bin/sh
  2.  
  3. # Description: Startup script for webserver on CentOS. cp it in/etc/init. d and
  4. # Chkconfig -- add nginx & chkconfig nginx on
  5. # Then you can use server command control nginx
  6. #
  7. # Chkconfig: 2345 08 99
  8. # Description: Starts, stops nginx
  9.  
  10. Set-e
  11.  
  12. PATH = $ PATH:/usr/local/nginx/sbin/
  13. DESC = "nginx daemon"
  14. NAME = nginx
  15. DAEMON =/usr/local/nginx/sbin/$ NAME
  16. CONFIGFILE =/usr/local/nginx/conf/nginx. conf
  17. PIDFILE =/usr/local/nginx/$ NAME. pid
  18. SCRIPTNAME =/etc/init. d/$ NAME
  19.  
  20. # Gracefully exit if the package has been removed.
  21. Test-x $ DAEMON | exit 0
  22.  
  23. D_start (){
  24. $ DAEMON-c $ CONFIGFILE | echo-n "already running"
  25. }
  26.  
  27. D_stop (){
  28. Kill-QUIT 'cat $ pidfile' | echo-n "not running"
  29. }
  30.  
  31. D_reload (){
  32. Kill-HUP 'cat $ pidfile' | echo-n "can't reload"
  33. }
  34.  
  35. Case "$1" in
  36. Start)
  37. Echo-n "Starting $ DESC: $ NAME"
  38. D_start
  39. Echo "."
  40. ;;
  41. Stop)
  42. Echo-n "Stopping $ DESC: $ NAME"
  43. D_stop
  44. Echo "."
  45. ;;
  46. Reload)
  47. Echo-n "Reloading $ DESC configuration ..."
  48. D_reload
  49. Echo "reloaded ."
  50. ;;
  51. Restart)
  52. Echo-n "Restarting $ DESC: $ NAME"
  53. D_stop
  54. Sleep 1
  55. D_start
  56. Echo "."
  57. ;;
  58. *)
  59. Echo "Usage: $ SCRIPTNAME {start | stop | restart | force-reload}"> & 2
  60. Exit 3
  61. ;;
  62. Esac
  63.  
  64. Exit 0

# Add nginx to the startup Service
Chmod 700/etc/init. d/nginx
/Etc/init. d/nginx start
/Sbin/chkconfig -- add nginx
/Sbin/chkconfig -- level 2345 nginx on

# -------------------------- Install memcache ------------------------------#
Cd/opt
Tar-xzf libevent-2.0.11-stable.tar.gz
Cd libevent-2.0.11-stable
./Configure
Make; make install
Ln-s/usr/local/lib/libevent-2.0.so.5/lib64/libevent-2.0.so.5

Cd/opt
Tar-xzf memcached-1.4.5.tar.gz
Cd memcached-1.4.5
./Configure -- prefix =/usr/local/memcached -- with-libevent =/usr
Make; make install

# Basic usage:
-L the address of the listener, memcached, has no authentication function and is strictly prohibited from being protected.
-P listens to the Internet port !!! The default value is 11211.
-D is run in the form of daemon. Generally, this parameter must be added.
-U is run as a user. Generally, low-privilege users such as nobody are selected.
-M maximum available memory, in megabytes
-The maximum number of concurrent operations in c. The default value is 1024.
-F growth factor
-P pid File
Start:
/Usr/local/memcached/bin/memcached-d-m 1024-p 11211-u www-c 4096
Close:
Killall-9 memcached

# Enable
Echo "/usr/local/memcached/bin/memcached-d-m 1024-p 11211-u www-c 4096">/etc/rc. local

# ---------------------------- Nginx and resin integration -------------------------#
# The default directory of resin is the same as that of nginx.
Vi/usr/local/resin/conf/resin. xml
Set

Modify:

# Create a test file
Vi/data/www/web001/index. jsp
2 + 2 = <% = 2 + 2%>

# Restart nginx and resin
/Etc/init. d/nginx restart
/Etc/init. d/resin restart

# Access the http://www.king.com if you see 2 + 2 = 4, it proves that nginx, resin integration successful

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.