Use the SMF (Service Management Facility) of Solaris10 to manage MySQL (with MySQL installation)

Source: Internet
Author: User

Http://www.sun.com/bigadmin/content/submitted/mysql_smf_tip.jsp
Login ing MySQL to Use With Service Management Facility (SMF)

 

William Pool (Puddle), October 2005.

The Solaris 10 OS uses the Service Management Facility (SMF) to handleservices. Traditional means like/etc/rc ?. D scripts still work, but as a legacy means. (For more information on SMF, see the References section .)

To take advantage of the SMF in the Solaris 10 OS using MySQL, follow these steps.

Note: Read the scripts and "change" the path of MySQL or MySQL's data-directory accordingly!

If you haven't initialized the MySQL database, do that first:

/Opt/sfw/bin/mysql_install_db

This will install the database into/var/mysql to override that use:

/Opt/sfw/bin/mysql_install_db-ldata =/opt/sfw/var/mysql

Note: If you change the location, change the information below!

First create a mysql group:

/Usr/sbin/groupadd mysql

Then create the mysql user:

/Usr/sbin/useradd-s/bin/false-g mysql-d/var/mysql-c "MySQL User" mysql

Create a service manifest file:

/Var/svc/manifest/network/mysql. xml

This contains the following:

<? Xml version = '1. 0'?>
<! DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<! --

William Pool (Puddle) 02/05
Service manifest for MySQL
E-mail: puddle@flipmotion.com
-->

<Service_bundle type = 'manifest 'name = 'mysql: mysql'>

<Service
Name = 'network/mysql'
Type = 'service'
Version = '1'>
<Create_default_instance enabled = 'false'/>
<Single_instance/>

<Dependency name = 'fs'
Grouping = 'require _ all'
Restart_on = 'none'
Type = 'service'>
<Service_fmri value = 'svc:/system/filesystem/local'/>
</Dependency>

<Dependency name = 'net'
Grouping = 'require _ all'
Restart_on = 'none'
Type = 'service'>
<Service_fmri value = 'svc:/network/loopback'/>
</Dependency>

<Exec_method
Type = 'method'
Name = 'start'
Exec = '/lib/svc/method/svc-mysql start'
Timeout_seconds = '-1'>
<Method_context>
<Method_credential user = 'mysql' group = 'mysql'/>
</Method_context>
</Exec_method>

<Exec_method
Type = 'method'
Name = 'stop'
Exec = ': kill'
Timeout_seconds = '-1'>
</Exec_method>

<Exec_method
Type = 'method'
Name = 'restart'
Exec = '/lib/svc/method/svc-mysql restart'
Timeout_seconds = '-1'>
</Exec_method>

</Service>

</Service_bundle>

Now create your "Service Method File" in/lib/svc/method called svc-mysql:

#! /Usr/bin/sh
#
# William Pool (Puddle) 01/05
# SMF Method file for MySQL
# E-mail: puddle@flipmotion.com
#
# This uses Sun's default MySQL packages
# SUNWmysqlu SUNWmysqlr
#
# Modify accordingly!
#
# NOTE: Make sure DB_DIR is owned BY the mysql user and group and chmod
#700.
#

../Lib/svc/share/smf_demo.sh

DB_DIR =/var/mysql
PIDFILE =$ {DB_DIR}/'/usr/bin/uname-n'. pid

Case "$1" in
Start)
/Usr/sfw/sbin/mysqld_safe -- user = mysql -- datadir =$ {DB_DIR} -- pid-file =$ {PIDFILE}>/dev/null &
;;
Stop)
If [-f $ {PIDFILE}]; then
/Usr/bin/pkill mysqld_safe>/dev/null 2> & 1
/Usr/bin/kill 'cat $ {PIDFILE} '>/dev/null 2> & 1 & echo-n' mysqld'
Fi
;;
'Restart ')
Stop
While pgrep mysqld>/dev/null
Do
Sleep 1
Done
Start
;;
*)
Echo ""
Echo "Usage: 'basename $ 0' {start | stop | restart }"
Echo ""
Exit 64
;;
Esac

# --- EOF

Now fix the permissions for the two files created:

Chown root: bin/lib/svc/method/svc-mysql
Chmod 555/lib/svc/method/svc-mysql
Chown root: sys/var/svc/manifest/network/mysql. xml
Chmod 444/var/svc/manifest/network/mysql. xml

Fix permissions on the MySQL data directory:

Chown-R mysql: mysql/var/mysql
Chmod-R 700/var/mysql

Import the service into the service repository:

# Svccfg import/var/svc/manifest/network/mysql. xml

Enable the service:

# Svcadm-v enable mysql

 

-----------------------------------

Solaris 10 has installed MySQL. The security administrator must log on to the system as the Root user. The following steps can be found in/usr/sfw/src/mysql/Docs.

 

1. Use the root identity login to the Console mode, and upload the information in advance.

#/Usr/sfw/bin/mysql_install_db
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
060118 21:24:03/usr/sfw/sbin/mysqld: Shutdown Complete
<Snip...>

2. Create a mysql user and group, and change the group of the object.

# Groupadd mysql
# Useradd-g mysql
# Chgrp-R mysql/var/mysql
# Chmod-R 770/var/mysql
# Installf SUNWmysqlr/var/mysql d 770 root mysql

3. Set MySQL to/var/mysql/my. cnf

4. Configure MySQL settings to the logging location.

# Cp/usr/sfw/share/mysql/my-medium.cnf/var/mysql/my. cnf

5. manually activate mysql

#/Usr/sfw/sbin/mysqld_safe -- user = mysql &

. Set the MySQL root user password (new-password in the following section is the password you want. You can change it to your favorite password. For security reasons, do not use new-password as your secret for password switch. Make sure to change it)

# Cd/usr/sfw/bin
#./Mysqladmin-u root password 'new-password'
#./Mysqladmin-u root-h 'hostname' password 'new-password'

7. Too many MySQL Server

#./Mysqlshow-p
Enter password: new-password

+ ----------- +
| Databases |
+ ----------- +
| Mysql |
| Test |
+ ----------- +

#./Mysql-u root-p
Enter password: new-password

Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 3 to server version: 4.0.20-standard
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> show databases;
+ ----------- +
| Databases |
+ ----------- +
| Mysql |
| Test |
+ ----------- +
2 rows in set (0.00 sec)

Mysql> quit;
Bye

8. Set the Solaris Server to automatically run and stop the MySQL Server when the Server is active or shut down.

# Ln/etc/sfw/mysql. server/etc/rc3.d/S99mysql
# Ln/etc/sfw/mysql. server/etc/rc0.d/K00mysql
# Ln/etc/sfw/mysql. server/etc/rc1.d/K00mysql
# Ln/etc/sfw/mysql. server/etc/rc2.d/K00mysql
# Ln/etc/sfw/mysql. server/etc/rcS. d/K00mysql

9. 9. Then, run a notebook to start Solaris from the new notebook and check whether MySQL can be automatically started. Set MySQL to/var/mysql/my. cnf.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.