Lab Environment:
NGINX CentOS 7.2x86_64 ip:172.16.253.94 192.168.1.10
RealServer1 CentOS 6.7x86_64 ip:192.168.1.20
RealServer2 CentOS 7.2x86_64 ip:192.168.1.30
Client RHEL5.5 ip:172.16.251.75
RealServer1:
[Email protected] ~]# iptables-f
[Email protected] ~]# Setenforce 0
[[email protected] ~]# yum-y install httpd php php-mysql mysql-server
[Email protected] ~]# service httpd restart
[[Email protected] ~]# service httpd MySQL
[Email protected] ~]# echo "RealServer1" >>/var/www/html/index.html
RealServer2:
[Email protected] ~]# iptables-f
[Email protected] ~]# Setenforce 0
[[email protected] ~]# yum-y install httpd php php-mysql mariadb-server
[Email protected] ~]# systemctl start Httpd.service mariadb.service
[Email protected] ~]# echo "RealServer2" >>/var/www/html/index.html
Load Balancer httpd:
1. Install Nginx:
[Email protected] ~]# iptables-f
[Email protected] ~]# Setenforce 0
[Email protected] ~]# yum-y install nginx-1.10.1-1.el7.ngx.x86_64.rpm
[Email protected] ~]# RPM-QL Nginx
2. Start the service:
[Email protected] ~]# nginx-t
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configuration file/etc/nginx/nginx.conf Test is successful
[Email protected] ~]# Nginx
[Email protected] ~]# SS-TNL
State recv-q send-q Local address:port Peer address:port
LISTEN 0 *:80 *:*
3. Define Upstream Load Balancing:
[[Email protected]]# vim/etc/nginx/nginx.conf
HTTP {
Omit part ...
Upstream websrvs{
Server 192.168.1.20;
Server 192.168.1.30;
}
Omit part ...
}
4. Call the Upstream module:
[[Email protected]]# vim/etc/nginx/conf.d/default.conf
server {
Omit part ...
Location/{
root/usr/share/nginx/html;
Index index.html index.htm;
Proxy_pass Http://websrvs;
}
Omit part ...
}
5. Client Test: (Default polling algorithm)
[[Email protected]~]# for i in {1..10}; Do Curl http://172.16.253.94; Done
Realserver 1
Realserver 2
Realserver 1
Realserver 2
Realserver 1
Realserver 2
Realserver 1
Realserver 2
Realserver 1
Realserver 2
6. Configure the Scheduler algorithm:
[[Email protected]]# vim/etc/nginx/nginx.conf
HTTP {
Omit part ...
Upstream websrvs{
Server 192.168.1.20;
Server 192.168.1.30;
Hash $request _uri consistent; Consistent hash algorithm: Send the same URL request to the same realserver
}
Omit part ...
}
7. Test the consistency hash algorithm:
[[Email protected]~]# for i in {1..10}; Do Curl http://172.16.253.94/; Done
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Realserver 1
Load Balancer SSH Service:
[[Email protected]]# vim/etc/nginx/nginx.conf
stream{
Upstream sshsrvs{
Server 192.168.1.20:22;
Server 192.168.1.30:22;
}
server {
Listen 172.16.253.94:22202;
Proxy_pass Sshsrvs;
}
}
[[email protected]] #nginx-S stop
[[email protected]] #nginx
Client Remote login:
Ssh-p 22202 [email protected]
Memcached Cache Service:
[[Email protected] ~] #yum-y install memcached
[[Email protected] ~] #rpm-ql memcache
[[Email protected] ~] #cat/etc/sysconfig/memcached
Port= "11211"
User= "Memcached"
maxconn= "1024"
Cachesize= "64"
Options= ""
[[Email protected] ~] #ss-TNL
State recv-q send-q Local address:port Peer address:port
LISTEN 0 *:11211 *:*
memcahed Simple configuration:
[[Email protected]~]# telnet 172.16.253.94 11211
Trying172.16.253.94 ...
Connected topxe94.magelinux.com (172.16.253.94).
Escape characteris ' ^] '.
Command:
Statistics classes: stats, stats items, stats slabs, stats sizes
Storage classes: Set, add, replace, append, prepend
Get data classes: Get, delete, INCR/DECR
Empty: Flush_all
Common options:
-M<NUM>: Cache space size in MB, default 64
-c<num>: Concurrent connection, default is 1024
-U USERNAME: Program runner
-P Port: Listening TCP port
-U port: Listening UDP port
-l <IP_ADDR>: IP address of the listener
-M: An error message is returned to the request store cache entry when the cache is exhausted
-f<factor>:chunk size growth factor
-t<num>: Number of threads, default = 4
Nginx Load Balancer-memcached Cache service