Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Last active November 24, 2020 06:21
Show Gist options
  • Save Lewiscowles1986/27cfeda001bb75a9151b5c974c2318bc to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/27cfeda001bb75a9151b5c974c2318bc to your computer and use it in GitHub Desktop.
Raspberry Pi MariaDB 10.1 with Galera Cluster build
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get install -y build-essential git cmake scons rpi-update
apt-get install -y libarchive-dev libevent-dev libssl-dev libboost-dev
apt-get install -y libncurses5-dev libbison-dev
cd /tmp
git clone -b 10.1 https://github.com/MariaDB/server.git --depth=1 mariadb-server-src
cd mariadb-server-src
cmake -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON ./
make
make install
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
update-rc.d mysqld defaults
echo "export PATH=\${PATH}:/usr/local/mysql/bin/" > /etc/profile.d/mysql
groupadd mysql && useradd -g mysql mysql
mkdir -p /srv/mysql
rm -rf /etc/mysql
install -v -dm 755 /etc/mysql &&
cat > /etc/mysql/my.cnf << "EOF"
# 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]
port = 3306
socket = /run/mysqld/mysqld.sock
datadir = /srv/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all.
skip-networking
# required unique id between 1 and 2^32 - 1
server-id = 1
# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000
# InnoDB tables are now used by default
innodb_data_home_dir = /srv/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /srv/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[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
EOF
source /etc/profile.d/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/srv/mysql --basedir=/usr/local/mysql
chown -R mysql:mysql /srv/mysql
apt-get install -y libboost-program-options-dev check
cd /tmp
git clone https://github.com/codership/galera --depth=1
cd galera
scons
if [ -d "/etc/php/7.0" ]; then
apt-get install -y php7.0-mysql
fi
@FlashThunder
Copy link

FlashThunder commented Dec 11, 2016

After 2 hours, lots of notices and few warning while compiling galera, but passing all tests... script finished. Seems it works! You got to configure it tho... Install service etc. Still many thanx 👍

mysql --version
mysql Ver 15.1 Distrib 10.1.20-MariaDB, for Linux (armv7l) using readline 5.1

@wmeitzen
Copy link

The compile process above seemed to work, but "mysql --version" returns a "command not found."

@Lewiscowles1986
Copy link
Author

@wmeltzen it's mysqld surely? (I don't actually remember)

@FlashT
Copy link

FlashT commented May 30, 2018

how do I update it now? there is mariadb in repository now, but it wants to just install a 10 version, doesn't see that it's already installed...

@kpdbhh
Copy link

kpdbhh commented Jul 5, 2018

Here are some Logs
[  5%] Built target strings
[  5%] Building CXX object mysys_ssl/CMakeFiles/mysys_ssl.dir/my_md5.cc.o
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc: In function ‘void md5_result(MD5_CONTEXT*, uchar*)’:
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc:86:29: error: ‘EVP_MD_CTX_cleanup’ was not declared in this scope
   EVP_MD_CTX_cleanup(context);
                             ^
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc: In function ‘void my_md5(uchar*, const char*, size_t)’:
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc:102:15: error: aggregate ‘MD5_CONTEXT md5_context’ has incomplete type and cannot be defined
   MD5_CONTEXT md5_context;
               ^~~~~~~~~~~
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc: In function ‘void my_md5_multi(uchar*, ...)’:
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc:127:15: error: aggregate ‘MD5_CONTEXT md5_context’ has incomplete type and cannot be defined
   MD5_CONTEXT md5_context;
               ^~~~~~~~~~~
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc: In function ‘size_t my_md5_context_size()’:
/tmp/mariadb-server-src/mysys_ssl/my_md5.cc:140:28: error: invalid application of ‘sizeof’ to incomplete type ‘MD5_CONTEXT {aka evp_md_ctx_st}’
   return sizeof(MD5_CONTEXT);
                            ^
