In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
First, prepare two nginx, two tomcat, and one mysql database, as follows
NginxIP address: 192.168.20.39 (lvs01)
192.168.20.40 (lvs02)
Drift address: 192.168.20.66
TomcatIP address: 192.168.20.41 (TM01)
192.168.20.42 (TM02)
MysqlIP address: 192.168.20.50
= 192.168.20.39 (lvs01) = =
Vi / usr/local/nginx/conf/nginx.conf
In http {
Include mime.types
Under default_type application/octet-stream;, remove #
Log_format main'$remote_addr-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent"$http_x_forwarded_for"'
Increase under gzip on
Include / usr/local/nginx/conf/conf.d/*.conf; # points to the subprofile
Cd / usr/local/nginx/conf/
Mkdir conf.d # create a subconfiguration folder
Cd conf.d/
Vi lvs01.conf
Server {
Listen 80
Server_name lvs01 192.168.20.39
Index index.html index.jsp
Root / usr/local/nginx/html
Access_log / usr/local/nginx/logs/tomcat.aa.com_access.log main
Location / {
Proxy_set_header HOST $host
Proxy_set_header X-Real-IP $remote_addr
Proxy_set_header Client-IP $remote_addr
Proxy_set_header X-For $proxy_add_x_forwarded_for
Proxy_pass http://center_pool; # sends all files to the tomcat server for processing
}
}
Vi pool.conf
Upstream center_pool {
Server 192.168.20.41:8080
Server 192.168.20.42:8080
Ip_hash; # stabilize ip session
}
Startup script
Vi / etc/init.d/nginx
#! / bin/bash
PROG= "/ usr/local/nginx/sbin/nginx"
PIDF= "/ usr/local/nginx/logs/nginx.pid"
Case "$1" in
Start)
$PROG
Stop)
Kill-s QUIT $(cat $PIDF)
Restart)
$0 stop
$0 start
Reload)
Kill-s HUP $(cat $PIDF)
*)
Echo "Usage: $0 {start | stop | restart | reload}"
Exit 1
Esac
Exit 0
Ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/
Chmod + x / etc/init.d/nginx
Chkconfig-add nginx
Nginx-t # checks whether the error is reported.
Service nginx start
Netstat-anpt | grep 80
-- deploy keepalived--
Yum-y install\
Popt-devel\
Kernel-devel\
Openssl-devel
Tar xvf keepalived-1.4.2.tar.gz
Cd keepalived-1.4.2
. / configure-- prefix=/
Make & & make install
Cp keepalived/etc/init.d/keepalived / etc/init.d/
Systemctl enable keepalived
Cd / etc/keepalived/
Vi keepalived.conf
! Configuration File for keepalived
Global_defs {
Route_id NGINX-01
}
Vrrp_script nginx {
Script "/ opt/nginx.sh"
Interval 2
Weight-10
}
Vrrp_instance VI_1 {
State MASTER # status is master
Interface ens33
Virtual_router_id 51
Priority 150 # priority is 150
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Nginx
}
Virtual_ipaddress {
192.168.20.66 # Drift address ip
}
}
Vi / opt/nginx.sh # script that turns nginx and keepalived on and off at the same time
#! / bin/bash
# Filename:nginx.sh
$(ps-ef | grep keepalived | grep-v grep | wc-l)
If [$A-gt 0]; then
/ etc/init.d/nginx start
Else
/ etc/init.d/nginx stop
Fi
Chmod + x / opt/nginx.sh
Systemctl start keepalived
-Test--
Systemctl stop keepalived
Killall-9 nginx (yum install psmisc-y)
Netstat-anpt | grep 80
Systemctl start keepalived
Netstat-anpt | grep 80
From this we can see that nginx can be turned on and off along with keepalived.
= 192.168.20.40 (lvs02) =
The main configuration file is the same as the primary server
Vi / usr/local/nginx/conf/nginx.conf
In http {
Include mime.types
Under default_type application/octet-stream;
Log_format main'$remote_addr-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent"$http_x_forwarded_for"'
Increase under gzip on
Include / usr/local/nginx/conf/conf.d/*.conf; # points to the subprofile
Cd / usr/local/nginx/conf/
Mkdir conf.d
Cd conf.d/
Vi lvs02.conf
Server {
Listen 80
Server_name lvs01 192.168.20.40
Index index.html index.jsp
Root / usr/local/nginx/html
Access_log / usr/local/nginx/logs/tomcat.aa.com_access.log main
Location / {
Proxy_set_header HOST $host
Proxy_set_header X-Real-IP $remote_addr
Proxy_set_header Client-IP $remote_addr
Proxy_set_header X-For $proxy_add_x_forwarded_for
Proxy_pass http://center_pool;
}
}
Vi pool.conf
Upstream center_pool {
Server 192.168.20.41:8080
Server 192.168.20.42:8080
Ip_hash
}
Vi / etc/init.d/nginx
#! / bin/bash
PROG= "/ usr/local/nginx/sbin/nginx"
PIDF= "/ usr/local/nginx/logs/nginx.pid"
Case "$1" in
Start)
$PROG
Stop)
Kill-s QUIT $(cat $PIDF)
Restart)
$0 stop
$0 start
Reload)
Kill-s HUP $(cat $PIDF)
*)
Echo "Usage: $0 {start | stop | restart | reload}"
Exit 1
Esac
Exit 0
Ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/
Chmod + x / etc/init.d/nginx
Chkconfig-add nginx
Nginx-t
Service nginx start
Netstat-anpt | grep 80
-deploy keepalived
Yum-y install popt-devel\
Kernel-devel\
Openssl-devel
Tar xvf keepalived-1.4.2.tar.gz
Cd keepalived-1.4.2
. / configure-- prefix=/
Make & & make install
Cp keepalived/etc/init.d/keepalived / etc/init.d/
Systemctl enable keepalived
Cd / etc/keepalived/
Vi keepalived.conf
! Configuration File for keepalived
Global_defs {
Route_id NGINX-02
}
Vrrp_script nginx {
Script "/ opt/nginx.sh"
Interval 2
Weight-10
}
Vrrp_instance VI_1 {
State BACKUP # status is backup
Interface ens33
Virtual_router_id 51
Priority 100 # priority is 100, so we can see that it is standby.
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
Track_script {
Nginx
}
Virtual_ipaddress {
192.168.20.66
}
}
Vi / opt/nginx.sh
#! / bin/bash
# Filename:nginx.sh
Avatar $(ip addr | grep 192.168.20.66 wc 32 | grep-v grep | wc-l)
If [$A-gt 0]; then
/ etc/init.d/nginx start
Else
/ etc/init.d/nginx stop
Fi
Chmod + x / opt/nginx.sh
Systemctl start keepalived
-- Test verification--
Ip addr show dev ens33 from server (192.168.20.40)
Then implement the failure (192.168.20.39) systemctl stop keepalived on the main server
Killall-9 nginx
After returning to the slave server (192.168.20.40) ip addr show dev ens33 (found that the drifting address is coming)
= = Database =
Mysql-u root-p
Create database slsaledb; # create a database
GRANT all ON slsaledb.* TO 'testuser'@'%' IDENTIFIED BY' admin123'
# Grant permissions
Flush privileges; # Refresh permissions
Quit
Mysql-u root-p
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: 0
*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.