Skip to content

Commit

Permalink
fixup! Add MySQL server example
Browse files Browse the repository at this point in the history
Signed-off-by: Jitender Kumar <jitender.kumar@intel.com>
  • Loading branch information
jkr0103 committed Jun 23, 2022
1 parent ce8049e commit 209fed2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
4 changes: 4 additions & 0 deletions mysql/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine)
UID ?= $(shell id -u)
GID ?= $(shell id -g)

ifeq ($(DEBUG),1)
GRAMINE_LOG_LEVEL = debug
Expand All @@ -16,6 +18,8 @@ mysqld.manifest: mysqld.manifest.template
gramine-manifest \
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
-Darch_libdir=$(ARCH_LIBDIR) \
-Duid=$(UID) \
-Dgid=$(GID) \
-Dentrypoint=$(realpath $(shell sh -c "command -v mysqld")) \
$< >$@

Expand Down
43 changes: 22 additions & 21 deletions mysql/README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
# MySQL example
This example is tested with MySQL version 8.0.29.

This directory contains an example for running Mysql server in Gramine, including
This directory contains an example for running MySQL server in Gramine, including
the Makefile and a template for generating the manifest.

# Pre-requisites
## Pre-requisites

- `sudo apt-get install mysql-server` to install MySQL server.
- Comment out the log line `log_error = /var/log/mysql/error.log` in the config file
- Comment out the log line `log_error = /var/log/mysql/error.log` in the config file
`/etc/mysql/mysql.conf.d/mysqld.cnf` to see the log on console.
- `systemctl stop mysql.service` to stop the default MySQL service .We will manually
- `systemctl stop mysql.service` to stop the default MySQL service. We will manually
run MySQL process.
- `sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld`
- `sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld`
to allow MySQL server to create socket file `mysqld.sock`.
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-files` to allow MySQL server for
internal usage.
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring` to allow MySQL server for
internal usage.
- `mysqld --initialize-insecure --datadir=mysql-data/` to initialize data directory.
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-files` to allow running
MySQL server under the current non-root user.
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring` to allow running
MySQL server under the current non-root user.
- `mysqld --initialize-insecure --datadir=/tmp/mysql-data` to initialize data directory. For
details on '--initialize-insecure', please see the https://dev.mysql.com/doc/mysql-linuxunix-excerpt/5.7/en/data-directory-initialization.html page.

# Build
## Build

Run `make` to build the non-SGX version and `make SGX=1` to build the SGX
version.

# Run
## Run

Execute any one of the following commands to run the workload:

- Natively: `mysqld --datadir /tmp/mysql`.
- Gramine w/o SGX: `gramine-direct mysqld -u root --datadir /tmp/mysql`.
- Gramine with SGX: `gramine-sgx mysqld -u root --datadir /tmp/mysql`.
- Natively: `mysqld --datadir /tmp/mysql-data`.
- Gramine w/o SGX: `gramine-direct mysqld --datadir /tmp/mysql-data`.
- Gramine with SGX: `gramine-sgx mysqld --datadir /tmp/mysql-data`.

# Testing client connection and running sysbench benchmarking
## Testing client connection and running Sysbench

Run below command from new terminal:
Run below commands from new terminal:

- `mysql -P 3306 --protocol=tcp -uroot` to connect a client to MySQL server.
- `mysql -P 3306 --protocol=tcp -u root` to connect a client to MySQL server.
- `mysql> exit` to disconnect the client.

Run Sysbench benchmarking:
Run Sysbench:

- `sudo apt install -y sysbench` to install sysbench.
- `sudo apt install -y sysbench` to install Sysbench.
- `sudo mysqladmin -h 127.0.0.1 -P 3306 create sbtest` to create test database.

- `sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-db=sbtest --time=20 --report-interval=5 oltp_read_write --tables=2 --table_size=100000 --threads=32 prepare` to
create records in test database.
- `sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-db=sbtest --time=20 --report-interval=5 oltp_read_write --tables=2 --table_size=100000 --threads=32 run` to
run the sysbench benchmarks.
run the Sysbench benchmarks.
- `sysbench --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-db=sbtest --time=20 --report-interval=5 oltp_read_write --tables=2 --table_size=100000 --threads=32 cleanup` to
delete the records from test database.
8 changes: 6 additions & 2 deletions mysql/mysqld.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ libos.entrypoint = "{{ entrypoint }}"
loader.log_level = "{{ log_level }}"

loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/lib:/usr/{{ arch_libdir }}"
loader.PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

loader.insecure__use_cmdline_argv = true
sys.enable_sigterm_injection = true
Expand All @@ -15,15 +14,19 @@ sgx.nonpie_binary = true
sgx.enclave_size = "8G"
sgx.thread_num = 128

loader.uid = {{ uid }}
loader.gid = {{ gid }}

fs.mounts = [
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
{ path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" },
{ path = "/usr/{{ arch_libdir }}", uri = "file:/usr/{{ arch_libdir }}" },
{ path = "/usr/sbin/mysqld", uri = "file:/usr/sbin/mysqld" },
{ path = "{{ entrypoint }}", uri = "file:{{ entrypoint }}" },
{ path = "/usr/lib/mysql", uri = "file:/usr/lib/mysql" },
{ path = "/var/lib/mysql-files", uri = "file:/var/lib/mysql-files" },
{ path = "/var/lib/mysql-keyring", uri = "file:/var/lib/mysql-keyring" },
{ path = "/var/run/mysqld", uri = "file:/var/run/mysqld" },
{ path = "/lib/mysql/plugin", uri = "file:/lib/mysql/plugin" },
{ path = "/tmp", uri = "file:/tmp" },
]

Expand All @@ -34,6 +37,7 @@ sgx.trusted_files = [
"file:{{ arch_libdir }}/",
"file:/usr/{{ arch_libdir }}/",
"file:/usr/lib/mysql/",
"file:/lib/mysql/plugin/",
]

sgx.allowed_files = [
Expand Down

0 comments on commit 209fed2

Please sign in to comment.