Lancer plusieurs instances de MySQL sur Solaris

From Deimos.fr / Bloc Notes Informatique
Jump to: navigation, search

1 Installation

Télécharger MySQL

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.41-solaris10-x86_64.pkg.gz/from/http://mir2.ovh.net/ftp.mysql.com/

Créer l'utilisateur MySQL

groupadd mysql
useradd -g mysql -s /bin/false -d /var/empty mysql

Vérifier que l'utilisateur est bien crée

# finger mysql
Login name: mysql
Directory: /var/empty                   Shell: /bin/sh
Never logged in.
No unread mail
No Plan. 

décompresser l'archive de MySQL puis l'installer

gunzip mysql-5.1.41-solaris10-x86_64.pkg.gz
pkgadd -d mysql-5.1.41-solaris10-x86_64.pkg

2 Configuration

2.1 my.cnf

Créer 2 fichiers de conf bien distinct en changeant :

  • le nom du fichier
  • le port
  • le socket
  • le datadir

exemple : /etc/my-prod.cnf

# The MySQL server
[mysqld]
port            = 3307
socket          = /var/lib/mysql/mysql-prod.sock
datadir = /mnt/ulprod-ld_mysql/databases
log-bin = /mnt/ulprod-ld_mysql/logs/mysql-bin
pid-file = /mnt/ulprod-ld_mysql/mysql-prod.pid
skip-locking
key_buffer = 64M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M 
myisam_sort_buffer_size = 128M
thread_cache_size = 8
query_cache_size = 128M
query_cache_limit = 2M
thread_concurrency = 8
skip-name-resolve
innodb_data_file_path=ibdata1:10M:autoextend
innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_home_dir = /mnt/ulprod-ld_mysql/
innodb_log_group_home_dir = /mnt/ulprod-ld_mysql/
innodb_file_per_table
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
default-storage_engine=InnoDB
thread_cache_size = 16
slow_query_log = 1
long_query_time = 1
skip-federated
server-id       = 1
#log-bin=mysql-bin
#sync_binlog = 1
 
[mysqldump]
quick
max_allowed_packet = 16M
 
[mysql]
no-auto-rehash
 
