Difference between revisions of "Docker - How to run Sybase ASE in a container"

From SybaseWiki
Jump to: navigation, search
m (Create the dontainer)
(For data)
 
Line 44: Line 44:
 
Run the centos image and start a bash shell. Make a note of the container id that is shown at the prompt.
 
Run the centos image and start a bash shell. Make a note of the container id that is shown at the prompt.
 
  docker run -t -i centos /bin/bash
 
  docker run -t -i centos /bin/bash
 +
 +
Sample output:
 +
docker run -t -i centos /bin/bash
 +
[root@2d0c8aae3341 /]#
 +
In this case the container id is 2d0c8aae3341.
  
 
  yum update
 
  yum update

Latest revision as of 20:35, 17 November 2015

This page will show you how SAP Sybase ASE (version 16.0 GA PL01) can be run in a docker container. You will also see how to work with docker images, containters and volumes.

All tests have been carried out on a Linux Centos 7 environment, I expect little to no change if you need to run it on Redhat. You need about 10 Gb of free space to install the Sybase software, database devices, etc. Beware that you need to split this free space into several separately mounted filesystems.

The Sybase ASE server will be called "ASE1".

No performance optimization has been done for docker nor for Sybase.

Unless otherwise noted, all commands need to be run under "root".

Prepare the system

Prepare your system to run docker and create the sybase user.

Package update

Under Centos / Redhat 7 firewalld can conflict with docker so we will remove it from the system.

yum remove firewalld

Make sure you have the latest patches installed. Reboot if a new kernel has been downloaded.

yum update
reboot

Add sybase user and group

Docker data volumes are separate filesystems on the Linux and are made available in a docker container. The sybase processes running in these containers must have the same uid/guid for the sybase user as on the host system (your Centos / Redhat server). Keep the uid/gid for the sybase user everywhere the same.

groupadd sybase -g <free-number>
useradd -u <free-number> -g sybase sybase

Initial docker setup

Install docker, start it, and have it started when the Linux server boots.

yum install docker
systemctl start docker
systemctl enable docker

If you run "docker images" you can see the available images. Download a basic docker image for centos.

docker images
docker pull centos
docker images

Create 2 docker images customized for Sybase

We will create 2 new docker images based on the centos image that has been downloaded previously. The first image will be used to store data (database devices, dump files) and the second image is used to run the Sybase processes. It is technically possible to use just 1 image.

For data

Run the centos image and start a bash shell. Make a note of the container id that is shown at the prompt.

docker run -t -i centos /bin/bash

Sample output:

docker run -t -i centos /bin/bash
[root@2d0c8aae3341 /]#

In this case the container id is 2d0c8aae3341.

yum update

Add the sybase group and user making sure that the uid and gid match with the host

groupadd sybase -g <number>
useradd -u <number> -g sybase sybase
exit

Create a new image based on the actions we have made

docker commit -m "sybase data image" -a "Peter Sap" <container-ID> sybase_data/centos:v1
docker images

For the Sybase processes

Run the centos image once more to install the additional packages that are required to run Sybase processes.

docker run -t -i centos /bin/bash
yum update
yum install glibc.i686 libaio
groupadd sybase -g <free-number>
useradd -u <free-number> -g sybase sybase
exit
docker commit -m "sybase server image" -a "Peter Sap" <2nd container-ID> sybase_server/centos:v1
docker images

Setup storage

In the test case that I have used a disk of 10 Gb was available at /dev/sdb. Modify all storage related instructions to your specific environment.

pvcreate /dev/sdb
vgcreate docker_vg /dev/sdb

Create the docker container for the database files

Setup storage

Create a filesystem of 2 Gb for the database files. Consider this as a bare minumum not sized for user databases nor for database dump files.

lvcreate -L 2G -n ASE1_data docker_vg
mkfs /dev/docker_vg/ASE1_data
mkdir /ASE1_data
mount /dev/docker_vg/ASE1_data /ASE1_data
chown sybase:sybase /ASE1_data

