Skip to content

Commit c126af7

Browse files
committed
fixup! Merge branch 'mysql' of https://github.com/jkr0103/examples into mysql
Signed-off-by: Jitender Kumar <[email protected]>
1 parent 0e5d94b commit c126af7

File tree

3 files changed

+57
-59
lines changed

3 files changed

+57
-59
lines changed

mysql/Makefile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ endif
1414

1515
mysqld.manifest: mysqld.manifest.template
1616
gramine-manifest \
17-
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
18-
-Darch_libdir=$(ARCH_LIBDIR) \
19-
-Dentrypoint=$(realpath $(shell sh -c "command -v mysqld")) \
20-
$< >$@
17+
-Dlog_level=$(GRAMINE_LOG_LEVEL) \
18+
-Darch_libdir=$(ARCH_LIBDIR) \
19+
-Dentrypoint=$(realpath $(shell sh -c "command -v mysqld")) \
20+
$< >$@
2121

22-
mysqld.manifest.sgx: mysqld.manifest
22+
# Make on Ubuntu <= 20.04 doesn't support "Rules with Grouped Targets" (`&:`),
23+
# for details on this workaround see
24+
# https://github.com/gramineproject/gramine/blob/e8735ea06c/CI-Examples/helloworld/Makefile
25+
mysqld.manifest.sgx mysqld.sig: sgx_sign
26+
@:
27+
28+
.INTERMEDIATE: sgx_sign
29+
sgx_sign: mysqld.manifest
2330
gramine-sgx-sign \
24-
--manifest $< \
25-
--output $@
31+
--manifest $< \
32+
--output $<.sgx
2633

2734
mysqld.token: mysqld.sig
2835
gramine-sgx-get-token --output $@ --sig $<

mysql/README.md

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,52 @@
1-
# Mysql example
2-
# This example is tested with mysql Ver 8.0.29
1+
# MySQL example
2+
This example is tested with MySQL version 8.0.29.
33

4-
This directory contains an example for running Mysql-Server in Gramine, including
4+
This directory contains an example for running Mysql server in Gramine, including
55
the Makefile and a template for generating the manifest.
66

7-
# Prerequisites Steps
7+
# Pre-requisites
88

9-
## Install mysql-server on baremetal:
10-
sudo apt-get install mysql-server
9+
- `sudo apt-get install mysql-server` to install MySQL server.
10+
- Comment out the log line `log_error = /var/log/mysql/error.log` in the config file
11+
`/etc/mysql/mysql.conf.d/mysqld.cnf` to see the log on console.
12+
- `systemctl stop mysql.service` to stop the default MySQL service .We will manually
13+
run MySQL process.
14+
- `sudo mkdir /var/run/mysqld && sudo chown -R <current_user>:<current_user> /var/run/mysqld`
15+
to allow MySQL server to create socket file `mysqld.sock`.
16+
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-files` to allow MySQL server for
17+
internal usage.
18+
- `sudo chown -R <current_user>:<current_user> /var/lib/mysql-keyring` to allow MySQL server for
19+
internal usage.
20+
- `mysqld --initialize-insecure --datadir=mysql-data/` to initialize data directory.
1121

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

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

21-
## Prepare new data directory:
22-
sudo mkdir /tmp/mysql && sudo chown -R <current_user>:<current_user> /tmp/mysql
27+
# Run
2328

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

28-
## Restart apparmor:
29-
sudo service apparmor restart
31+
- Natively: `mysqld --datadir /tmp/mysql`.
32+
- Gramine w/o SGX: `gramine-direct mysqld -u root --datadir /tmp/mysql`.
33+
- Gramine with SGX: `gramine-sgx mysqld -u root --datadir /tmp/mysql`.
3034

31-
## Initialize mysql:
32-
mysqld --initialize-insecure --datadir=/tmp/mysql
33-
sudo rm /tmp/mysql/undo*
35+
# Testing client connection and running sysbench benchmarking
3436

35-
# Generating the manifest
37+
Run below command from new terminal:
3638

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

39-
## Building for Linux
42+
Run Sysbench benchmarking:
4043

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

43-
## Building for SGX
44-
45-
Run `make SGX=1` (non-debug) or `make SGX=1 DEBUG=1` (debug) in the directory.
46-
47-
# Run Mysql with Gramine
48-
49-
Here's an example of running Mysql under Gramine:
50-
51-
Without SGX:
52-
```
53-
gramine-direct mysqld -u root --datadir /tmp/mysql
54-
```
55-
56-
With SGX:
57-
```
58-
gramine-sgx mysqld -u root --datadir /tmp/mysql
59-
```
47+
- `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
48+
create records in test database.
49+
- `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
50+
run the sysbench benchmarks.
51+
- `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
52+
delete the records from test database.

mysql/mysqld.manifest.template

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
# mysql manifest example
2-
loader.preload = "file:{{ gramine.libos }}" # for compatibility with v1.0
1+
# MySQL manifest example
32

43
loader.entrypoint = "file:{{ gramine.libos }}"
54
libos.entrypoint = "{{ entrypoint }}"
65

76
loader.log_level = "{{ log_level }}"
87

98
loader.env.LD_LIBRARY_PATH = "/lib:{{ arch_libdir }}:/usr/lib:/usr/{{ arch_libdir }}"
10-
loader.env.PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
9+
loader.PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
1110

1211
loader.insecure__use_cmdline_argv = true
1312
sys.enable_sigterm_injection = true
1413

1514
sgx.nonpie_binary = true
16-
sgx.enclave_size = "4G"
17-
sys.stack.size = "16M"
18-
sgx.thread_num = 64
15+
sgx.enclave_size = "8G"
16+
sgx.thread_num = 128
1917

2018
fs.mounts = [
2119
{ path = "/lib", uri = "file:{{ gramine.runtimedir() }}" },
2220
{ path = "{{ arch_libdir }}", uri = "file:{{ arch_libdir }}" },
2321
{ path = "/usr/{{ arch_libdir }}", uri = "file:/usr/{{ arch_libdir }}" },
24-
{ path = "/usr", uri = "file:/usr" },
22+
{ path = "/usr/sbin/mysqld", uri = "file:/usr/sbin/mysqld" },
23+
{ path = "/usr/lib/mysql", uri = "file:/usr/lib/mysql" },
2524
{ path = "/var/lib/mysql-files", uri = "file:/var/lib/mysql-files" },
2625
{ path = "/var/lib/mysql-keyring", uri = "file:/var/lib/mysql-keyring" },
2726
{ path = "/var/run/mysqld", uri = "file:/var/run/mysqld" },
@@ -35,7 +34,6 @@ sgx.trusted_files = [
3534
"file:{{ arch_libdir }}/",
3635
"file:/usr/{{ arch_libdir }}/",
3736
"file:/usr/lib/mysql/",
38-
"file:/usr/share/mysql-8.0/",
3937
]
4038

4139
sgx.allowed_files = [

0 commit comments

Comments
 (0)