Selasa, 27 Oktober 2009

Instalasi Mysql 5.1.34 di solaris 10


Terusik dengan performa MySQL di solaris 10. Pagi ini sebelum beraktifikas, ditemani mesin X4150 dan external storage, saatnya merajut script ruwet.

Tidak semulus yang dibayangkan namun mudah


download mysql-5.1.34-solaris10-x86_64.tar.gz bisa dicari di download mysql.

taruh di /export/home

cd /export/home
gunzip mysql-5.1.34-solaris10-x86_64.tar.gz
tar -xvf mysql-5.1.34-solaris10-x86_64.tar
groupadd mysql
useradd -g mysql mysql
mv mysql-5.1.34-solaris10-x86_64 mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data

kemudian cek dengan

root@sbypoc # bin/mysqld_safe --user=mysql &
[1] 634
root@sbypoc # 091027 12:54:37 mysqld_safe Logging to '/export/home/mysql/data/sbypoc.err'.
091027 12:54:37 mysqld_safe Starting mysqld daemon with databases from /export/home/mysql/data

root@sbypoc #ps -ef|grep mysql
root 634 393 0 12:54:37 pts/4 0:00 /bin/sh bin/mysqld_safe --user=mysql


sekarang menancapkan ke service ke smf

bikin file /lib/svc/method/svc-mysql

isinya


#!/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_include.sh

DB_DIR=/export/home/mysql/data

PIDFILE=${DB_DIR}/`/usr/bin/uname -n`.pid



case "$1" in

start)

/export/home/mysql/bin/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

kemudian buat file /var/svc/manifest/network/mysql.xml

isinya

<?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>

kemudian kita ubah permisi filenya

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

chown -R mysql:mysql /export/home/mysql

chmod -R 700 /export/home/mysql/data

kita lakukan import ke SMF

svccfg import /var/svc/manifest/network/mysql.xml
svcadm -v enable mysql


Kamis, 15 Oktober 2009

amazing tool "wc, head and tail "


kali ini pasti ditemui oleh sysadmin dalam mengelola file konfigurasi. yaitu apabila terjadi perubahan apakah bisa kita merubah dengan script daripada melakukan edit melalui editor.
terutama tambah delete di file konfigurasi tanpa merusak file tersebut.

contoh kasus :

# /etc/lilo.conf - See: `lilo(8)' and `lilo.conf(5)',
# --------------- `install-mbr(8)', `/usr/share/doc/lilo/',
# and `/usr/share/doc/mbr/'.

# +---------------------------------------------------------------+
# | !! Reminder !! |
# | |
# | Don't forget to run `lilo' after you make changes to this |
# | conffile, `/boot/bootmess.txt' (if you have created it), or |
# | install a new kernel. The computer will most likely fail to |
# | boot if a kernel-image post-install script or you don't |
# | remember to run `lilo'. |
# | |
# +---------------------------------------------------------------+

# Specifies the boot device. This is where Lilo installs its boot
# block. It can be either a partition, or the raw device, in which
# case it installs in the MBR, and will overwrite the current MBR.
#
boot=/dev/sda

# Specifies the device that should be mounted as root. (`/')
#
#root=/dev/sda1

# This option may be needed for some software RAID installs.
#
# raid-extra-boot=mbr-only

# Enable map compaction:
# Tries to merge read requests for adjacent sectors into a single
# read request. This drastically reduces load time and keeps the
# map smaller. Using `compact' is especially recommended when
# booting from a floppy disk. It is disabled here by default
# because it doesn't always work.
#
# compact

# Installs the specified file as the new boot sector
# You have the choice between: text, bmp, and menu
# Look in lilo.conf(5) manpage for details
#
#install=menu

# Specifies the location of the map file
#
map=/boot/map

# You can set a password here, and uncomment the `restricted' lines
# in the image definitions below to make it so that a password must
# be typed to boot anything but a default configuration. If a
# command line is given, other than one specified by an `append'
# statement in `lilo.conf', the password will be required, but a
# standard default boot will not require one.
#
# This will, for instance, prevent anyone with access to the
# console from booting with something like `Linux init=/bin/sh',
# and thus becoming `root' without proper authorization.
#
# Note that if you really need this type of security, you will
# likely also want to use `install-mbr' to reconfigure the MBR
# program, as well as set up your BIOS to disallow booting from
# removable disk or CD-ROM, then put a password on getting into the
# BIOS configuration as well. Please RTFM `install-mbr(8)'.
#
# password=tatercounter2000

# Specifies the number of deciseconds (0.1 seconds) LILO should
# wait before booting the first image.
#
delay=20

# You can put a customized boot message up if you like. If you use
# `prompt', and this computer may need to reboot unattended, you
# must specify a `timeout', or it will sit there forever waiting
# for a keypress. `single-key' goes with the `alias' lines in the
# `image' configurations below. eg: You can press `1' to boot
# `Linux', `2' to boot `LinuxOLD', if you uncomment the `alias'.
#
# message=/boot/bootmess.txt
# prompt
# delay=100
# timeout=100

# Specifies the VGA text mode at boot time. (normal, extended, ask, )
#
# vga=ask
# vga=9
#


# Kernel command line options that apply to all installed images go
# here. See: The `boot-prompt-HOWTO' and `kernel-parameters.txt' in
# the Linux kernel `Documentation' directory.
#
# append=""

# If you used a serial console to install Ubuntu, this option should be
# enabled by default.
# serial=

#
# Boot up Linux by default.
#
default=Linux

image=/vmlinuz
label=Linux
read-only
# restricted
# alias=1
append="root=/dev/sda1 "
initrd=/initrd.img

image=/vmlinuz.old
label=LinuxOLD
read-only
optional
# restricted
# alias=2
append="root=/dev/sda1 "
initrd=/initrd.img.old


# If you have another OS on this machine to boot, you can uncomment the
# following lines, changing the device name on the `other' line to
# where your other OS' partition is.
#
# other=/dev/hda4
# label=HURD
# restricted
# alias=3


anda pingin menghapus baris

image=/vmlinuz.old
label=LinuxOLD
read-only
optional
# restricted
# alias=2
append="root=/dev/sda1 "
initrd=/initrd.img.old


sambil iseng buka bash

bikin script pakai head tail dan wc

#!/bin/bash

num=`grep -n "image=/vmlinuz.old" /etc/lilo.conf | cut -f1 -d:`
let num=num-1
head -n $num /etc/lilo.conf > /tmp/lilo.conf.baru
let num=num+9
tot=`wc -l /etc/lilo.conf | cut -f1 -d " "`
let num=num-tot
tail -n $num /etc/lilo.conf >> /tmp/lilo.conf.baru

file hasil script ada di /tmp/lilo.conf.baru