Create a Dockerfile and the image

mkdir -p /var/docker_projects/sybase_data
vi /var/docker_projects/sybase_data/Dockerfile
# Dockerfile for sybase data volume containers
FROM sybase_data/centos:v1
MAINTAINER peter@petersap.nl
USER sybase

Build the image

docker build -t="sybase/data:v1" /var/docker_projects/sybase_data

Create the container

docker create --privileged=true -v /ASE1_data:/ASE1_data --name=ASE1_data -t -i sybase/data:v1

Create the container for the Sybase software

Setup storage

Create a filesystem of 6 Gb for the Sybase software.

lvcreate -L 6G -n sybase-ase160.22544 docker_vg
mkfs /dev/docker_vg/sybase-ase160.22544
mkdir /sybase-ase160.22544
mount /dev/docker_vg/sybase-ase160.22544 /sybase-ase160.22544
chown sybase:sybase /sybase-ase160.22544

Install the Sybase software

su - sybase
cd /sybase-ase160.22544

Copy the Sybase software into the current directory

scp <user>@<server>:<directory>/EBF22544.tgz .
tar -xf EBF22544.tgz
rm EBF22544.tgz
cd ebf22544

Run the installer, install the software in /sybase-ase160.22544. Do not configure any of the products.

./setup.bin
cd ..
rm -Rf ebf22544

Type exit to go back to root

exit

Create the container

Note that we use the "sybase/data:v1" image again, as we did when the container for the database files was created.

docker create --privileged=true -v /sybase-ase160.22544:/sybase-ase160.22544 --name=ase160.22544 -t -i sybase/data:v1

Create the container to run Sybase ASE

Setup storage

Create a filesystem of 2 Gb to store the errorlog files, startup scripts, etc.

lvcreate -L 2G -n ASE1_server docker_vg
mkfs /dev/docker_vg/ASE1_server
mkdir /ASE1_server
mount /dev/docker_vg/ASE1_server /ASE1_server
chown sybase:sybase /ASE1_server

Create a Dockerfile

mkdir -p /var/docker_projects/sybase_server
vi /var/docker_projects/sybase_server/Dockerfile
# Dockerfile for sybase server containers
FROM sybase_server/centos:v1
MAINTAINER peter@petersap.nl
USER sybase

Build the image

docker build -t="sybase/server:v1" /var/docker_projects/sybase_server

Create the container

Change the ip-address 10.0.0.29 to match your own environment. The port numbers 5000 can also be changed. Remember to make the same changes later on.

As you can see below, the "docker create" statement references to the containers that have already been created, using the --volumes-from option.

docker create --hostname=ASE1_server --publish=10.0.0.29:5000:5000 --privileged=true --volumes-from ASE1_data --volumes-from ase160.22544 -v /ASE1_server:/ASE1_server --name=ASE1_server -t -i sybase/server:v1

Build the Sybase ASE server

At this point we have created the containers for the Sybase software (with the software installed), a container for the database devices and a container to run ASE. Now we will start the container for running ASE and build the Sybase server.

Start the container

docker start --attach=true --interactive=true ASE1_server

You should get a bash shell while running the container.

Source in the Sybase environment variables.

. /sybase-ase160.22544/SYBASE.sh

Create a resource file

Create a resource file for building ASE

