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
- Yum-y install gcc-c ++ bison patch unzip mlocate flex wget automake autoconf gd cpp gettext readline-devel libjpeg \
- Libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 \
- Glib2-devel bzip2 bzip2-devel ncurses-devel curl-devel e2fsprogs e2fsprogs-devel libidn-devel openldap \
- 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
- [Client]
- Port = 3306
- Socket =/data/mysql. sock
-
- [Mysqld]
- Character_set_server = utf8
- Collation-server = utf8_general_ci
- Replicate-ignore-db = mysql
- Replicate-ignore-db = test
- Replicate-ignore-db = information_schema
- User = mysql
- Port = 3306
- Socket =/data/mysql. sock
- Basedir =/usr/local/mysql
- Datadir =/data/mysql/data
- Log-error =/data/mysql/mysql_error.log
- Pid-file =/data/mysql. pid
- Open_files_limit = 10240
- Back_log = 600
- Max_connections = 5000
- Max_connect_errorrs = 6000
- Table_cache = 512
- External-locking = FALSE
- Max_allowed_packet = 32 M
- Sort_buffer_size = 6 M
- Join_buffer_size = 8 M
- Thread _ cache_size = 300
- Thread_concurrency = 8
- Query_cache_size = 512 M
- Query_cache_limit = 2 M
- Query_cache_min_res_unit = 2 k
- Default-storage-engine = MyISAM
- Thread_stack = 256 K
- Transaction_isolation = READ-COMMITTED
- Tmp_table_size = 256 M
- Max_heap_table_size = 256 M
- Long_query_time = 3
- Log-slave-updates
- Log-bin =/data/mysql/binlog
- Binlog_cache_size = 4 M
- Binlog_format = MIXED
- Max_binlog_cache_size = 8 M
- Max_binlog_size = 100 M
- Relay-log-index =/data/mysql/relaylog
- Relay-log-info-file =/data/mysql/relaylog
- Relay-log =/data/mysql/relaylog
- Expire_logs_days = 30
- Key_buffer_size = 384 M
- Read_buffer_size = 4 M
- Read_rnd_buffer_size = 16 M
- Bulk_insert_buffer_size = 64 M
- Myisam_sort_buffer_size = 128 M
- Myisam_max_sort_file_size = 100G
- Myisam_repair_threads = 1
- Myisam_recover
-
- Interactive_timeout = 120
- Wait_timeout = 120
-
- Skip_external_locking
- Skip-name-resolve
- # Master-connect-retry = 10
- Slave-skip-errors = 1396
-
- # Master-host = 192.168.1.2
- # Master-user = username
- # Master-password = password
- # Master-ports = 3306
-
- Server-id = 1
-
- Skip-innodb
-
- Log-slow-queries =/data/mysql/slow. log
- Long_query_time = 2
-
- [Mysqldump]
- Quick
- 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
- Cat>/etc/profile <
- Export JAVA_HOME =/usr/local/jdk1.6.0 _ 25
- Export CLASS_PATH = $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib
- Export PATH = $ PATH: $ JAVA_HOME/bin
- 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
- Cat>/usr/local/nginx/conf/nginx. conf <
- User www;
- Worker_processes 8;
- Error_log/usr/local/nginx/logs/nginx_error.log crit;
- Pid/usr/local/nginx. pid;
- # Use Tcmalloc to optimize nginx Performance
- Google_perftools_profiles/var/tmp/tcmalloc;
- # Specifies the value for maximum file descriptors that can be opened by this process.
- Worker_rlimit_nofile 65535;
- # Working mode and maximum number of connections
- Events
- {
- Use epoll;
- Worker_connections 65535;
- }
- # Set the http server and use its reverse proxy function to provide Load Balancing support
- Http
- {
- # Set the mime type
- Include mime. types;
- Default_type application/octet-stream;
- # Charset gb2312;
- # Set Request Buffer
- Server_names_hash_bucket_size 128;
- Client_header_buffer_size 32 k;
- Large_client_header_buffers 4 32 k;
- # Set the size limit of files that can be uploaded by the client
- Client_max_body_size 300 m;
- Sendfile on;
- Tcp_nopush on;
- Keepalive_timeout 60;
- Tcp_nodelay on;
- Server_tokens off;
- Client_body_buffer_size 512 k;
- Proxy_connect_timeout 5;
- Proxy_send_timeout 60;
- Proxy_read_timeout 5;
- Proxy_buffer_size 16 k;
- Proxy_buffers 4 64 k;
- Proxy_busy_buffers_size 128 k;
- Proxy_temp_file_write_size 128 k;
- # Fastcgi_connect_timeout 300;
- # Fastcgi_send_timeout 300;
- # Fastcgi_read_timeout 300;
- # Fastcgi_buffer_size 64 k;
- # Fastcgi_buffers 4 64 k;
- # Fastcgi_busy_buffers_size 128 k;
- # Fastcgi_temp_file_write_size 128 k;
- Gzip on;
- Gzip_min_length 1 k;
- Gzip_buffers 4 16 k;
- Gzip_http_version 1.1;
- Gzip_comp_level 2;
- Gzip_types text/plain application/x-javascript text/css application/xml;
- Gzip_vary on;
-
- # Limit_zone crawler $ binary_remote_addr 10 m;
-
- ### Prohibit Website access through ip addresses
- Server {
- Server_name _;
- Return 404;
- }
- Server
- {
- Listen 80;
- Server_name www.king.com;
- Index index.html index.htm index. jsp index. do; # sets the default homepage address for access.
- Root/data/www/web001/; # set the path for storing website resources
- # Limit_conn crawler 20;
- If (-d $ request_filename)
- {
- Rewrite ^/(. *) ([^/]) $ http: // $ host/$1 $2/permanent;
- }
- # All jsp pages are handled by resin
- Location ~ \. (Jsp | jspx | do )? $ {
- 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_pass http: // 127.0.0.1: 8080; # redirect to resin
- }
- 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
- {
- Expires 30d;
- }
- Location ~ . * \. (Js | css )? $
- {
- Expires 1 h;
- }
-
- # Define the write format of access logs
- Log_format wwwlog '$ remote_addr-$ remote_user [$ time_local] "$ request "'
- '$ Status $ body_bytes_sent "$ http_referer "'
- '"$ Http_user_agent" $ http_x_forwarded_for ';
- Access_log/data/logs/www_nginx.log wwwlog; # set the path for storing access logs
- }
- Server
- {
- Listen 80;
- Server_name status.www.kerry.com;
- Location /{
- Stub_status on;
- Access_log off;
- }
- }
- }
- EOF
# Add a STARTUP script
Vi/etc/init. d/nginx
- #! /Bin/sh
-
- # Description: Startup script for webserver on CentOS. cp it in/etc/init. d and
- # Chkconfig -- add nginx & chkconfig nginx on
- # Then you can use server command control nginx
- #
- # Chkconfig: 2345 08 99
- # Description: Starts, stops nginx
-
- Set-e
-
- PATH = $ PATH:/usr/local/nginx/sbin/
- DESC = "nginx daemon"
- NAME = nginx
- DAEMON =/usr/local/nginx/sbin/$ NAME
- CONFIGFILE =/usr/local/nginx/conf/nginx. conf
- PIDFILE =/usr/local/nginx/$ NAME. pid
- SCRIPTNAME =/etc/init. d/$ NAME
-
- # Gracefully exit if the package has been removed.
- Test-x $ DAEMON | exit 0
-
- D_start (){
- $ DAEMON-c $ CONFIGFILE | echo-n "already running"
- }
-
- D_stop (){
- Kill-QUIT 'cat $ pidfile' | echo-n "not running"
- }
-
- D_reload (){
- Kill-HUP 'cat $ pidfile' | echo-n "can't reload"
- }
-
- Case "$1" in
- Start)
- Echo-n "Starting $ DESC: $ NAME"
- D_start
- Echo "."
- ;;
- Stop)
- Echo-n "Stopping $ DESC: $ NAME"
- D_stop
- Echo "."
- ;;
- Reload)
- Echo-n "Reloading $ DESC configuration ..."
- D_reload
- Echo "reloaded ."
- ;;
- Restart)
- Echo-n "Restarting $ DESC: $ NAME"
- D_stop
- Sleep 1
- D_start
- Echo "."
- ;;
- *)
- Echo "Usage: $ SCRIPTNAME {start | stop | restart | force-reload}"> & 2
- Exit 3
- ;;
- Esac
-
- 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