-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfig_MaxScale.py
157 lines (104 loc) · 4.86 KB
/
config_MaxScale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python3.6
import os,sys,time,fileinput
print('Disable firewalld\n')
os.system('systemctl stop firewalld')
os.system('systemctl disable firewalld')
with fileinput.FileInput('/etc/selinux/sql', inplace=True,backup='.bak') as f1:
for line in f1:
print(line.replace('SELINUX=enforcing','SELINUX=disabled'),end='')
f1.close()
############################################################################# get ip
# ip_ = os.popen("ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\\2/p'").read().split('\n')
# ip_server = ip_[0]
############################################################################## get netmask
net = os.popen("ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,\"0/\",$4);print $4}'").read().split('\n')
net_ = net[0]
netmask = net_.split('/')[-1]
################################################################################ list interfaces
inf_ = os.popen('ls /sys/class/net/').read().split()
print('\nYour interfaces: '+str(inf_)+'\n')
inf = (inf_[0])
############################################################################### get gateway
gw = os.popen("ip route |grep default | awk '{print $3}'").read()
print('Config network.')
time.sleep(2)
n = ''
while n != 'c':
print('\n+ {:-<6} + {:-^15} + '.format('',''))
print('| {:<20} | '.format('please enter your option'.title()))
print('| {:<24} | '.format('[1]enter 1 default '))
print('| {:<25} | '.format('[2]enter 2 to modify '))
print('| {:<25} | '.format('[c]enter C to continue '))
print('+ {:-<6} + {:-^15} + '.format('',''))
n = input('\nEnter option: '.title())
if n == '1':
with fileinput.FileInput('/etc/sysconfig/network-scripts/ifcfg-'+inf, inplace=True) as f:
for line in f:
print(line.replace('BOOTPROTO="dhcp"','BOOTPROTO=static'),end='')
f.close()
with open('/etc/sysconfig/network-scripts/ifcfg-'+inf, 'a+') as f1:
f1.write('\nIPADDR=' + ip_server)
f1.write('\nFREFIX=' + netmask)
f1.write('\nGATEWAY=' + gw)
f1.write('\nDNS1='+ gw)
f1.write('\nDNS2=8.8.8.8')
f1.close()
os.system('systemctl restart network')
print('Config network done!!! Plz hit C to continue'.title())
elif n == '2':
name_inf = input('Enter name inteface: ')
ip = input('Enter ip your server: ')
print('Example Enter Netmask: 8 16 24')
netmask = input('Enter Netmask: ')
with fileinput.FileInput('/etc/sysconfig/network-scripts/ifcfg-'+name_inf, inplace=True) as f:
for line in f:
print(line.replace('BOOTPROTO="dhcp"','BOOTPROTO=static'),end='')
f.close()
with open('/etc/sysconfig/network-scripts/ifcfg-'+name_inf, 'a+') as f1:
f1.write('\nIPADDR=' + ip)
f1.write('\nFREFIX=' + netmask)
f1.write('\nGATEWAY=' + gw)
f1.write('\nDNS1='+ gw)
f1.write('\nDNS2=8.8.8.8')
f1.close()
os.system('systemctl restart network')
print('Config network done!!! Plz hit C to continue'.title())
elif n == 'c':
break
else:
print("\n\ti don't know your option!!!,".title(),'Please enter try!!!'.upper())
############################################################################ Install && sql Max_Scale
print('\nBegin install Maxscale and Mariadb-client\n')
os.system('curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash')
os.system('yum -y install maxscale MariaDB-client ')
os.system('cp /root/maxscale.cnf /etc/')
server1 = input('Enter ip server1: ')
server2 = input('Enter ip server2: ')
server3 = input('Enter ip server3: ')
ip_server = input('Enter ip maxscale: ')
user = input('Enter user cluster: ')
passw = input('Enter password user cluster: ')
print('edit file maxscale.cnf')
time.sleep(2)
with open('/etc/maxscale.cnf', 'r') as f:
newtext = f.read()
while 'ddress=server1' in newtext:
newtext=newtext.replace('ddress=server1','ddress='+server1)
while 'ddress=server2' in newtext:
newtext=newtext.replace('ddress=server2','ddress='+server2)
while 'ddress=server3' in newtext:
newtext =newtext.replace('ddress=server3','ddress='+server3)
while 'user=myuser' in newtext:
newtext =newtext.replace('user=myuser','user='+user)
while 'passwd=mypwd' in newtext:
newtext =newtext.replace('passwd=mypwd','passwd='+passw)
while 'address=maxscale' in newtext:
newtext =newtext.replace('address=maxscale','maxscale='+ip_server)
with open('/etc/maxscale.cnf', "w") as f:
f.write(newtext)
print('start maxscale service ')
os.system('systemctl start maxscale.service')
os.system('systemctl enable maxscale.service')
print('\nConfig done!!!!')
time.sleep(2)
os.system('mysql -h ' +ip_server+ ' -u'+user+ ' -p'+passw)