In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Redis cache server
Redis is a key-value storage system. Similar to Memcached, it supports relatively more value types of storage, including
String (string), list (linked list), set (collection), zset (sorted set-ordered set), and hash (hash type).
1. Redis not only supports simple KBH data, but also provides storage of data structures such as list,set,zset,hash.
2. Redis supports data backup, that is, data backup in master-slave mode.
3. Redis supports data persistence. You can keep the data in memory on disk and load it again when you restart it.
Nginx+tomcat+redis implements load balancing and session sharing
1. Install and deploy nginx load balancer server
Install dependent packages such as zlib-devel, pcre-devel, etc.
[root@www ~] # yum-y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel openssl openssl-devel
Note:
Implementation of back-end web load balancing with proxy and upstream Modules
After combining the default ngx_http_proxy_module module and ngx_http_upstream_module module of nginx
Health check of end server
Create a nginx program user
[root@www] # useradd-s / sbin/nologin www
Compile and install nginx
[root@www ~] # tar zxf nginx-1.10.2.tar.gz
[root@www ~] # cd nginx-1.10.2/
[root@www nginx-1.10.2] # / configure-- prefix=/usr/local/nginx1.10-- user=www-- group=www-- with-http_stub_status_module-- with-http_realip_module-- with-http_ssl_module-- with-http_gzip_static_module-- with-pcre-- with-http_flv_module
[root@www nginx-1.10.2] # make & & make install
Optimize the execution path of nginx programs
[root@www nginx-1.10.2] # ln-s / usr/local/nginx1.10/sbin/nginx / usr/local/sbin/
[root@www nginx-1.10.2] # nginx- t
Nginx: the configuration file / usr/local/nginx1.10/conf/nginx.conf syntax is ok
Nginx: configuration file / usr/local/nginx1.10/conf/nginx.conf test is successful
Write a script for nginx service: the script is as follows:
Just copy it in.
[root@www ~] # cat / etc/init.d/nginx
#! / bin/bash# nginx Startup script for the Nginx HTTP Server# chkconfig:-85 nginx pidfile: / usr/local/nginx1.10/logs/nginx.pid# config: / usr/local/nginx1.10/conf/nginx.confnginxd=/usr/local/nginx1.10/sbin/nginxnginx_config=/usr/local/nginx1.10/conf/nginx.confnginx_pid=/usr/local/nginx1.10/logs/nginx.pidRETVAL=0prog= "nginx" # Source function library.. / etc/rc.d/init.d/functions# Start nginx daemons functions.start () {if [- f $nginx_pid] Thenecho "nginx already running...." exit 1fiecho-n "Starting $prog:" $nginxd-c ${nginx_config} RETVAL=$? [$RETVAL= 0] & & touch / var/lock/subsys/nginx} # Stop nginx daemons functions.stop () {echo-n "Stopping $prog:" $nginxd-s stop RETVAL=$? [$RETVAL= 0] & & rm-f / var/lock/subsys/nginx} # reloadnginx service functions.reload () {echo-n "Reloading $prog:" $nginxd-s reload} # Statusngnx service functionsstatus () {if [- f $nginx_pid] Thenecho "$prog is running" elseecho "$prog is stop" fi} case "$1" instart) start;; stop) stop;; reload) reload;; restart) stopstart;; status) status;; *) echo "Usage: $prog {start | stop | restart | reload | status}" exit 1;; esac
[root@www ~] # chmod + x / etc/init.d/nginx
[root@www] # chkconfig-- add nginx
[root@www ~] # chk config nginx on
[root@www ~] # systemctl daemon-reload
Configure nginx reverse proxy: reverse proxy + load balancer + health probe, nginx.conf file content:
[root@www ~] # cat / usr/local/nginx1.10/conf/nginx.conf
User www www;worker_processes 4 workerboards logs/nginx.pid;events 0001 0010 0100 1000 http include mime.types;default_type application/octet-stream log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;worker_rlimit_nofile 10240 host pid {workers 4096;} 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 logs/access.log main;server_tokens off;sendfile on;tcp_nopush on; # keepalive_timeout 0 http_x_forwarded_for keepalivetimeout 65; # Compression Settingsgzip on;gzip_comp_level 6 × gzipkeeper httpmakers version 1.1 Gzip_buffers 168kdomestic buffermakers types text/plain text/css text/javascript application/json application/javascriptapplication/x-javascript application/xml;gzip_vary on; # end gzip # http_proxy Settingsclient_max_body_size 10mThe clientbreakbodybufferplates size 128kms proxyconversation connectbacks timeout 75 proxybirthday timeouts 75proxybirthday buffers timeouts 75proxybirthday buffers 4kproxychips buffers 4 32kparts bus buffersboxes size 64k # load balance Settingsupstream backend_tomcat {server 192.168.31.83 server 8080 weight=1 max_fails=2 fail_timeout=10s; # to change server 192.168.31.250 server 8080 weight=1 max_fails=2 fail_timeout=10s; # to change # virtual host Settingsserver {listen 80 serverSecretname www.benet.com;charset utf-8;location / {root html;index index.jsp index.html index.htm;} location ~. (jsp | do) ${proxy_pass http://backend_tomcat; Proxy_redirect off; 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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;} location / nginxstatus {stub_status on; access_log off Allow 192.168.1.0 allow 24; # to change deny all;}
Restart the nginx service for the changes to take effect
[root@www ~] # service nginx restart
Configure firewall gauge to allow tcp/80 port to go out
[root@www] # firewall-cmd-- permanent-- add-port=80/tcp
Success
[root@www] # firewall-cmd-- reload
Success
2. Install and deploy the tomcat application server
Install JDK on the tomcat-1 and tomcat-2 nodes
Before installing tomcat, you must install JDK,JDK. The full name of JDK,JDK is java development kit, which is free of charge by sun.
For the java language software development kit, which contains the java virtual machine (JVM), the written java source program
Compilation can form java bytecode, and as long as JDK is installed, you can use JVM to interpret these bytecode files, thus ensuring that
The cross-platform nature of java.
Install JDK and configure the java environment:
Decompress jdk-7u65-linux-x64.gz
[root@tomcat-1 ~] # tar zxf jdk-7u65-linux-x64.gz
Move the extracted jdk1.7.065 directory to / usr/local/ and rename it to java
[root@tomcat-1 ~] # mv jdk1.7.065/ / usr/local/java
Add the following to the / etc/profile file:
Export JAVAHOME=/usr/local/java
Export PATH=$JAVAHOME/bin:$PATH
Execute the profile file through the source command to make it effective.
[root@tomcat-1 ~] # source / etc/profile
[root@tomcat-1 ~] # echo $PATH
/ usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
Install JDK on tomcat-2 in the same way
Run the java-version command on the tomcat-1 and tomcat-2 nodes respectively to see if the java version is the same as the previously installed
Consistent.
[root@tomcat-1 ~] # java-version
Java version "1.7.065"
Java (TM) SE Runtime Environment (build 1.7.065-b17)
Java HotSpot (TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
So far, the java environment has been configured
Install and configure tomcat on tomcat-1 and tomcat-2 nodes
Extract the apache-tomcat-7.0.54.tar.gz package
[root@tomcat-1 ~] # tar zxf apache-tomcat-7.0.54.tar.gz
Move the extracted folder to / usr/local/ and rename it to tomcat7
[root@tomcat-1 ~] # mv apache-tomcat-7.0.54 / usr/local/tomcat7
Configure tomcat environment variables
The content of / etc/profile file is as follows:
Export JAVAHOME=/usr/local/java
Export CATALINAHOME=/usr/local/tomcat7
Export PATH=$JAVAHOME/bin:$CATALINAHOME/bin:$PATH
Execute the profile file through the source command to make it effective.
[root@tomcat-1 ~] # source / etc/profile
[root@tomcat-1 ~] # echo $PATH
/ usr/local/java/bin:/usr/local/tomcat7/bin:/usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/
Bin:/root/bin
View the version information of tomcat
[root@tomcat-1 ~] # catalina.sh version
Using CATALINABASE: / usr/local/tomcat7
Using CATALINAHOME: / usr/local/tomcat7
Using CATALINATMPDIR: / usr/local/tomcat7/temp
Using JREHOME: / usr/local/java
Using CLASSPATH: / usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.54
Server built: May 19 2014 10:26:15
Server number: 7.0.54.0
OS Name: Linux
OS Version: 3.10.0-327.el7.x8664
Architecture: amd64
JVM Version: 1.7.065-b17
JVM Vendor: Oracle Corporation
Start tomcat
[root@tomcat-1 ~] # / usr/local/tomcat7/bin/startup.sh
Using CATALINABASE: / usr/local/tomcat7
Using CATALINAHOME: / usr/local/tomcat7
Using CATALINATMPDIR: / usr/local/tomcat7/temp
Using JREHOME: / usr/local/java
Using CLASSPATH: / usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.
Tomcat runs on port 8080 by default. Run the netstat command to view the listening information of port 8080.
[root@tomcat-1 ~] # netstat-anpt | grep java
Tcp6 00: 8009: LISTEN 42330/java
Tcp6 0 0: 8080: LISTEN 42330/java
Firewall rule configuration:
[root@tomcat-1] # firewall-cmd-- permanent-- add-port=8080/tcp
Success
[root@tomcat-1] # firewall-cmd-- reload
Success
Install it in tomcat-2 in the same way
Open the browser to test the access to tomcat-1 and tomcat-2 respectively
Run the / usr/local/tomcat7/bin/shutdown.sh command if you want to shut down tomcat
All right, you can see the success of the visit. Our tomcat installation is complete. Let's modify the configuration file.
[root@tomcat-1 ~] # vim / usr/local/tomcat7/conf/server.xml
Set the default virtual host and add jvmRoute*
Modify the default virtual host, point the path of the website file to / web/webapp1, and add the context segment to the host section
Add document directory and test files
[root@tomcat-1] # mkdir-p / web/webapp1
[root@tomcat-1 ~] # cd / web/webapp1/
[root@ tomcat-1 webapp1] # vi index.jsp
The index.jsp content is as follows:
Tomcat-1Session serviced by tomcatSession IDCreated on
Stop tomcat, check the configuration file, and start tomcat
[root@tomcat-1 ~] # shutdown.sh
[root@tomcat-1 ~] # netstat-anpt | grep java
[root@tomcat-1 ~] # catalina.sh configtest
Using CATALINA_BASE: / usr/local/tomcat7
Using CATALINA_HOME: / usr/local/tomcat7
Using CATALINA_TMPDIR: / usr/local/tomcat7/temp
Using JRE_HOME: / usr/local/java
Using CLASSPATH: / usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Nov 16, 2016 1:04:05 AM org.apache.catalina.core.AprLifecycleListenerinit
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production
Environments was not found on the java.library.path:
/ usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Nov 16, 2016 1:04:05 AM org.apache.coyote.AbstractProtocolinit
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Nov 16, 2016 1:04:05 AM org.apache.coyote.AbstractProtocolinit
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Nov 16, 2016 1:04:05 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 534 ms
[root@tomcat-1 ~] # startup.sh
Using CATALINA_BASE: / usr/local/tomcat7
Using CATALINA_HOME: / usr/local/tomcat7
Using CATALINA_TMPDIR: / usr/local/tomcat7/temp
Using JRE_HOME: / usr/local/java
Using CLASSPATH: / usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat-1 ~] # netstat-anpt | grep java
Tcp6 00: 8009: LISTEN 8180/java
Tcp6 0 0: 8080: LISTEN 8180/java
The configuration of the Tomcat-2 node is basically similar to that of the tomcat-1 node, except that the jvmRoute is different, and in order to distinguish which node
Provide access, and the test page title is different (the web content provided by the two tomcat servers in the production environment is the same). Its
His configuration is all the same.
Access the nginx host with a browser to verify load balancing
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 263
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.