Skip to content

Commit

Permalink
fixup! Merge branch 'mysql' of https://github.com/jkr0103/examples in…
Browse files Browse the repository at this point in the history
…to mysql

Signed-off-by: Jitender Kumar <jitender.kumar@intel.com>
  • Loading branch information
jkr0103 committed Jun 14, 2022
1 parent 0e5d94b commit c126af7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 59 deletions.
21 changes: 14 additions & 7 deletions mysql/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ endif

mysqld.manifest: mysqld.manifest.template
gramine-manifest \
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
-Darch_libdir=$(ARCH_LIBDIR) \
-Dentrypoint=$(realpath $(shell sh -c "command -v mysqld")) \
$< >$@
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
-Darch_libdir=$(ARCH_LIBDIR) \
-Dentrypoint=$(realpath $(shell sh -c "command -v mysqld")) \
$< >$@

mysqld.manifest.sgx: mysqld.manifest
# Make on Ubuntu <= 20.04 doesn't support "Rules with Grouped Targets" (`&:`),
# for details on this workaround see
# https://github.com/gramineproject/gramine/blob/e8735ea06c/CI-Examples/helloworld/Makefile
mysqld.manifest.sgx mysqld.sig: sgx_sign
@:

.INTERMEDIATE: sgx_sign
sgx_sign: mysqld.manifest
gramine-sgx-sign \
--manifest $< \
--output $@
--manifest $< \
--output $<.sgx

mysqld.token: mysqld.sig
gramine-sgx-get-token --output $@ --sig $<
Expand Down
81 changes: 37 additions & 44 deletions mysql/README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,52 @@
# Mysql example
# This example is tested with mysql Ver 8.0.29
# 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.

# Prerequisites Steps
# Pre-requisites

## Install mysql-server on baremetal:
sudo apt-get install mysql-server
- `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
`/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
run MySQL process.
- `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.

## Comment log in /etc/mysql/mysql.conf.d/mysqld.cnf to see the logs on console:
#log_error = /var/log/mysql/error.log
# Build

## Stop mysql service, we need to manually run mysql with mysqld:
systemctl stop mysql.service
sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld
sudo chown -R <current_user>:<current_user> /var/lib/mysql-files
sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring
Run `make` to build the non-SGX version and `make SGX=1` to build the SGX
version.

## Prepare new data directory:
sudo mkdir /tmp/mysql && sudo chown -R <current_user>:<current_user> /tmp/mysql
# Run

## Add the following 2 lines to /etc/apparmor.d/usr.sbin.mysqld:
/tmp/mysql r,
/tmp/mysql/** rwk,
Execute any one of the following commands to run the workload:

## Restart apparmor:
sudo service apparmor restart
- 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`.

## Initialize mysql:
mysqld --initialize-insecure --datadir=/tmp/mysql
sudo rm /tmp/mysql/undo*
# Testing client connection and running sysbench benchmarking

# Generating the manifest
Run below command from new terminal:

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

## Building for Linux
Run Sysbench benchmarking:

Run `make` (non-debug) or `make DEBUG=1` (debug) in the directory.
- `sudo apt install -y sysbench` to install sysbench.
- `sudo mysqladmin -h 127.0.0.1 -P 3306 create sbtest` to create test database.

## Building for SGX

Run `make SGX=1` (non-debug) or `make SGX=1 DEBUG=1` (debug) in the directory.

# Run Mysql with Gramine

Here's an example of running Mysql under Gramine:

Without SGX:
```
gramine-direct mysqld -u root --datadir /tmp/mysql
```

With SGX:
```
gramine-sgx mysqld -u root --datadir /tmp/mysql
```
- `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.
- `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.
14 changes: 6 additions & 8 deletions mysql/mysqld.manifest.template
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# mysql manifest example
loader.preload = "file:{{ gramine.libos }}" # for compatibility with v1.0
# MySQL manifest example

loader.entrypoint = "file:{{ gramine.libos }}"
libos.entrypoint = "{{ entrypoint }}"

loader.log_level = "{{ log_level }}"

loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/lib:/usr/{{ arch_libdir }}"
loader.env.PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
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

sgx.nonpie_binary = true
sgx.enclave_size = "4G"
sys.stack.size = "16M"
sgx.thread_num = 64
sgx.enclave_size = "8G"
sgx.thread_num = 128

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", uri = "file:/usr" },
{ path = "/usr/sbin/mysqld", uri = "file:/usr/sbin/mysqld" },
{ 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" },
Expand All @@ -35,7 +34,6 @@ sgx.trusted_files = [
"file:{{ arch_libdir }}/",
"file:/usr/{{ arch_libdir }}/",
"file:/usr/lib/mysql/",
"file:/usr/share/mysql-8.0/",
]

sgx.allowed_files = [
Expand Down

0 comments on commit c126af7

Please sign in to comment.