You are here
MyEnv Installation Guide
This article covers the installation of MyEnv, the MySQL and MariaDB environment of FromDual.
To learn more about what MyEnv is go here.
Table of Contents
- MyEnv Requirements
- Preparations for MyEnv
- Download of MyEnv
- Installation of MyEnv
- Downloading and installing database binary tar-ball
- Configuration of MyEnv
- Put MyEnv under Systemd controll
- Put a database under MyEnv control
- How MyEnv works
- Functionality
- Upgrade MyEnv
- Debugging
- Un-install MyEnv
- Frequently Asked Questions (FAQ)
MyEnv Requirements
- Currently MyEnv works on Linux (other UNIXes may work but are not tested).
- MyEnv works best with recent CentOS or Ubuntu Linux distributions.
- MyEnv is based on PHP (5.0 to 7.x).
- A dedicated user (typically
mysql
) to run the databases is required. This user must have a shell (bash is tested). - MyEnv requires the following packages:
RockyLinux, Alma Linux, Oracle Linux, Red Hat Enterprise Linux (RHEL) and CentOS
php-cli
php-mysqli
(provided by RPMphp-mysql
)php-posix
(provided by RPMphp-process
)libaio
shell> sudo dnf install php-cli php-mysqli php-posix libaio
Ubuntu and Debian
php-cli
php-mysql
libaio1
lsb-release
shell> sudo apt install php-cli php-mysql libaio1 lsb-release
OpenSUSE and SLES
php-posix
php-pcntl
php-mysql
php-sockets
shell> sudo zypper install php-posix php-pcntl php-mysql php-sockets
Preparations for MyEnv
In the file /etc/php5/cli/php.ini
or /etc/php/7.0/cli/php.ini
(Ubuntu) or /etc/php.ini
(CentOS), change the setting variables_order
to EGPCS
.
Then you have to set up the user and the group:
shell> sudo groupadd {mariadb|mysql} shell> sudo useradd -g {mariadb|mysql} -d /home/{mariadb|mysql} -m -s /bin/bash {mariadb|mysql} shell> sudo passwd {mariadb|mysql}
MyEnv runs as user {mariadb|mysql}
, just like any regular mariadbd/mysqld
process.
You might want to check, if the home directory of the user mariadb/mysql
was created at the right place. If not, you can use the following commands to create it:
shell> sudo mkdir -p /home/{mariadb|mysql} shell> sudo chown -R {mariadb|mysql}: /home/{mariadb|mysql} shell> sudo mkdir /run/mysqld /run/mariadb shell> sudo chown {mariadb|mysql}: /run/mysqld /run/mariadb
Next ist the directory where the MyEnv configuration will be located. DO NOT FORGET to give the mariadb/mysql
user read and write permission for this directory.
shell> sudo mkdir /etc/myenv/ shell> sudo chown -R {mariadb|mysql}: /etc/myenv/ shell> sudo chmod 755 /etc/myenv
Switch the user ...
shell> su - {mariadb|mysql}
... and create some more folders in his home directory:
shell> mkdir ~/product ~/database ~/download
- product is the location of the unpacked binaries. This is the location where MyEnv is looking for them by default.
- download is intended to be used as landing zone for downloads, such as fresh binary tarballs.
- database usually contains the
datadir
of the instances (more preciselyinstancedir
).
Download of MyEnv
MyEnv can be downloaded from the FromDual download page or directly over the command line:
shell> cd ~/download shell> VERSION='2.0.0' shell> wget https://support.fromdual.com/admin/download/myenv-${VERSION}.tar.gz
Once the archive has finished downloading, you can move on to the installation.
Installation of MyEnv
To install MyEnv you have to untar it. It is recommended to do that in the product
directory.
shell> cd ~/product shell> tar xf ~/download/myenv-${VERSION}.tar.gz shell> ln -s myenv-${VERSION} myenv
Downloading and installing database binary tar-ball
Before you start configuring MyEnv and a MyEnv controlled database instance it is recommended to first install the binary tar ball of your favourite flavour of MySQL/MariaDB:
For MariaDB:
Go to the MariaDB Downloads page, choose Generic Linux to find which release you want to use.
shell> cd ~/download shell> MAVERSION='10.3.12' shell> GLIBCVERSION='214' shell> wget https://downloads.mariadb.org/f/mariadb-${MAVERSION}/bintar-linux-glibc_${GLIBCVERSION}-x86_64/mariadb-${MAVERSION}-linux-glibc_${GLIBCVERSION}-x86_64.tar.gz shell> cd ~/product shell> tar xf ~/download/mariadb-${MAVERSION}-linux-glibc_${GLIBCVERSION}-x86_64.tar.gz shell> ln -s mariadb-${MAVERSION}-linux-glibc_${GLIBCVERSION}-x86_64 mariadb-${MAVERSION}
For MySQL:
Go to the Download MySQL Community Server page, choose Linux - Generic to find which release you want to use.
shell> cd ~/download shell> MYVERSION='5.7.25' shell> GLIBCVERSION='2.12' shell> wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-${MAVERSION}-linux-glibc${GLIBCVERSION}-x86_64.tar.gz shell> cd ~/product shell> tar xf ~/download/mysql-${MYVERSION}-linux-glibc${GLIBCVERSION}-x86_64.tar.gz shell> ln -s mysql-${MYVERSION}-linux-glibc${GLIBCVERSION}-x86_64 mysql-${MYVERSION}
Configuration of MyEnv
To configure MyEnv you have 2 possibilities:
- You can configure MyEnv by running the MyEnv installer:
shell> ~/product/myenv/bin/installMyEnv.php
- or you can configure MyEnv manually:
shell> echo 'export MYENV_BASE=/home/{mariadb|mysql}/product/myenv' > /etc/myenv/MYENV_BASE shell> cp ~/product/myenv/tpl/myenv.conf.template /etc/myenv/myenv.conf shell> cp ~/product/myenv/tpl/variables.conf.template /etc/myenv/variables.conf shell> cp ~/product/myenv/tpl/aliases.conf.template /etc/myenv/aliases.conf shell> cat ~/product/myenv/tpl/profile.template >> ~/.bash_profile
When you have chosen to use the MyEnv installer, follow the steps through the set-up. If you already have binaries available, you get the possibility to create a new database instance.
After each MyENV installation or configuration operation you have to run:
shell> source ~/.bash_profile
Put MyEnv under Systemd controll
shell> sudo cp ~/product/myenv/tpl/systemd.myenv.{mariadb|mysql}.unit.template /etc/systemd/system/myenv.service shell> sudo systemctl daemon-reload shell> sudo systemctl enable myenv.service Created symlink /etc/systemd/system/myenv → /etc/systemd/system/myenv.service. shell> sudo systemctl status myenv.service ● myenv.service - FromDual Environment for MySQL and MariaDB (myenv) Loaded: loaded (/etc/systemd/system/myenv.service; enabled; vendor preset: enabled) Active: inactive (dead) Docs: https://www.fromdual.com/myenv-installation-guide shell> sudo systemctl start myenv shell> sudo systemctl status myenv ● myenv.service - FromDual Environment for MySQL and MariaDB (myenv) Loaded: loaded (/etc/systemd/system/myenv.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2020-09-01 09:42:39 CEST; 4s ago Docs: https://www.fromdual.com/myenv-installation-guide Process: 19532 ExecStartPre=/bin/mkdir -p /var/run/myenv /var/run/mysqld (code=exited, status=0/SUCCESS) Process: 19533 ExecStartPre=/bin/chown mysql: /var/run/myenv /var/run/mysqld (code=exited, status=0/SUCCESS) Main PID: 19534 (myenv_start_sto) Tasks: 32 (limit: 4915) Memory: 343.7M CGroup: /system.slice/myenv.service ├─19534 /usr/bin/php -d variables_order=EGPCS /home/mysql/product/myenv/bin/myenv_start_stop.php start ├─19552 bin/mysqld --defaults-file=/home/mysql/database/monitoring/etc/my.cnf --basedir=/home/mysql/product/mysql-5.7 --datadir=/home/mysql/database/monitoring/data --user=mysql ├─19584 sh -c export LC_ALL=C ; /usr/bin/php -d variables_order=EGPCS -f /home/mysql/product/myenv-2.0.2/bin/database.php mysql-80 start 2>&1 2>/tmp/my_exec.stderr.19534 ├─19585 /usr/bin/php -d variables_order=EGPCS -f /home/mysql/product/myenv-2.0.2/bin/database.php mysql-80 start └─19595 bin/mysqld --defaults-file=/home/mysql/database/mysql-80/etc/my.cnf --basedir=/home/mysql/product/mysql-8.0 --datadir=/home/mysql/database/mysql-80/data --user=mysql Sep 01 09:42:39 boss systemd[1]: Starting FromDual Environment for MySQL and MariaDB (myenv)... Sep 01 09:42:39 boss systemd[1]: Started FromDual Environment for MySQL and MariaDB (myenv). shell> tail -f /home/{mariadb|mysql}/product/myenv/log/myenv_start_stop.log -n 1000 2020-09-01 09:42:39 Starting myenv_start_stop 2020-09-01 09:42:39 Starting instances: monitoring mysql-80 dwh mysql-57 mariadb-104 mariadb-105 mysql-8019 2020-09-01 09:42:39 Starting instance: monitoring 2020-09-01 09:42:42 Starting instance: mysql-80 2020-09-01 09:42:54 Starting instance: dwh 2020-09-01 09:42:57 Starting instance: mysql-57 2020-09-01 09:43:00 Starting instance: mariadb-104 2020-09-01 09:43:03 Starting instance: mariadb-105 2020-09-01 09:43:10 Starting instance: mysql-8019 2020-09-01 09:43:18 Finished myenv_start_stop (rc=0).
Put a database under MyEnv control
Run the MyEnv install script ~/product/myenv/bin/installMyEnv
and choose the option "a" (add instance) then follow the instructions.
Or add a section similar to the following example to the MyEnv configuration file /etc/myenv/myenv.conf
:
# # /etc/myenv/myenv.conf # [test] start = yes stop = yes hideschema = mysql,performance_schema,lost+found,sys type = mysqld basedir = /home/mysql/product/mysql-5.7 instancedir = /home/mysql/database/myenv_test datadir = /home/mysql/database/myenv_test/data user = mysql port = 3306 socket = /run/mysqld/mysql-3306.sock my.cnf = /home/mysql/database/myenv_test/etc/my.cnf angel = no cgroups = no stage = testing
How MyEnv works
It is always recommended to work as user mysql
for starting, stopping and doing maintenance work. Otherwise you run into conflicts with permissions on files, etc.
When you login as user mysql
you will get the current status of your environment (if MyEnv is installed and configured correctly):
mysql@master:~ [prodcms, 3308]> u Up : mysql-5721 (5.7.21) prodcms (10.2) Down : mysql-57 (5.7) mariadb-103 (10.3.8) mysql-4030 (4.0.30) mysql-4125 (4.1.25) mariadb-55 (5.5) galera-57-a (5.7) galera-57-b (5.7) galera-57-c (5.7) mysql-5721 (*:3311 ) : cacti mysql-57 (*:3310 ) : cluster_test test01 test02 test03 test04 mariadb-103 (*:3314 ) : typo3 mysql-4030 (*:3309 ) : test mysql-4125 (*:3313 ) : test foodmart mariadb-55 (*:3307 ) : drupal7 prodcms (*:3308 ) : drupal8 mariadb-55 (*:3312 ) : magento oxid galera-57-a (192.168.57.1:3306 ) : hybris galera-57-b (192.168.57.2:3306 ) : hybris galera-57-c (192.168.57.3:3306 ) : hybris mysql@master:~ [prodcms, 3308]>
Functionality
The most important command in MyEnv are:
<instance> : Switches to the environment for this instance. For example: shell> mariadb-103 u or up : Lists, which releases are available, which instances are up and down and which instance contains which database. For example: shell> u start : Starts the actual or a specific instance. For example: shell> start or shell> start mysql-805 stop : Stops the actual instance or a specific instance. For example: shell> stop or shell> stop mariadb-10212 restart : restarts the actual or a specific instance. For example: shell> restart or shell> restart mysql-5721 bootstrap : bootstraps a Galera node. V : print the current MyEnv version cdb : cd to the binlogdir of this instance. cdd : cd to the datadir of this instance. cde : cd to the etcdir of this instance. cdh : cd to the basedir of this instance. cdi : cd to the instancedir of this instance. cdl : cd to the logdir of this instance. cdm : cd to the myenv-directory. cdt : cd to the tmpdir of this instance. cd a b : cd to a directory with the name where a is substituted by b. For example: shell> pwd /var/lib/mysql1 shell> cd 1 2 shell> pwd /var/lib/mysql2 ll : ls -l la : ls -la mv : mv -i rm : rm -i
Some examples:
mysql@chef:~ [mariadb-103, 3318]> u Up : mariadb-102 (10.2) mysql-57 (5.7) Down : monitoring (5.7) dwh (5.7.21) mariadb-103 (10.3) monitoring (*:3319) : mem mem__advisor_text mem__advisors mem__bean_config mem__config mem__enterprise mem__events mem__instruments mem__instruments_config mem__inventory mem__quan sys zabbix mariadb-102 (*:3312 ) : test dwh (*:3325 ) : cms crm datamart download erp focmm foodmart mpm shop staging tellmatic test mariadb-103 (*:3318 ) : foodmart test world mysql-57 (*:3320 ) : FlughafenDB test test2 mysql@chef:~ [mariadb-103, 3318]> dwh mysql@chef:~ [dwh, 3325]> mysql@chef:~ [dwh, 3325]> start . SUCCESS! mysql@chef:~ [dwh, 3325]> restart .. SUCCESS! . SUCCESS! mysql@chef:~ [dwh, 3325]> stop .. SUCCESS! mysql@chef:~ [dwh, 3325]> mariadb-102 mysql@chef:~ [mariadb-102, 3312]> cdm mysql@chef:~/product/myenv [mariadb-102, 3312]> cdh mysql@chef:~/product/mariadb-10.2 [mariadb-102, 3312]> cdd mysql@chef:~/database/mariadb-102/data [mariadb-102, 3312]> cdb mysql@chef:~/database/mariadb-102/binlog [mariadb-102, 3312]> cde mysql@chef:~/database/mariadb-102/etc [mariadb-102, 3312]> cdl mysql@chef:~/database/mariadb-102/log [mariadb-102, 3312]> cd 102 103 mysql@chef:~/database/mariadb-103/log [mariadb-102, 3312]>
MyEnv works with aliases, variables and functions. With the UNIX commands alias
, env
and declare -F | grep -v '_'
you get an overview over the MyEnv functionality.
Upgrade MyEnv
Upgrading MyEnv is very easy. You can proceed as follows if you want to upgrade to a newer version of MyEnv:
shell> su - mysql shell> cd ~/download shell> VERSION='2.0.0' shell> wget https://support.fromdual.com/admin/download/myenv-${VERSION}.tar.gz shell> cd ~/product shell> tar xf ../download/myenv-${VERSION}.tar.gz shell> unlink myenv shell> ln -s myenv-${VERSION} myenv
You are basically going to to re-install MyEnv, but with a newer version.
Please also check the Release notes for specific problems.
Debugging
To enable debugging functionality, use the following command:
shell> export MYENV_DEBUG=1
To disable the debugging again, use the following command:
shell> unset MYENV_DEBUG
Feedback is always welcome! In case you found a bug or you have a feature request, please report it to the FromDual bug tracker or send us an email.
Un-install MyEnv
To un-install MyEnv again just remove the myenv section from your .bash_profile
and the ~/product/myenv
link:
shell> cd ~/product shell> sudo rm -rf myenv-x.y myenv /etc/init.d/myenv /etc/myenv
Make sure that the original start/stop script is put back in place and that the my.cnf
is at its original location.
Frequently Asked Questions (FAQ)
Question: How can I set a default instance chosen when I log in?
Answer: In the configuration file /etc/myenv/myenv.conf
you can add a default
instance in the [default]
section as follows:
# # /etc/myenv/myenv.conf # [default] default = mariadb-105
This instance leads to the following prompt and environment when logged in:
mysql@boss:~ [mariadb-105, 3306]>
Comments
Cannot find nor guess PID file
In all FromDual tools the
rc
is unique. So you can easily find where in the code the error happened. In your case it is inlib/myEnv.inc
in the functionstopInstance
.In the code we check if PID file is empty. And it is empty if it cannot be found:
my.cnf
specified inmyenv.conf
as variablepid_file
orpid-file
$datadir/mysqld.pid
$datadir/<hostname>.pid
It would be interesting for us if you could tell us where your PID file is located and where it is configured.