[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
 
[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
 
[mysqlhotcopy]
interactive-timeout

exemple : /etc/my-dr.cnf

# The MySQL server
[mysqld]
port            = 3306
socket          = /var/lib/mysql/mysql-dr.sock
datadir = /mnt/ulprod-pa_mysql/databases
log-bin = /mnt/ulprod-pa_mysql/logs/mysql-bin
pid-file = /mnt/ulprod-pa_mysql/mysql-dr.pid
skip-locking
key_buffer = 64M
max_allowed_packet = 1M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M 
myisam_sort_buffer_size = 128M
thread_cache_size = 8
query_cache_size = 128M
query_cache_limit = 2M
thread_concurrency = 8
skip-name-resolve
innodb_data_file_path=ibdata1:10M:autoextend
innodb_buffer_pool_size = 2048M
innodb_additional_mem_pool_size = 20M
innodb_data_home_dir = /mnt/ulprod-pa_mysql/
innodb_log_group_home_dir = /mnt/ulprod-pa_mysql/
innodb_file_per_table
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
default-storage_engine=InnoDB
thread_cache_size = 16
slow_query_log = 1
long_query_time = 1
skip-federated
server-id       = 1
#log-bin=mysql-bin
#sync_binlog = 1
 
[mysqldump]
quick
max_allowed_packet = 16M
 
[mysql]
no-auto-rehash
 
[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
 
[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
 
[mysqlhotcopy]
interactive-timeout

puis créer le fichier de conf client afin de forcer l'utilisation du protocol TCP plutot que du socket local

exemple : /etc/my.cnf

[client]
protocol        = tcp

2.2 Initialisation des bases

Créer les répertoires pour les databases et pour les logs

mkdir /mnt/ulprod-ld_mysql/{databases,logs}
mkdir /mnt/ulprod-pa_mysql/{databases,logs}

Initialiser les bases MySQL

/opt/mysql/mysql/scripts/mysql_install_db --user=mysql --ldata=/mnt/ulprod-ld_mysql/databases
/opt/mysql/mysql/scripts/mysql_install_db --user=mysql --ldata=/mnt/ulprod-pa_mysql/databases

2.3 Script de start

faire une copie du script de start pour chaque instance

mkdir /opt/mysql/mysql/share/mysql
cp /opt/mysql/mysql/support-files/mysql.server /opt/mysql/mysql/share/mysql/mysql.server-prod
cp /opt/mysql/mysql/support-files/mysql.server /opt/mysql/mysql/share/mysql/mysql.server-dr

Editer chacun de ces script et modifiez la ligne :

$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &

En spécifiant le fichier de conf a utiliser, et en supprimant "--datadir=$datadir" et "--pid-file=$server_pid_file" ce qui devrait donner ceci pour le fichier "mysql.server-prod" :

$bindir/mysqld_safe --defaults-file=/etc/my-prod.cnf $other_args >/dev/null 2>&1 &

et ceci pour "mysql.server-dr" :

$bindir/mysqld_safe --defaults-file=/etc/my-dr.cnf $other_args >/dev/null 2>&1 &

Commenter également la ligne "datadir="

#datadir=/var/lib/mysql

Definir la variable "server_pid_file=" en spécifiant le fichier PID defini dans la conf. par exemple :

server_pid_file=/mnt/ulprod-pa_mysql/mysql-uat.pid

Definir la variable "extra_args=" en spécifiant le fichier de conf. par exemple :

extra_args="-c /etc/my-uat.cnf"

2.4 Fichier SMF

Créer 2 fichiers SMF avec 2 noms differents et modifier la ligne "exec" pour qu'elle fasse appel au bon script :

exemple : /var/svc/manifest/application/database/mysql-prod.xml

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
    Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
    Use is subject to license terms.
    MySQL.xml : MySQL manifest, Scott Fehrman, Systems Engineer
    updated: 2005-09-16
-->
 
<service_bundle type='manifest' name='MySQL Prod'>
<service name='application/database/mysql-prod' type='service' version='1'>
 
<single_instance />
 
    <dependency
        name='filesystem'
        grouping='require_all'
        restart_on='none'
        type='service'>
        <service_fmri value='svc:/system/filesystem/local' />
    </dependency>
 
    <exec_method
        type='method'
        name='start'
        exec='/opt/mysql/mysql/share/mysql/mysql.server-prod start'
        timeout_seconds='120' />
 
    <exec_method
        type='method'
        name='stop'
        exec='/opt/mysql/mysql/share/mysql/mysql.server-prod stop'
        timeout_seconds='120' />
 
    <instance name='default' enabled='false' />
 
    <stability value='Unstable' />
 
    <template>
        <common_name>
            <loctext xml:lang='C'>MySQL Prod RDBMS 5.0.19</loctext>
        </common_name>
        <documentation>
            <manpage title='mysql' section='1' manpath='/opt/mysql/mysql/man' />
        </documentation>
    </template>
 
</service>
</service_bundle>

exemple : /var/svc/manifest/application/database/mysql-dr.xml

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
    Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
    Use is subject to license terms.
    MySQL.xml : MySQL manifest, Scott Fehrman, Systems Engineer
    updated: 2005-09-16
-->
 
<service_bundle type='manifest' name='MySQL DR'>
<service name='application/database/mysql-dr' type='service' version='1'>
 
<single_instance />
 
    <dependency
        name='filesystem'
        grouping='require_all'
        restart_on='none'
        type='service'>
        <service_fmri value='svc:/system/filesystem/local' />
    </dependency>
 
    <exec_method
        type='method'
        name='start'
        exec='/opt/mysql/mysql/share/mysql/mysql.server-dr start'
        timeout_seconds='120' />
 
    <exec_method
        type='method'
        name='stop'
        exec='/opt/mysql/mysql/share/mysql/mysql.server-dr stop'
        timeout_seconds='120' />
 
    <instance name='default' enabled='false' />
 
    <stability value='Unstable' />
 
    <template>
        <common_name>
            <loctext xml:lang='C'>MySQL DR RDBMS 5.0.19</loctext>
        </common_name>
        <documentation>
            <manpage title='mysql' section='1' manpath='/opt/mysql/mysql/man' />
        </documentation>
    </template>
 
</service>
</service_bundle>

2.5 Validation des SMF

Faire valider les services avec la commande suivante :

svccfg validate /var/svc/manifest/application/database/mysql-prod.xml
svccfg validate /var/svc/manifest/application/database/mysql-dr.xml

si la commande ne retourne rien, c'est que tout est parfait!

On importe ensuite les scripts XML :

svccfg import /var/svc/manifest/application/database/mysql-prod.xml
svccfg import /var/svc/manifest/application/database/mysql-dr.xml

puis pour valider on vérifie que les services sont bien present :

svcs mysql-prod
svcs mysql-dr

enfin on met les bon droits

chown -Rf mysql: /mnt/ulprod-pa_mysql
chown -Rf mysql: /mnt/ulprod-ld_mysql
chmod -Rf 700 /mnt/ulprod-pa_mysql
chmod -Rf 700 /mnt/ulprod-ld_mysql

2.6 Démarrage

Il ne reste plus qu'a activer le service

svcadm enable mysql-prod
svcadm enable mysql-dr