Commit 7417bdd1 authored by Vladimir Bashkirtsev's avatar Vladimir Bashkirtsev

Added mysql server build

parent 9c45aac5
all: my-cnf mariadb-config
dd if=/dev/zero of=swap bs=1048576 count=1024
chmod 600 swap
mkswap swap
swapon swap
rm /etc/passwd
mv -v /data/etc/passwd /etc/passwd
rm /etc/group
mv -v /data/etc/group /etc/group
rm /etc/shadow
mv -v /data/etc/shadow /etc/shadow
rm /etc/gshadow
mv -v /data/etc/gshadow /etc/gshadow
groupadd -g 40 mysql
useradd -c "MySQL Server" -d /srv/mysql -g mysql -s /bin/false -u 40 mysql
rm /etc/passwd-
rm /etc/group-
rm /etc/shadow-
rm /etc/gshadow-
mv -v /etc/passwd /data/etc/passwd
ln -sv /data/etc/passwd /etc/passwd
mv -v /etc/group /data/etc/group
ln -sv /data/etc/group /etc/group
mv -v /etc/shadow /data/etc/shadow
ln -sv /data/etc/shadow /etc/shadow
mv -v /etc/gshadow /data/etc/gshadow
ln -sv /data/etc/gshadow /etc/gshadow
tar xf mariadb-10.3.13.tar.gz
cd mariadb-10.3.13 && sed -i "s@data/test@\$${INSTALL_MYSQLTESTDIR}@g" sql/CMakeLists.txt
mkdir mariadb-10.3.13/build
cd mariadb-10.3.13/build && cmake -DCMAKE_BUILD_TYPE=Release -DINSTALL_LAYOUT=DEB -DWITH_EXTRA_CHARSETS=complex -DSKIP_TESTS=ON -DTOKUDB_OK=0 -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON ..
$(MAKE) -C mariadb-10.3.13/build
$(MAKE) -C mariadb-10.3.13/build test
$(MAKE) -C mariadb-10.3.13/build install
rm -rf /usr/mysql-test
install -v -dm 755 /etc/mysql
@echo "$$MY_CNF" > /etc/mysql/my.cnf
@echo "$$MARIADB_CONFIG" > /etc/config/mariadb
install -v -Dm755 mariadb /usr/share/easycwmp/functions
install -v -Dm755 wsrep-init /usr/sbin/wsrep-init
sed -i '/^\[Service\]$$/a ExecStartPre=/usr/sbin/wsrep-init' /lib/systemd/system/mariadb.service
sed -i '/^\[Service\]$$/a TimeoutStartSec=60min' /lib/systemd/system/mariadb.service
sed -i 's/^Restart=.*/Restart=always/' /lib/systemd/system/mariadb.service
systemctl enable mariadb.service
install -v -Dm755 mysqlchk /usr/sbin/mysqlchk
install -v -Dm644 mysqlchk.socket /lib/systemd/system/mysqlchk.socket
install -v -Dm644 mysqlchk@.service /lib/systemd/system/mysqlchk@.service
systemctl enable mysqlchk.socket
mysql_install_db --basedir=/usr --user=mysql --skip-test-db
sed -e '/^UserParameter=device\.product.*/a UserParameter=mysql.version,mysql -V' -i /etc/zabbix_agentd.conf
sed -e '/^UserParameter=device\.product.*/a UserParameter=mysql.ping,mysqladmin -u root ping | grep -c alive' -i /etc/zabbix_agentd.conf
sed -e '/^UserParameter=device\.product.*/a UserParameter=mysql.size[*],bash -c '\''echo "select sum($$(case "$$3" in both|"") echo "data_length+index_length";; data|index) echo "$$3_length";; free) echo "data_free";; esac)) from information_schema.tables$$([[ "$$1" = "all" || ! "$$1" ]] || echo " where table_schema=\\"$$1\\"")$$([[ "$$2" = "all" || ! "$$2" ]] || echo "and table_name=\\"$$2\\"");" | mysql -u root -N'\''' -i /etc/zabbix_agentd.conf
sed -e '/^UserParameter=device\.product.*/a UserParameter=mysql.discovery,l=$$(echo "show databases" | mysql -u root -N);echo -n '\''{"data":['\'';for i in $${l};do echo -n "{\\"{#DBNAME}\\": \\"$$i\\"},";done|sed -e '\''s:\\},$$:\\}:'\'';echo -n '\'']}'\'';' -i /etc/zabbix_agentd.conf
sed -e '/^UserParameter=device\.product.*/a UserParameter=mysql.status[*],echo "show global status where Variable_name='\''\$$1'\'';" | mysql -u root -N | awk '\''{print $$$$2}'\''' -i /etc/zabbix_agentd.conf
rm -rf mariadb-10.3.13
swapoff swap
rm -rf swap
my-cnf:
define MY_CNF
# Begin /etc/mysql/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /run/mysqld/mysqld.sock
# The MySQL server
[mysqld]
datadir = /var/lib/mysql
socket = /run/mysqld/mysqld.sock
user = mysql
bind-address = 0.0.0.0
port = 3306
log-bin = binlog
binlog_format = ROW
expire_logs_days = 1
skip-external-locking
skip-name-resolve
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
# InnoDB tables are now used by default
default-storage-engine = InnoDB
innodb_data_home_dir = /var/lib/mysql
innodb_log_group_home_dir = /var/lib/mysql
# All the innodb_xxx values below are the default ones:
innodb_data_file_path = ibdata1:12M:autoextend
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 122M
innodb_log_file_size = 32M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 0
innodb_autoinc_lock_mode = 2
innodb_lock_wait_timeout = 50
!include /run/mysqld/wsrep.conf
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
# End /etc/mysql/my.cnf
endef
export MY_CNF
mariadb-config:
define MARIADB_CONFIG
config wsrep 'galera'
option cluster_address ''
option cluster_options ''
endef
export MARIADB_CONFIG
client: client:
dd if=/dev/zero of=swap bs=1048576 count=1024 dd if=/dev/zero of=swap bs=1048576 count=1024
chmod 600 swap chmod 600 swap
......
#!/bin/sh
#common_execute_method_param "$parameter" "$permission" "$get_cmd" "$set_cmd" "xsd:$type" "$forcedinform"
# $forcedinform should be set to 1 if the parameter is included in the inform message otherwise empty
# Default of $type = string
#############################
# Entry point functuons #
#############################
prefix_list="$prefix_list $DMROOT.MySQL."
entry_execute_method_list="$entry_execute_method_list entry_execute_method_root_MySQL"
entry_execute_method_list_forcedinform="$entry_execute_method_list_forcedinform entry_execute_method_root_MySQL"
entry_execute_method_root_MySQL() {
case "$1" in ""|"$DMROOT."|"$DMROOT.MySQL."*)
common_execute_method_obj "$DMROOT.MySQL." "0"
common_execute_method_param "$DMROOT.MySQL.RootPassword" "1" "" "mysql_set_root_password"
common_execute_method_param "$DMROOT.MySQL.SafeToBootstrap" "1" "mysql_get_safe_to_bootstrap" "mysql_set_safe_to_bootstrap" "xsd:boolean"
common_execute_method_param "$DMROOT.MySQL.GaleraBootstrap" "1" "" "mysql_galera_bootstrap" "xsd:boolean"
common_execute_method_param "$DMROOT.MySQL.GaleraClusterAddress" "1" "mysql_get_cluster_address" "mysql_set_cluster_address"
common_execute_method_param "$DMROOT.MySQL.GaleraClusterOptions" "1" "mysql_get_cluster_options" "mysql_set_cluster_options"
return 0;
;;
esac
return $E_INVALID_PARAMETER_NAME;
}
#######################################
# Data model parameters functions #
#######################################
mysql_set_root_password() {
local pass="$1"
echo "GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '$pass' WITH GRANT OPTION" | mysql
}
mysql_get_safe_to_bootstrap() {
if [ -f /var/lib/mysql/grastate.dat ]; then
local safe=`grep -c 'safe_to_bootstrap: 1' /var/lib/mysql/grastate.dat`
if [ $safe = 1 ]; then
echo "true"
else
echo "false"
fi
else
echo "true"
fi
return 0
}
mysql_set_safe_to_bootstrap() {
if [ -f /var/lib/mysql/grastate.dat ]; then
if [ $1 = "true" ]; then
sed -i 's/^safe_to_bootstrap: ./safe_to_bootstrap: 1/' /var/lib/mysql/grastate.dat
else
sed -i 's/^safe_to_bootstrap: ./safe_to_bootstrap: 0/' /var/lib/mysql/grastate.dat
fi
fi
}
mysql_galera_bootstrap() {
local safe=`mysql_get_safe_to_bootstrap`
if [ $safe = "true" ]; then
systemctl stop mariadb
wsrep-init
galera_new_cluster
fi
return 0
}
mysql_get_cluster_address() {
echo `$UCI_GET mariadb.galera.cluster_address`
}
mysql_set_cluster_address() {
local address=`$UCI_GET mariadb.galera.cluster_address`
if [ "$address" != "$1" ]; then
$UCI_SET mariadb.galera.cluster_address="$1"
$UCI_COMMIT
wsrep-init
systemctl restart mariadb
fi
}
mysql_get_cluster_options() {
echo `$UCI_GET mariadb.galera.cluster_options`
}
mysql_set_cluster_options() {
local options=`$UCI_GET mariadb.galera.cluster_options`
if [ "$options" != "$1" ]; then
$UCI_SET mariadb.galera.cluster_options="$1"
$UCI_COMMIT
wsrep-init
systemctl restart mariadb
fi
}
#!/bin/bash
#
# This script checks if a mysql server is healthy running on localhost. It will
# return:
# "HTTP/1.x 200 OK" (if mysql is running smoothly)
# - OR -
# "HTTP/1.x 500 Internal Server Error" (else)
#
# The purpose of this script is make haproxy capable of monitoring mysql properly
#
MYSQL_HOST="localhost"
MYSQL_PORT="3306"
MYSQL_USERNAME='root'
MYSQL_OPTS="-N -q -A --connect-timeout=10"
MYSQL_BIN='/usr/bin/mysql'
CHECK_QUERY="select 1"
CHECK_QUERY1="show global status where variable_name='wsrep_local_state'"
CHECK_QUERY2="show global variables where variable_name='read_only'"
CHECK_QUERY3="show global variables where variable_name='wsrep_sst_method'"
GALERA=`/sbin/uci get mariadb.galera.cluster_address`
return_ok()
{
echo "HTTP/1.1 200 OK"
echo "Content-Type: text/html"
echo "Content-Length: 43"
echo ""
echo "<html><body>MySQL is running.</body></html>"
echo ""
exit 0
}
return_fail()
{
echo "HTTP/1.1 503 Service Unavailable"
echo "Content-Type: text/html"
echo "Content-Length: 42"
echo ""
echo "<html><body>MySQL is *down*.</body></html>"
echo ""
exit 1
}
if [ -z $GALERA ]; then
status=$($MYSQL_BIN $MYSQL_OPTS --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME -e "$CHECK_QUERY;" 2>/dev/null)
if [ $? -ne 0 ]; then
return_fail;
else
return_ok;
fi
else
status=$($MYSQL_BIN $MYSQL_OPTS --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME -e "$CHECK_QUERY1;" 2>/dev/null)
if [ $? -ne 0 ]; then
return_fail;
fi
status=$(echo $status | awk '{print $2;}')
if [ $status -eq 2 ] || [ $status -eq 4 ]; then
readonly=$($MYSQL_BIN $MYSQL_OPTS --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME -e "$CHECK_QUERY2;" 2>/dev/null)
if [ $? -ne 0 ]; then
return_fail;
fi
readonly=$(echo $readonly | awk '{print $2;}')
if [ "$readonly" = "YES" -o "$readonly" = "ON" ]; then
return_fail;
fi
if [ $status -eq 2 ]; then
method=$($MYSQL_BIN $MYSQL_OPTS --host=$MYSQL_HOST --port=$MYSQL_PORT --user=$MYSQL_USERNAME -e "$CHECK_QUERY3;" 2>/dev/null)
if [ $? -ne 0 ]; then
return_fail;
fi
method=$(echo $method | awk '{print $2;}')
if [ -z "$method" ] || [ "$method" = "rsync" ] || [ "$method" = "mysqldump" ]; then
return_fail;
fi
fi
return_ok;
fi
fi
[Unit]
Description = MySQL check socket
[Socket]
ListenStream = 9000
Accept = yes
[Install]
WantedBy = sockets.target
[Unit]
Description = MySQL check service
Requires = mysqlchk.socket
[Service]
Type = simple
ExecStart = /usr/sbin/mysqlchk
StandardInput = socket
StandardError = journal
[Install]
WantedBy = multi-user.target
#!/bin/sh
UCI_GET="/sbin/uci -q get"
ADDRESS=`$UCI_GET mariadb.galera.cluster_address`
OPTIONS=`$UCI_GET mariadb.galera.cluster_options`
if [ ! -z $ADDRESS ]; then
cat << EOF > /run/mysqld/wsrep.conf
[mysqld]
wsrep_on = ON
wsrep_provider = /usr/lib/libgalera_smm.so
wsrep_cluster_address = "gcomm://$ADDRESS"
wsrep_sst_method = mariabackup
wsrep_sst_auth = root:
wsrep_slave_threads = 1
EOF
if [ ! -z "$OPTIONS" ]; then
echo "wsrep_provider_options = $OPTIONS" >> /run/mysqld/wsrep.conf
fi
chown mysql.mysql /run/mysqld/wsrep.conf
else
rm -f /run/mysqld/wsrep.conf
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment