[demos] Add MySQL demo
This commit is contained in:
parent
47bd1fd7af
commit
6dcdfc2fc4
4
demos/mysql/.gitignore
vendored
Normal file
4
demos/mysql/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
occlum_instance
|
||||
mysql_src
|
||||
boost*
|
||||
*tar*
|
28
demos/mysql/README.md
Normal file
28
demos/mysql/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
# Run MySQL on Occlum
|
||||
|
||||
[`MySQL`](https://www.mysql.com/) is a widely used open-source relational database management system (RDBMS).
|
||||
|
||||
### Build and install
|
||||
```
|
||||
./dl_and_build_mysql.sh
|
||||
```
|
||||
This command downloads MySQL-8.0.31 source code and builds from it.
|
||||
When completed, all MySQL related binaries and tools are installed.
|
||||
|
||||
### Run server and client
|
||||
|
||||
#### Initialize and start the MySQL server
|
||||
```
|
||||
./run_mysql_server.sh
|
||||
```
|
||||
This command initializes and runs the server (using `mysqld`) in Occlum.
|
||||
When completed, the server starts to wait connections.
|
||||
|
||||
#### Start the MySQL client and send simple queries
|
||||
```
|
||||
./run_mysql_client.sh
|
||||
```
|
||||
This command starts the client (using `mysql`) in Occlum and test basic query SQLs.
|
||||
|
||||
The network protocol between client and server uses uds(unix domain socket) by default.
|
||||
More configuration can be tuned and applied in `my.cnf`.
|
28
demos/mysql/apply-mysql-to-occlum.patch
Normal file
28
demos/mysql/apply-mysql-to-occlum.patch
Normal file
@ -0,0 +1,28 @@
|
||||
--- mysql_src/mysys/my_rdtsc-origin.cc 2022-12-08 09:14:01.171126659 +0000
|
||||
+++ mysql_src/mysys/my_rdtsc.cc 2022-12-08 09:08:52.016352814 +0000
|
||||
@@ -299,16 +299,16 @@
|
||||
*/
|
||||
|
||||
ulonglong my_timer_ticks(void) {
|
||||
-#if defined(HAVE_SYS_TIMES_H) && defined(HAVE_TIMES)
|
||||
- {
|
||||
- struct tms times_buf;
|
||||
- return (ulonglong)times(×_buf);
|
||||
- }
|
||||
-#elif defined(_WIN32)
|
||||
- return (ulonglong)GetTickCount();
|
||||
-#else
|
||||
+// #if defined(HAVE_SYS_TIMES_H) && defined(HAVE_TIMES)
|
||||
+// {
|
||||
+// struct tms times_buf;
|
||||
+// return (ulonglong)times(×_buf);
|
||||
+// }
|
||||
+// #elif defined(_WIN32)
|
||||
+// return (ulonglong)GetTickCount();
|
||||
+// #else
|
||||
return 0;
|
||||
-#endif
|
||||
+// #endif
|
||||
}
|
||||
|
||||
/**
|
50
demos/mysql/dl_and_build_mysql.sh
Executable file
50
demos/mysql/dl_and_build_mysql.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
BLUE='\033[1;34m'
|
||||
NC='\033[0m'
|
||||
echo -e "${BLUE}Start installing dependencies.${NC}"
|
||||
|
||||
# Prepare environment
|
||||
DEPS="libnuma-dev libboost-all-dev"
|
||||
|
||||
apt-get update
|
||||
apt-get install -y ${DEPS}
|
||||
|
||||
BOOST="boost_1_77_0"
|
||||
wget https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/${BOOST}.tar.bz2
|
||||
tar --bzip2 -xf ${BOOST}.tar.bz2
|
||||
pushd ${BOOST}
|
||||
./bootstrap.sh --prefix=/usr --with-python=python3 &&
|
||||
./b2 stage -j4 threading=multi link=shared
|
||||
./b2 install threading=multi link=shared
|
||||
popd
|
||||
|
||||
echo -e "${BLUE}Finish installing dependencies.${NC}"
|
||||
|
||||
echo -e "${BLUE}Start building mysql from src.${NC}"
|
||||
|
||||
# Download released tarball
|
||||
VERSION="8.0.31"
|
||||
TARBALL="mysql-${VERSION}.tar.gz"
|
||||
wget https://github.com/mysql/mysql-server/archive/refs/tags/${TARBALL}
|
||||
rm -rf mysql_src && mkdir mysql_src
|
||||
tar -xf ${TARBALL} -C mysql_src --strip-components 1
|
||||
|
||||
# Make modification to
|
||||
# 1. Disable `times` syscall
|
||||
patch -s -p0 < apply-mysql-to-occlum.patch
|
||||
|
||||
# Build and install
|
||||
pushd mysql_src
|
||||
mkdir bld && cd bld
|
||||
|
||||
cmake -j$(nproc) .. -DCMAKE_CXX_FLAGS="-fpic -pie" -DCMAKE_C_FLAGS="-fpic -pie"
|
||||
|
||||
CC="-fpic -pie" CXX="-fpic -pie" make -j$(nproc)
|
||||
|
||||
make install -j$(nproc)
|
||||
cd ..
|
||||
|
||||
echo -e "${BLUE}Finish building mysql from src.${NC}"
|
||||
popd
|
19
demos/mysql/my.cnf
Normal file
19
demos/mysql/my.cnf
Normal file
@ -0,0 +1,19 @@
|
||||
# MySQL configure file
|
||||
|
||||
[client]
|
||||
socket = /tmp/mysql.sock
|
||||
port = 3306
|
||||
bind-address = 127.0.0.1
|
||||
|
||||
[mysqld]
|
||||
socket = /tmp/mysql.sock
|
||||
port = 3306
|
||||
bind-address = 127.0.0.1
|
||||
skip-networking = 0
|
||||
skip_ssl = 0
|
||||
mysqlx = 0
|
||||
wait_timeout = 60
|
||||
interactive_timeout = 120
|
||||
|
||||
[mysql]
|
||||
connect_timeout = 2
|
34
demos/mysql/mysql.yaml
Normal file
34
demos/mysql/mysql.yaml
Normal file
@ -0,0 +1,34 @@
|
||||
includes:
|
||||
- base.yaml
|
||||
# mysql
|
||||
targets:
|
||||
# copy bins
|
||||
- target: /bin
|
||||
copy:
|
||||
- files:
|
||||
# server tools
|
||||
- /usr/local/mysql/bin/mysqld
|
||||
# client tools
|
||||
- /usr/local/mysql/bin/mysql
|
||||
- /usr/local/mysql/bin/mysqladmin
|
||||
- /usr/local/mysql/bin/mysqlshow
|
||||
- target: /etc
|
||||
copy:
|
||||
- files:
|
||||
- ../my.cnf
|
||||
- target: /etc
|
||||
copy:
|
||||
- files:
|
||||
- /etc/localtime
|
||||
- target: /opt/occlum/glibc/etc
|
||||
copy:
|
||||
- files:
|
||||
- /etc/localtime
|
||||
- target: /opt/occlum/glibc/lib
|
||||
copy:
|
||||
- files:
|
||||
- /usr/local/mysql/lib/mysqlrouter/private/libprotobuf-lite.so.3.19.4
|
||||
- target: /
|
||||
copy:
|
||||
- files:
|
||||
- /usr/local/mysql/bin/mysqld
|
32
demos/mysql/run_mysql_client.sh
Executable file
32
demos/mysql/run_mysql_client.sh
Executable file
@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
GREEN='\033[1;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
MYSQL=mysql
|
||||
MYSQLSHOW=mysqlshow
|
||||
MYSQLADMIN=mysqladmin
|
||||
|
||||
# Need to wait until server is ready
|
||||
echo -e "${GREEN}Need to wait mysql server to start${NC}"
|
||||
|
||||
pushd occlum_instance
|
||||
|
||||
echo -e "${GREEN}Run mysql client on Occlum${NC}"
|
||||
|
||||
# Use unix domain socket
|
||||
occlum exec /bin/${MYSQLADMIN} version
|
||||
|
||||
occlum exec /bin/${MYSQLSHOW}
|
||||
|
||||
occlum exec /bin/${MYSQL} -e "SELECT User, Host, plugin FROM mysql.user"
|
||||
|
||||
echo -e "${GREEN}Run mysql client on host${NC}"
|
||||
|
||||
# Use TCP/IP
|
||||
/usr/local/mysql/bin/${MYSQLSHOW} -h 127.0.0.1 -P 3306
|
||||
|
||||
occlum stop
|
||||
|
||||
popd
|
42
demos/mysql/run_mysql_server.sh
Executable file
42
demos/mysql/run_mysql_server.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
GREEN='\033[1;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
bomfile=${SCRIPT_DIR}/mysql.yaml
|
||||
|
||||
MYSQL=mysql
|
||||
MYSQLD=mysqld
|
||||
|
||||
# 1. Init Occlum instance
|
||||
rm -rf occlum_instance && occlum new occlum_instance
|
||||
pushd occlum_instance
|
||||
|
||||
new_json="$(jq '.resource_limits.user_space_size = "3500MB" |
|
||||
.resource_limits.kernel_space_heap_size ="3000MB" |
|
||||
.resource_limits.max_num_of_threads = 96' Occlum.json)" && \
|
||||
echo "${new_json}" > Occlum.json
|
||||
|
||||
|
||||
# 2. Copy files into Occlum instance and build
|
||||
rm -rf image
|
||||
copy_bom -f $bomfile --root image --include-dir /opt/occlum/etc/template
|
||||
|
||||
occlum build
|
||||
|
||||
# 3. Run the program
|
||||
echo -e "${GREEN}Run mysql server (mysqld) on Occlum${NC}"
|
||||
|
||||
occlum start
|
||||
|
||||
echo -e "${GREEN}mysql server initialize${NC}"
|
||||
|
||||
occlum exec /bin/${MYSQLD} --initialize-insecure --user=root
|
||||
|
||||
echo -e "${GREEN}mysql server start${NC}"
|
||||
|
||||
occlum exec /bin/${MYSQLD} --user=root
|
||||
|
||||
popd
|
Loading…
Reference in New Issue
Block a user