Последняя чуть более сложная задача - это внести важные поправки в конфигурационный файл. Необходимо указать MariaDB использовать только определенный конфигурационный файл
В секции start после $bindir/mysqld_safe добавить --defaults-file=/opt/mariadb-data/my.cnf
Должно получиться приблизительно следующее
1 2 3
# Give extra arguments to mysqld with the my.cnf file. This script # may be overwritten at next upgrade. $bindir/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path"$other_args >/dev/null 2>&1 &
Также необходимо внести изменения в строке с mysqladmin для функции wait_for_ready(), чтобы MariaDB смога правильно слушать сервер при старте. Для этого добавим в функцию wait_for_ready() после $bindir/mysqladmin путь до конфигурационного файла --defaults-file=/opt/mariadb-data/my.cnf
Выглядеть это будет приблизительно следующим образом
1 2 3
wait_for_ready () { [...] if$bindir/mysqladmin --defaults-file=/opt/mariadb-data/my.cnf ping >/dev/null 2>&1; then
Если данная функция будет отсутствовать, то необходимо будет внести изменения в файл запуска
=== modified file 'support-files/mysql.server.sh' --- support-files/mysql.server.sh 2013-07-16 17:09:54 +0000 +++ support-files/mysql.server.sh 2014-02-17 10:10:30 +0000 @@ -147,68 +147,12 @@ datadir_set=1 ;; --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; + --socket=*) socket=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; esac done } -wait_for_pid () { - verb="$1" # created | removed - pid="$2" # process ID of the program operating on the pid-file - pid_file_path="$3" # path to the PID file. - - i=0 - avoid_race_condition="by checking again" - - while test $i -ne $service_startup_timeout ; do - - case "$verb" in - 'created') - # wait for a PID-file to pop into existence. - test -s "$pid_file_path" && i='' && break - ;; - 'removed') - # wait for this PID-file to disappear - test ! -s "$pid_file_path" && i='' && break - ;; - *) - echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path" - exit 1 - ;; - esac - - # if server isn't running, then pid-file will never be updated - if test -n "$pid"; then - if kill -0 "$pid" 2>/dev/null; then - : # the server still runs - else - # The server may have exited between the last pid-file check and now. - if test -n "$avoid_race_condition"; then - avoid_race_condition="" - continue # Check again. - fi - - # there's nothing that will affect the file. - log_failure_msg "The server quit without updating PID file ($pid_file_path)." - return 1 # not waiting any more. - fi - fi - - echo $echo_n ".$echo_c" - i=`expr $i + 1` - sleep 1 - - done - - if test -z "$i" ; then - log_success_msg - return 0 - else - log_failure_msg - return 1 - fi -} - # Get arguments from the my.cnf file, # the only group, which is read from now on is [mysqld] if test -x ./bin/my_print_defaults @@ -266,6 +210,69 @@ parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server` +# wait for the pid file to disappear +wait_for_gone () { + pid="$1" # process ID of the program operating on the pid-file + pid_file_path="$2" # path to the PID file. + + i=0 + crash_protection="by checking again" + + while test $i -ne $service_startup_timeout ; do + + if kill -0 "$pid" 2>/dev/null; then + : # the server still runs + else + if test ! -s "$pid_file_path"; then + # no server process and no pid-file? great, we're done! + log_success_msg + return 0 + fi + + # pid-file exists, the server process doesn't. + # it must've crashed, and mysqld_safe will restart it + if test -n "$crash_protection"; then + crash_protection="" + sleep 5 + continue # Check again. + fi + + # Cannot help it + log_failure_msg "The server quit without updating PID file ($pid_file_path)." + return 1 # not waiting any more. + fi + + echo $echo_n ".$echo_c" + i=`expr $i + 1` + sleep 1 + + done + + log_failure_msg + return 1 +} + +wait_for_ready () { + + test -n "$socket" && sockopt="--socket=$socket" + + i=0 + while test $i -ne $service_startup_timeout ; do + + if $bindir/mysqladmin $sockopt ping >/dev/null 2>&1; then + log_success_msg + return 0 + fi + + echo $echo_n ".$echo_c" + i=`expr $i + 1` + sleep 1 + + done + + log_failure_msg + return 1 +} # # Set pid file if not given # @@ -292,7 +299,7 @@ # Give extra arguments to mysqld with the my.cnf file. This script # may be overwritten at next upgrade. $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 & - wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$? + wait_for_ready; return_value=$? # Make lock for RedHat / SuSE if test -w "$lockdir" @@ -319,7 +326,7 @@ echo $echo_n "Shutting down MySQL" kill $mysqld_pid # mysqld should remove the pid file when it exits, so wait for it. - wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$? + wait_for_gone $mysqld_pid "$mysqld_pid_file_path"; return_value=$? else log_failure_msg "MySQL server process #$mysqld_pid is not running!" rm "$mysqld_pid_file_path"
Устанавливаем базу данных
Запускаем mysql_install_db указывая путь до конфигурационного файла как аргумент
1 2
[root@test opt]# cd mariadb [root@test mariadb]# scripts/mysql_install_db --defaults-file=/opt/mariadb-data/my.cnf
Запускаем MariaDB
1 2
[root@test opt]# /etc/init.d/mariadb start Starting MySQL... [ OK ]
Настраиваем автозапуск MariaDB
1 2 3
[root@test opt]# cd /etc/init.d [root@test init.d]# chkconfig --add mariadb [root@test init.d]# chkconfig --levels 3 mariadb on
[root@test mariadb]# mysql --socket=/opt/mariadb-data/mariadb.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.5.24-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
mysql>
Устанавливаем root-пароль
Поскольку в данный момент доступ к базе осуществляется без пароля, что не очень безопасно, то установим пароль для root-пользователя.
1 2 3 4 5
$ mysql -u root mysql> use mysql; mysql>updateuserset password=PASSWORD("new-password") whereUser='root'; mysql> flush privileges; mysql> exit