1. Intallation HAProxy
2. Supptort proxy
pull/19/head
Aidaho12 2018-04-30 12:04:21 +06:00
parent a4b35b52d0
commit 329ed1beab
11 changed files with 128 additions and 18 deletions

View File

@ -52,12 +52,17 @@ For Apache do virtualhost with cgi-bin. Like this:
DocumentRoot /var/www/haproxy-wi
ScriptAlias /cgi-bin/ "/var/www/haproxy-wi/app/"
<Directory /var/www/haproxy-wi>
<Directory /var/www/haproxy-wi/app>
Options +ExecCGI
AddHandler cgi-script .py
Order deny,allow
Allow from all
</Directory>
<FilesMatch "\.config$">
Order Deny,Allow
Deny from all
</FilesMatch>
</VirtualHost>
```
# Database support
@ -77,7 +82,7 @@ MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIE
```
Edit $HOME_HAPROXY-WI/app/haproxy-webintarface.config with your env
```
Copy ssh key on all HAproxy servers
## Copy ssh key on all HAproxy servers, upload private key via Haproxy-WI in Admin area(Tab "SSH key" in "Servers" page), or sets root password in app/haproxy-webintarface.config.
Login http://haproxy-wi-server/users.py, and add: users, groups and servers. Default: admin/admin

View File

@ -17,6 +17,7 @@ form = cgi.FieldStorage()
serv = form.getvalue('serv')
fullpath = config.get('main', 'fullpath')
time_zone = config.get('main', 'time_zone')
proxy = config.get('main', 'proxy')
ssh_keys = config.get('ssh', 'ssh_keys')
ssh_user_name = config.get('ssh', 'ssh_user_name')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
@ -61,7 +62,6 @@ def telegram_send_mess(mess):
import telegram
token_bot = config.get('telegram', 'token')
channel_name = config.get('telegram', 'channel_name')
proxy = config.get('telegram', 'proxy')
if proxy is not None:
pp = telegram.utils.request.Request(proxy_url=proxy)
@ -181,6 +181,8 @@ def links():
'<li><a href=/app/add.py#backend title="Add single backend" class="add head-submenu">Add backend</a></li>'
'<li><a href=/app/add.py#ssl title="Upload SSL cert" class="cert head-submenu">SSL</a></li>'
'<li><a href=/app/config.py title="Edit Haproxy Config" class="edit head-submenu">Edit config</a> </li>')
if is_admin():
print('<li><a href=/app/ihap.py title="Installation HAProxy" class="hap head-submenu">Installation</a> </li>')
print('</li>')
if is_admin():
print('<li><a title="Keepalived" class="ha">Keepalived</a>'
@ -205,7 +207,7 @@ def links():
'</li>')
print('</ul>'
'</nav>'
'<div class="copyright-menu">HAproxy-WI v2.3</div>'
'<div class="copyright-menu">HAproxy-WI v2.3.1</div>'
'</div>')
def show_login_links():
@ -296,6 +298,7 @@ def get_auto_refresh(h2):
'</div>'
'</div>'
'</div>')
def ssh_connect(serv):
ssh = SSHClient()
ssh.load_system_host_keys()
@ -309,12 +312,16 @@ def ssh_connect(serv):
return ssh
except paramiko.AuthenticationException:
print('<div class="alert alert-danger">Authentication failed, please verify your credentials</div>')
return False
except paramiko.SSHException as sshException:
print('<div class="alert alert-danger">Unable to establish SSH connection: %s </div>' % sshException)
return False
except paramiko.BadHostKeyException as badHostKeyException:
print('<div class="alert alert-danger">Unable to verify server\'s host key: %s </div>' % badHostKeyException)
return False
except Exception as e:
print('<div class="alert alert-danger">{}</div>'.format(e.args))
return False
def get_config(serv, cfg, **kwargs):
if kwargs.get("keepalived"):
@ -381,7 +388,11 @@ def show_config(cfg):
def install_haproxy(serv):
script = "install_haproxy.sh"
os.system("cp scripts/%s ." % script)
commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script ]
if proxy is not None:
proxy_serv = proxy
else:
proxy_serv = ""
commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script +" " + proxy_serv]
upload(serv, tmp_config_path, script)
ssh_command(serv, commands)

View File

@ -5,6 +5,7 @@ cgi_path = ${fullpath}/app/
log_path = ${fullpath}/log/
cert_local_dir = ${cgi_path}/certs/
time_zone = UTC
proxy =
[configs]
#Server for save configs from HAproxy servers
@ -43,7 +44,6 @@ syslog_server =
enable = 0
token =
channel_name =
proxy =
[haproxy]
#Command for restart HAproxy service

40
app/ihap.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
import html
import cgi
import funct
import sql
from configparser import ConfigParser, ExtendedInterpolation
funct.head("Installation HAProxy")
funct.check_login()
funct.page_for_admin()
path_config = "haproxy-webintarface.config"
config = ConfigParser(interpolation=ExtendedInterpolation())
config.read(path_config)
proxy = config.get('main', 'proxy')
serv = ""
print('<script src="/inc/users.js"></script>'
'<h2>Installation HAProxy</h2>'
'<table class="overview">'
'<tr class="overviewHead">'
'<td class="padding10 first-collumn">Note</td>'
'<td>Server</td>'
'<td></td>'
'</tr>'
'<tr>'
'<td class="padding10 first-collumn">'
'<b>Haproxy-WI will try install haproxy-1.18.5, if it does not work then haproxy-1.15</b>'
'</td>'
'<td class="padding10 first-collumn">'
'<select id="haproxyaddserv">'
'<option disable selected>Choose master</option>')
funct.choose_only_select(serv)
print('</select>'
'</td>'
'<td>'
'<a class="ui-button ui-widget ui-corner-all" id="install" title="Install HAProxy">Install</a>'
'</td>'
'</table>'
'<div id="ajax"></div>')

View File

@ -270,4 +270,7 @@ if form.getvalue('masteradd'):
commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script+" BACKUP "+interface+" "+vrrpip+" "+kp ]
funct.ssh_command(slave, commands)
os.system("rm -f %s" % script)
os.system("rm -f %s" % script)
if form.getvalue('haproxyaddserv'):
funct.install_haproxy(form.getvalue('haproxyaddserv'))

View File

@ -1,10 +1,29 @@
#!/bin/bash
yum install haproxy socat -y > /dev/null
if [[ $1 != "" ]]
then
export http_proxy="$1"
export https_proxy="$1"
echo "Exporting proxy"
fi
if [ -f /etc/haproxy/haproxy.cfg ];then
echo -e 'error: Haproxy alredy installed. You can edit config<a href="/app/config.py" title="Edit HAProxy config">here</a>'
exit 1
fi
wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
yum install haproxy18-1.8.1-5.el7.x86_64.rpm -y
if [ $? -eq 1 ]
then
yum install wget socat -y > /dev/null
wget http://cbs.centos.org/kojifiles/packages/haproxy/1.8.1/5.el7/x86_64/haproxy18-1.8.1-5.el7.x86_64.rpm
yum install haproxy18-1.8.1-5.el7.x86_64.rpm -y
fi
if [ $? -eq 1 ]
then
yum install haproxy socat -y > /dev/null
fi
echo "" > /etc/haproxy/haproxy.cfg
cat << EOF > /etc/haproxy/haproxy.cfg
global
@ -37,7 +56,8 @@ defaults
timeout check 10s
maxconn 3000
listen stats *:8085
listen stats
bind *:8085
stats enable
stats uri /stats
stats realm HAProxy-04\ Statistics
@ -59,6 +79,7 @@ systemctl restart haproxy
if [ $? -eq 1 ]
then
echo "Can't start Haproxy service"
echo "error: Can't start Haproxy service"
exit 1
fi
fi
echo "success"

View File

@ -8,8 +8,9 @@ fi
yum install keepalived -y > /dev/null
if [ $? -eq 1 ]
then
exit 1
then
echo "error: Can't install keepalived"
exit 1
fi
echo "" > $CONF
@ -48,7 +49,7 @@ vrrp_instance VI_1 {
EOF
if [ $? -eq 1 ]
then
echo "Can't read keepalived config"
echo "error: Can't read keepalived config"
exit 1
fi
sed -i "s/MASTER/$1/g" $CONF
@ -69,6 +70,6 @@ firewall-cmd --reload
if [ $? -eq 1 ]
then
echo "Can't start keepalived"
echo "error: Can't start keepalived"
exit 1
fi

View File

@ -503,7 +503,7 @@ if form.getvalue('newserver') is not None:
print('Content-type: text/html\n')
if add_server(hostname, ip, group, typeip, enable, master):
show_update_server(hostname)
if form.getvalue('serverdel') is not None:
print('Content-type: text/html\n')
if delete_server(form.getvalue('serverdel')):

View File

@ -66,6 +66,11 @@
font-family: "Font Awesome 5 Solid";
content: "\f044";
}
.hap::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f074";
}
.ha::before {
display: none;
font-family: "Font Awesome 5 Solid";

View File

@ -88,6 +88,25 @@ $( function() {
} );
}
});
$('#install').click(function() {
$("#ajax").html('')
$.ajax( {
url: "options.py",
data: {
haproxyaddserv: $('#haproxyaddserv').val(),
},
type: "GET",
success: function( data ) {
data = data.replace(/\s+/g,' ');
if (data.indexOf('error') != '-1' || data.indexOf('alert') != '-1' || data.indexOf('Failed') != '-1') {
$("#ajax").html('<div class="alert alert-danger">'+data+'</data>');
} else if (data.indexOf('success') != '-1' ){
$('.alert-danger').remove();
$("#ajax").html('<div class="alert alert-success">'+data+'</data>');
}
}
} );
});
$('.alert-danger').remove();
$('#add-user').click(function() {

View File

@ -107,15 +107,20 @@ cat << EOF > /etc/httpd/conf.d/haproxy-wi.conf
CustomLog /var/log/httpd/haproxy-wi.access.log combined
DocumentRoot /var/www/$HOME_HAPROXY_WI
ScriptAlias "/cgi-bin/ "/var/www/$HOME_HAPROXY_WI/app/"
ScriptAlias /cgi-bin/ "/var/www/$HOME_HAPROXY_WI/app/"
<Directory $HOME_HAPROXY_WI>
<Directory /var/www/$HOME_HAPROXY_WI/app>
Options +ExecCGI
AddHandler cgi-script .py
Order deny,allow
Allow from all
</Directory>
<FilesMatch "\.config$">
Order Deny,Allow
Deny from all
</FilesMatch>
</VirtualHost>
EOF