mysys_ssl/CMakeFiles/mysys_ssl.dir/build.make:182: recipe for target 'mysys_ssl/CMakeFiles/mysys_ssl.dir/my_md5.cc.o' failed
make[2]: *** [mysys_ssl/CMakeFiles/mysys_ssl.dir/my_md5.cc.o] Error 1
CMakeFiles/Makefile2:8562: recipe for target 'mysys_ssl/CMakeFiles/mysys_ssl.dir/all' failed
make[1]: *** [mysys_ssl/CMakeFiles/mysys_ssl.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
cp: cannot stat '/usr/local/mysql/support-files/mysql.server': No such file or directory
update-rc.d: error: unable to read /etc/init.d/mysqld
install: creating directory '/etc/mysql'
./setup.sh: 106: ./setup.sh: source: not found
./setup.sh: 107: ./setup.sh: /usr/local/mysql/scripts/mysql_install_db: not found
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libaio1 libcgi-fast-perl libcgi-pm-perl libdbi-perl libencode-locale-perl
  libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
  liblwp-mediatypes-perl libreadline5 libterm-readkey-perl libtimedate-perl
  liburi-perl lxkeymap python-cairo python-gobject python-gobject-2
  python-gtk2 python-xklavier socat
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libboost-program-options1.62-dev libboost-program-options1.62.0
  libsubunit-dev libsubunit0
The following NEW packages will be installed:
  check libboost-program-options-dev libboost-program-options1.62-dev
  libboost-program-options1.62.0 libsubunit-dev libsubunit0
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 514 kB of archives.
After this operation, 2,215 kB of additional disk space will be used.
Get:1 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian stretch/main armhf libsubunit0 armhf 1.1.0-3 [8,444 B]
Get:2 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian stretch/main armhf libsubunit-dev armhf 1.1.0-3 [9,356 B]
Get:3 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian stretch/main armhf check armhf 0.10.0-3 [178 kB]
Get:4 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian stretch/main armhf libboost-program-options1.62.0 armhf 1.62.0+dfsg-4 [136 kB]
Get:5 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian stretch/main armhf libboost-program-options1.62-dev armhf 1.62.0+dfsg-4 [178 kB]
Get:6 http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian stretch/main armhf libboost-program-options-dev armhf 1.62.0.1+b4 [3,716 B]
Fetched 514 kB in 4s (117 kB/s)                          
Selecting previously unselected package libsubunit0:armhf.
(Reading database ... 143371 files and directories currently installed.)
Preparing to unpack .../0-libsubunit0_1.1.0-3_armhf.deb ...
Unpacking libsubunit0:armhf (1.1.0-3) ...
Selecting previously unselected package libsubunit-dev.
Preparing to unpack .../1-libsubunit-dev_1.1.0-3_armhf.deb ...
Unpacking libsubunit-dev (1.1.0-3) ...
Selecting previously unselected package check:armhf.
Preparing to unpack .../2-check_0.10.0-3_armhf.deb ...
Unpacking check:armhf (0.10.0-3) ...
Selecting previously unselected package libboost-program-options1.62.0:armhf.
Preparing to unpack .../3-libboost-program-options1.62.0_1.62.0+dfsg-4_armhf.deb ...
Unpacking libboost-program-options1.62.0:armhf (1.62.0+dfsg-4) ...
Selecting previously unselected package libboost-program-options1.62-dev:armhf.
Preparing to unpack .../4-libboost-program-options1.62-dev_1.62.0+dfsg-4_armhf.deb ...
Unpacking libboost-program-options1.62-dev:armhf (1.62.0+dfsg-4) ...
Selecting previously unselected package libboost-program-options-dev:armhf.
Preparing to unpack .../5-libboost-program-options-dev_1.62.0.1+b4_armhf.deb ...
Unpacking libboost-program-options-dev:armhf (1.62.0.1+b4) ...
Setting up libboost-program-options1.62.0:armhf (1.62.0+dfsg-4) ...
Processing triggers for install-info (6.3.0.dfsg.1-1+b1) ...
Setting up libsubunit0:armhf (1.1.0-3) ...
Setting up libboost-program-options1.62-dev:armhf (1.62.0+dfsg-4) ...
Setting up libsubunit-dev (1.1.0-3) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Setting up check:armhf (0.10.0-3) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libboost-program-options-dev:armhf (1.62.0.1+b4) ...
Cloning into 'galera'...
remote: Counting objects: 1224, done.
remote: Compressing objects: 100% (1010/1010), done.
remote: Total 1224 (delta 249), reused 557 (delta 138), pack-reused 0
Receiving objects: 100% (1224/1224), 3.36 MiB | 3.38 MiB/s, done.
Resolving deltas: 100% (249/249), done.
scons: Reading SConscript files ...
Host: linux armv7l 32bit
Signature: version: 3.23, revision: XXXX
Using C compiler executable: gcc
C compiler version is: gcc (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516
Using C++ compiler executable: g++
C++ compiler version is: g++ (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516
Checking for C library pthread... yes
Checking for C library atomic... yes
Checking for C library rt... yes
Checking for C header file sys/epoll.h... yes
Checking for C header file byteswap.h... yes
Checking for C header file endian.h... yes
Checking for C header file execinfo.h... yes
Checking if compiling in C++11 mode ... no
Checking for std::tr1::array ... yes
Checking for C++ header file boost/shared_ptr.hpp... yes
Checking for std::tr1::unordered_map ... yes
Checking for C++ library boost_program_options... yes
Checking for C++ header file asio.hpp... no
Falling back to bundled asio
Checking for C++ header file asio.hpp... yes
Checking for C++ header file asio/ssl.hpp... no
SSL support required but asio/ssl.hpp was not found or not usable
check that SSL devel headers are installed and usable

@kpdbhh
Copy link

kpdbhh commented Jul 5, 2018

I am facing with this error .....plz help me....only complete 5%....working with RPI3

@ronie19
Copy link

ronie19 commented May 13, 2020

Is there any tutorial website for same ?

@Lewiscowles1986
Copy link
Author

This is so old now, you should really not use. It's 4 years old and we've had 2-3 major OS updates since then MariaDB 10.1 is OLD

What parts of this was it you needed?

@ronie19
Copy link

ronie19 commented May 14, 2020

Actually I want to set up multiple Raspberry Pi over a lan with static IP on all. Data entered on any one shall be replicated on all. For some alarm system project in my college.

@Lewiscowles1986
Copy link
Author

Right, none of that has anything to do with this...

@ronie19
Copy link

ronie19 commented May 14, 2020

Someone on Facebook did point to this blog while I put my requirements there

@sanfx
Copy link

sanfx commented Nov 23, 2020

FYI future visitors galera is part of mariadb-server from mariadb version 10.4 onwards

@Lewiscowles1986
Copy link
Author

Thx @sanfx, this is from 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment