Haproxy Agent MySQL Service

Source: Internet
Author: User

-----client---------haproxy-------MYSQL1---------mysql2------

192.168.1.250 192.168.1.1 192.168.1.10 192.168.1.20

First, install MySQL

[[Email protected] ~] #tar-ZXVF bison-2.5.tar.gz

[Email protected] ~]#./configure && make&& make install

[[Email protected] ~] #tar-ZXVF cmake-2.8.7.tar.gz

[Email protected] ~]#./bootstrap && gmake && gmake Install

[[Email protected] ~] #tar-ZXVF mysql-5.5.22.tar.gz

[[Email protected] ~] #cmake-dcmake_install_prefix=/usr/local/mysql-

dsysconfdir=/etc/-ddefault_charset=utf8-

Ddefault_collation=utf8_general_ci-dwith_extra_charsets=all

[[Email protected] ~] #make && make install

Initialize MySQL:

[email protected] ~]# CP support-files/my-medium.cnf/etc/my.cnf

[Email protected]st ~]# CD Scripts

[Email protected] ~]#/mysql_install_db--basedir=/usr/local/mysql/--

datadir=/usr/local/mysql/data/--user=mysql

[email protected] ~]# CP. /support-files/mysql.server/etc/init.d/mysqld

[Email protected] ~]# ln-s/usr/local/mysql/bin/*/usr/local/bin/

[Email protected] ~]# mysqladmin-u root password ' redhat '

Login test:

[Email protected] ~]# mysql-u root-p

To create a database:

[Email protected] ~]# mysql> createdata Server1;

Of course you can also install MySQL using yum

[[email protected] ~]# yum-y install MySQL mysql-devel mysql-server

Second, installation Haproxy

1. Installation

[Email protected] ~]# yum-y install Pcre-devel zlib-devel

[Email protected] ~]# TAR-ZXVF haproxy-1.4.24.tar.gz-c/usr/src/

[Email protected] ~]# cd/usr/src/haproxy-1.4.24/

[email protected] ~]# make target=linux26 prefix=/usr/local/haproxy

Note: Linux26 refers to the kernel version number of Linux.

[[email protected] ~]# make install Prefix=/usr/local/haproxy

2, Configuration Haproxy

[Email protected] ~]# Mkdir/etc/haproxy

[Email protected] ~]# cp/usr/src/haproxy-1.4.24/examples/haproxy.cfg/etc/haproxy/

[Email protected] ~]# vim/etc/haproxy/haproxy.cfg

Modify:

Global

Log 127.0.0.1 local0//configuration logging, local0 to log device, default to System log

Log 127.0.0.1 local1 Notice//notice is logging level, usually with 7 levels

#log Loghost local0 Info

Maxconn 4096//default maximum connection number, consider Ulimit-n limit: can increase ulimitn

819200 limit of the number of #ulimit

Chroot/usr/share/haproxy//Run path

UID 99

GID 99

#debug

#quiet

Defaults

Log global//define logs as logs in global

Mode TCP//pattern is four layer

Option Tcplog//log format with HTTP

Option Dontlognull//Do not record health check log information

Retries 3//Three connection failure is considered to be the server is not available, can also be set by the following

#redispatch

Maxconn 2000//Maximum number of connections

Contimeout 5000//Connection time-out

Clitimeout 50000//Client time-out

Srvtimeout 50000//service-time timeout

Listen stats

Mode http

bind:6677

Stats enable

Stats Hide-version

Stats Uri/haproxyadmin?stats

Stats Realm Haproxy\ Statistics

Stats Auth Admin:admin

Stats Admin If TRUE

Listen Mysqlcluster 0.0.0.0:3306

Balance Roundrobin

Server M1 192.168.56.202:3306 Check Port 3306 maxconn 300

Server M2 192.168.56.203:3306 Check port 3306 maxconn 300

Attention:

If an error occurs when booting:/haproxy.main ()] cannot chroot (/usr/share/haproxy)

is created manually:

[Email protected] ~]# Mkdir/usr/share/haproxy

If an error occurs when booting: Starting proxy cacti:cannot bind socket

Then execute:

[Email protected] ~]# SYSCTL-E net.ipv4.ip_nonlocal_bind=1

3. Start Haproxy

[Email protected] ~]# ln-s/usr/local/haproxy/sbin/*/usr/sbin///Note the directory of soft links

[Email protected] ~]# Cp/usr/src/haproxy-1.4.24/examples/haproxy.init

/etc/init.d/haproxy

[Email protected] ~]# chmod +x/etc/init.d/haproxy

[[email protected] ~]#/etc/init.d/haproxy start

[Email protected] ~]#/etc/init.d/haproxy status

[Email protected] ~]# NETSTAT-ANP | grep haproxy//uses TCP port 80

[Email protected] ~]# chkconfig--add haproxy

[Email protected] ~]# chkconfig haproxy on

Http://192.168.56.200:6677/haproxyadmin?stats viewing the status of a cluster

Iv. MySQL Authorized user login (MySQL in the cluster to authorize)

Mysql> GRANT All on * * to ' root ' @ ' 192.168.56.% ' identified by ' Redhat ';

mysql> flush Privileges;

Five, test:

[Email protected] ~]# mysql-u root-h 192.168.56.200-p

Log in two times to view each

can increase keepalived


This article is from the "11000174" blog, please be sure to keep this source http://11010174.blog.51cto.com/11000174/1890829

Haproxy Agent MySQL Service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.