cd /ASE1_server
vi ASE1.rs
sybinit.release_directory: USE_DEFAULT
sybinit.product: sqlsrv
sqlsrv.server_name: ASE1
sqlsrv.sa_password: secret123
sqlsrv.new_config: yes
sqlsrv.do_add_server: yes
sqlsrv.network_protocol_list: tcp
sqlsrv.network_hostname_list: ASE1_server
sqlsrv.network_port_list: 5000
sqlsrv.application_type: USE_DEFAULT
sqlsrv.server_page_size: USE_DEFAULT
sqlsrv.force_buildmaster: no
sqlsrv.master_device_physical_name: /ASE1_data/master.dat
sqlsrv.master_device_size: USE_DEFAULT
sqlsrv.master_database_size: USE_DEFAULT
sqlsrv.errorlog: /ASE1_server/ASE1.errorlog
sqlsrv.do_upgrade: no
sqlsrv.sybsystemprocs_device_physical_name: /ASE1_data/sybsystemprocs.dat
sqlsrv.sybsystemprocs_device_size: USE_DEFAULT
sqlsrv.sybsystemprocs_database_size: USE_DEFAULT
sqlsrv.sybsystemdb_device_physical_name: /ASE1_data/sybsystemdb.dat
sqlsrv.sybsystemdb_device_size: USE_DEFAULT
sqlsrv.sybsystemdb_database_size: USE_DEFAULT
sqlsrv.tempdb_device_physical_name: /ASE1_data/tempdb.dat
sqlsrv.tempdb_device_size: USE_DEFAULT
sqlsrv.tempdb_database_size: USE_DEFAULT
sqlsrv.default_backup_server: SYB_BACKUP
#sqlsrv.addl_cmdline_parameters: PUT_ANY_ADDITIONAL_COMMAND_LINE_PARAMETERS_HERE
sqlsrv.do_configure_pci: no
sqlsrv.sybpcidb_device_physical_name: PUT_THE_PATH_OF_YOUR_SYBPCIDB_DATA_DEVICE_HERE
sqlsrv.sybpcidb_device_size: USE_DEFAULT
sqlsrv.sybpcidb_database_size: USE_DEFAULT
# If sqlsrv.do_optimize_config is set to yes, both sqlsrv.avail_physical_memory and sqlsrv.avail_cpu_num need to be set.
sqlsrv.do_optimize_config: no
sqlsrv.avail_physical_memory: PUT_THE_AVAILABLE_PHYSICAL_MEMORY_FOR_ASE_IN_OPTIMIZATION
sqlsrv.avail_cpu_num: PUT_THE_AVAILABLE_NUMBER_CPU_FOR_ASE_IN_OPTIMIZATION

Build ASE1

srvbuildres -r ASE1.rs

Add an extra entry to the interfaces file to allow ASE to connect to the backupserver that will be running in another container. Remember to make changes to the ip-address and port number where needed.

vi $SYBASE/interfaces

Add these lines

SYB_BACKUP_docker
       query tcp ether 10.0.0.29 5001

Modify the corresponding entry in ASE. Also, configure "console logging" to capture the ASE errorlog inside the log file of the running container.

isql -Usa -Psecret123 -SASE1
sp_addserver SYB_BACKUP,null,SYB_BACKUP_docker
go
sp_configure 'enable console logging',1
go
exit

Create a start script

Create a script that will start ASE1 when the docker container is kicked off.

cd /ASE1_server
vi start_ASE1.sh
#!/bin/sh

# Source in the Sybase environment variables

. /sybase-ase160.22544/SYBASE.sh

# Start ASE1
${SYBASE}/${SYBASE_ASE}/install/RUN_ASE1
RET=$?

exit ${RET}
chmod +x start_ASE1.sh
exit

You should now be back at the root prompt of your Linux centos/redhat host.

Create a new container that will kick off ASE1 when the container starts

As you have seen above, if you start the container you will get a bash prompt. Now we need to build the container once more with the ENTRYPOINT clause in the Dockerfile so start script is executed where container ASE1_server is started.

Create a Dockerfile

mkdir -p /var/docker_projects/ASE1_server
cp /var/docker_projects/sybase_server/Dockerfile /var/docker_projects/ASE1_server

Add this line to the new Dockerfile (/var/docker_projects/ASE1_server/Dockerfile)

ENTRYPOINT /ASE1_server/start_ASE1.sh

Create image and container

docker build -t="sybase/ase1:v1" /var/docker_projects/ASE1_server
docker rm ASE1_server
docker create --hostname=ASE1_server --publish=10.0.0.29:5000:5000 --privileged=true --volumes-from ASE1_data --volumes-from ase160.22544 -v /ASE1_server:/ASE1_server --name=ASE1_server -t -i sybase/ase1:v1

