This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mysqlsetup.sh
executable file
·131 lines (96 loc) · 4.35 KB
/
mysqlsetup.sh
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
#!/bin/bash
. /mnt/context.sh
## setting the network for NFS
echo 0 > /proc/sys/net/ipv4/tcp_sack
echo 0 > /proc/sys/net/ipv4/tcp_timestamps
# Add entries to fstab
if ( ! grep "NFS Mount Points Added" /etc/fstab); then
# Create mount points
mkdir -p /db/mysql_data
mkdir -p /db/mysql_binlog
mkdir -p /db/mysql_config
mkdir -p /db/mysql_tranlog
cat >>/etc/fstab <<MNTTAB
# NFS Mount Points Added
#
$NFSDATA /db/mysql_data nfs _netdev,rw,bg,hard,rsize=32768,wsize=32768,nointr,timeo=600,proto=tcp,nolock,noatime,tcp,vers=3
$LOGMNT /db/mysql_binlog nfs _netdev,rw,bg,hard,rsize=32768,wsize=32768,nointr,timeo=600,proto=tcp,nolock,noatime,tcp,vers=3
$CONFIGMNT /db/mysql_config nfs _netdev,rw,bg,hard,rsize=32768,wsize=32768,nointr,timeo=600,proto=tcp,nolock,noatime,tcp,vers=3
$TRANLOG /db/mysql_tranlog nfs _netdev,rw,bg,hard,rsize=32768,wsize=32768,nointr,timeo=600,proto=tcp,nolock,noatime,tcp,vers=3
MNTTAB
fi
if (! mount -a ); then
echo "Failed to mount all filesystems listed in /etc/fstab">&2
if (! mountpoint -q /db/mysql_data); then
echo "Failed to mount $NFSDATA">&2
fi
if (! mountpoint -q /db/mysql_binlog); then
echo "Failed to mount $LOGMNT">&2
fi
if (! mountpoint -q /db/mysql_config); then
echo "Failed to mount $CONFIGMNT">&2
fi
if (! mountpoint -q /db/mysql_tranlog); then
echo "Failed to mount $TRANLOG">&2
fi
wget http://$CARINA_IP/cgi-bin/updateappstatus.sh?service=$SERVICE_NAME\&vmid=$VMID\&envid=$ENVID\&status=MASTER_INIT_FAIL 2> /dev/null
fi
if [ ! -d /db/mysql_config/$HOSTNAME ]; then
mkdir /db/mysql_data/$HOSTNAME
mkdir /db/mysql_binlog/$HOSTNAME
mkdir /db/mysql_config/$HOSTNAME
mkdir /db/mysql_tranlog/$HOSTNAME
#copy the configuration files
rm /etc/mysql/my.cnf
mv /etc/mysql/* /db/mysql_config/$HOSTNAME/
cp /mnt/my.cnf /db/mysql_config/$HOSTNAME/
echo "slow_query_log_file = /db/mysql_tranlog/$HOSTNAME/mysql-slow.log" >> /db/mysql_config/$HOSTNAME/my.cnf
echo "log_error = /db/mysql_tranlog/$HOSTNAME/mysql-error.log" >> /db/mysql_config/$HOSTNAME/my.cnf
echo "log_bin = /db/mysql_binlog/$HOSTNAME/master-bin" >> /db/mysql_config/$HOSTNAME/my.cnf
echo "log-bin-index = /db/mysql_binlog/$HOSTNAME/master-bin" >> /db/mysql_config/$HOSTNAME/my.cnf
echo "general_log_file = /db/mysql_tranlog/$HOSTNAME/mysql.log" >> /db/mysql_config/$HOSTNAME/my.cnf
echo "datadir = /db/mysql_data/$HOSTNAME/mysql" >> /db/mysql_config/$HOSTNAME/my.cnf
echo "bind-address = $IP" >> /db/mysql_config/$HOSTNAME/my.cnf
ln -s /db/mysql_config/$HOSTNAME/my.cnf /etc/mysql/my.cnf
ln -s /db/mysql_config/$HOSTNAME/debian-start /etc/mysql/debian-start
ln -s /db/mysql_config/$HOSTNAME/debian.cnf /etc/mysql/debian.cnf
ln -s /db/mysql_config/$HOSTNAME/conf.d /etc/mysql/conf.d
#copy the mysql files
cp -R /var/lib/mysql /db/mysql_data/$HOSTNAME/mysql
rm /db/mysql_data/$HOSTNAME/mysql/ib_logfile0
rm /db/mysql_data/$HOSTNAME/mysql/ib_logfile1
# Setup permissions
chown -R mysql:mysql /db/mysql_data/$HOSTNAME
chown -R mysql:mysql /db/mysql_binlog/$HOSTNAME
chown -R mysql:mysql /db/mysql_config/$HOSTNAME
chown -R mysql:mysql /db/mysql_tranlog/$HOSTNAME
if [ ! -d /var/run/mysqld ]; then
mkdir /var/run/mysqld
chown mysql:mysql /var/run/mysqld
fi
if [ -f /etc/init/mysql.override ]; then
rm /etc/init/mysql.override
fi
#start up mysql
/etc/init.d/mysql start
#set the root password
/usr/bin/mysqladmin -u root password $DBPWD
else
#remove the configuration files
rm -rf /etc/mysql/*
#make the link
ln -s /db/mysql_config/$HOSTNAME/my.cnf /etc/mysql/my.cnf
ln -s /db/mysql_config/$HOSTNAME/debian-start /etc/mysql/debian-start
ln -s /db/mysql_config/$HOSTNAME/debian.cnf /etc/mysql/debian.cnf
ln -s /db/mysql_config/$HOSTNAME/conf.d /etc/mysql/conf.d
if [ ! -d /var/run/mysqld ]; then
mkdir /var/run/mysqld
chown mysql:mysql /var/run/mysqld
fi
if [ -f /etc/init/mysql.override ]; then
rm /etc/init/mysql.override
fi
#start up mysqld
/etc/init.d/mysql start
fi
wget http://$CARINA_IP/cgi-bin/updateappstatus.sh?service=$SERVICE_NAME\&vmid=$VMID\&envid=$ENVID\&status=MASTER_INIT_DONE 2> /dev/null