Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Experimental keepalived+nginx+apache+mysql how to achieve High availability load balancing part 2

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following is an experiment on how to achieve high-availability load balancing with keepalived+nginx+apache+mysql. I hope it can give you some help in practical application. There are many things involved in load balancing, not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

Introduction of the environment

Hostname ip installation software nginx_mysql_m192.168.255.67keepalived+nginxnginx_mysql_s192.168.255.66keepalived+nginxmysql1192.168.255.52mysql, mysql-servermysql2192.168.255.57mysql, mysql-server

II. Keepalived configuration

The configuration of keepalived is similar to that of the previous article.

Vim / etc/keepalived/keepalived.conf

! Configuration File for keepalived

Global_defs {notification_email {root@localhost} notification_email_from keepalived@localhostsmtp_server 127.0.0.1smtp_connect_timeout 30router_id nginx_mysql_svrrp_skip_check_adv_addr#vrrp_strictvrrp_garp_interval 0vrrp_gna_interval 0} vrrp_script chk_nginx {script "/ etc/keepalived/nginx_check.sh" # script to check the status of nginx interval 2weight 3} vrrp_instance VI_1 {state BACKUPinterface ens160virtual_router_id 66priority 100 # backup Advert_int 1authentication {auth_type PASSauth_pass 1111} virtual_ipaddress {192.168.255.200} track_script {chk_nginx}}

III. Configuration of nginx

Because nginx listens on port 3306 and does not need web service, the configuration file is relatively simple, but the stream module is needed.

You need to add-- with--stream when configuring

/ configure-add-module=../ngx_cache_purge-2.3-prefix=/usr/local/nginx-with-http_ssl_module-with-stream-with-pcre=../pcre-8.41-with-zlib=../zlib-1.2.11-with-openssl=../openssl-1.0.2o

Other installation methods are the same as those in the previous article

Modify nginx configuration file

# user nobody

Worker_processes 1

# error_log logs/error.log

# error_log logs/error.log notice

# error_log logs/error.log info

# pid logs/nginx.pid

Events {

Worker_connections 1024

}

Stream {

Upstream mysql {

Server 192.168.255.52 server 3306 weight=5 max_fails=3 fail_timeout=30s; server 192.168.255.57 weight=5 max_fails=3 fail_timeout=30s;} server {listen 3306; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass mysql;}

}

Start nginx

/ usr/local/nginx/sbin/nginx

Netstat-napt

It is found that nginx has been successfully monitored.

Backup has the same nginx configuration

IV. Mysql database configuration

Next is the highlight, the mysql master configuration.

1 mysql installation

Wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Mv http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm / etc/yum.repo/

Rpm-ivh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Yum install-y mysql&&yum install mysql-server-y

Systemctl start mysql

First, we configure the mysql dual master model to synchronize its data.

Vim / etc.my.cnfserver-id=1log-bin=mysql-binbinlog_format=mixedrelay-log=relay-binrelay-log-index=slave-relay-bin.indexauto-increment-increment=2auto-increment-offset=1log-slave-updates

What needs to be added to the history of the red box?

There are two different mysql in the powder box.

The pink frame of mysql2 is 2.

Then restart mysql

Systemctl restart mysql

Mysql

Mysql > grant all privileges on. To zhangsan@192.168.255.53 identified by '123456'

Change ip to mysql1 on mysql2

The remaining steps were found in the last blog mysql data asynchrony, so I won't talk about it here.

We authorize the web CVM to perform all operations.

Mysqlmysql > create database db_jd;mysql > create user web@localhost identified by '123456employees make sure MySQL > grant all privileges on *. * to web@localhost;mysql > create user web@192.168.255.50 identified by' 123456questions make MySQL > create user web@192.168.255.53 identified by '123456problems make MySQL > grant all privileges on db_jd.* to web@192.168.255.50;mysql > grant all privileges on db_jd.* to web@192.168.255.53;mysql > flush privileges

Then use php to connect to mysql on the web server to see if it is successful

> cd / var/www/htmlvim con.php

Vim index.php

Product addition-JD product management system JD product management book name: sales price: market price:

Vim deal.php

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report