Start the container to run ASE1

docker start ASE1_server

Run "docker ps" to see the container running. If it is not running do "docker logs ASE1_server".

docker ps

Build the Sybase backup server

Create the container

docker create --hostname=ASE1_BCK_server --publish=10.0.0.29:5001:5001 --privileged=true --volumes-from ASE1_server --name=ASE1_BCK_server -t -i sybase/server:v1

Build the Sybase backup server

docker start --attach=true --interactive=true ASE1_BCK_server
. /sybase-ase160.22544/SYBASE.sh
cd /ASE1_server
vi SYB_BACKUP.rs
sybinit.release_directory: USE_DEFAULT
sybinit.product: bsrv
bsrv.server_name: SYB_BACKUP
bsrv.new_config: yes
bsrv.do_add_backup_server: yes
bsrv.do_upgrade: no
bsrv.network_protocol_list: tcp
bsrv.network_hostname_list: ASE1_BCK_server
bsrv.network_port_list: 5001
bsrv.allow_hosts_list: +
bsrv.language: USE_DEFAULT
bsrv.character_set: USE_DEFAULT
bsrv.tape_config_file: USE_DEFAULT
bsrv.errorlog: /ASE1_server/SYB_BACKUP.errorlog
sqlsrv.related_sqlsrvr: ASE1
sqlsrv.sa_login: sa
sqlsrv.sa_password: secret123
#bsrv.addl_cmdline_parameters: PUT_ANY_ADDITIONAL_COMMAND_LINE_PARAMETERS_HERE
srvbuildres -r SYB_BACKUP.rs

Create a start script

Create a script that will start the backup server when the docker container is started

vi start_ASE1_BCK.sh
#!/bin/sh

# Source in the Sybase environment variables

. /sybase-ase160.22544/SYBASE.sh

# Start ASE1_BCK
${SYBASE}/${SYBASE_ASE}/install/RUN_SYB_BACKUP
RET=$?

exit ${RET}
chmod +x start_ASE1_BCK.sh
exit

Create a new container that will kick off ASE1_BCK when the container starts

mkdir -p /var/docker_projects/ASE1_BCK_server
cp /var/docker_projects/sybase_server/Dockerfile /var/docker_projects/ASE1_BCK_server

Add this line to the new Dockerfile (/var/docker_projects/ASE1_BCK_server/Dockerfile)

ENTRYPOINT /ASE1_server/start_ASE1_BCK.sh

Create a new image and a new container, remember to change the ip-address and the port number.

docker build -t="sybase/ase1_bck:v1" /var/docker_projects/ASE1_BCK_server
docker rm ASE1_BCK_server
docker create --hostname=ASE1_BCK_server --publish=10.0.0.29:5001:5001 --privileged=true --volumes-from ASE1_server --name=ASE1_BCK_server -t -i sybase/ase1_bck:v1
docker start ASE1_BCK_server

How to manage the Sybase instances

Sybase ASE and backup server can be stopped and started with docker commands

docker start ASE1_server
docker start ASE1_BCK_server
docker ps
docker stop ASE1_server
docker stop ASE1_BCK_server

If you run the "shutdown" command in Sybase ASE the server will stop and the docker container will also end. Same for the backup server if you run "shutdown SYB_BACKUP" in ASE.

If for some reason a server will not start (or crashes) you can examine the console log file

docker logs ASE1_server

All the Sybase files are also accesable on the Linux (centos/Redhat) host so if a container will not start anymore you can still make changes to the configuration.

Wrapping up

add to /etc/fstab

Add the filesystems to /etc/fstab

/dev/docker_vg/sybase-ase160.22544 /sybase-ase160.22544 ext2 defaults 0 0
/dev/docker_vg/ASE1_data /ASE1_data ext2 defaults 0 0
/dev/docker_vg/ASE1_server /ASE1_server ext2 defaults 0 0