вторник, июня 19, 2012

Memcacheq init.d script

source: memcacheq by Alexander Titov (qik) 
I removed few parameters from line 43
  • vim /etc/init.d/memcacheq
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /bin/sh
#
# chkconfig: - 55 45
# description:  The memcacheq daemon is a network memory cache service.
# processname: memcacheq
# config: /etc/sysconfig/memcacheq
# pidfile: /var/run/memcached/memcacheq.pid

# Standard LSB functions
#. /lib/lsb/init-functions

# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/memcacheq ];then
        . /etc/sysconfig/memcacheq
fi

# Check that networking is up.
. /etc/sysconfig/network

if [ "$NETWORKING" = "no" ]
then
        exit 0
fi

RETVAL=0
prog="memcacheq"

start () {
        echo -n $"Starting $prog: "

    if [ ! -e /var/run/memcacheq ]; then
        mkdir /var/run/memcacheq
    fi

        # insure that /var/run/memcacheq has proper permissions
    if [ "`stat -c %U /var/run/memcacheq`" != "$USER" ]; then
        chown $USER /var/run/memcacheq
    fi

        daemon --pidfile /var/run/memcacheq/memcacheq.pid /usr/local/bin/memcacheq -d -N -p $PORT -u $USER  -H "$DATADIR" -B $MAXMESSAGE -L $LOGBUF -P /var/run/memcacheq/memcacheq.pid $OPTIONS
#        daemon --pidfile /var/run/memcacheq/memcacheq.pid /usr/local/bin/memcacheq -d -N -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -H "$DATADIR" -B $MAXMESSAGE -A $PAGESIZE -L $LOGBUF -P /var/run/memcacheq/memcacheq.pid $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcacheq
}
stop () {
        echo -n $"Stopping $prog: "
        killproc -p /var/run/memcacheq/memcacheq.pid /usr/local/bin/memcacheq
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ] ; then
            rm -f /var/lock/subsys/memcacheq
            rm -f /var/run/memcacheq.pid
        fi
}

restart () {
        stop
        start
}


# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status memcacheq
        ;;
  restart|reload|force-reload)
        restart
        ;;
  condrestart)
        [ -f /var/lock/subsys/memcacheq ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
        exit 1
esac

exit $?
  • vim /etc/sysconfig/memcacheq
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Configuration file for the memcacheq service.

DATADIR=/data1/memcacheq

LOGBUF=1024

MAXMESSAGE=1024

OPTIONS='> /data1/mq_error.log'

USER=root

PORT=22201
  • service memcacheq start
  • chkconfig memcacheq on

понедельник, июня 18, 2012

Create partition table and format disk (Centos 6) Softlayer

At SoftLayer i created server with two hard disks: primary (you can choose size max 100GB) and secondary (you can choose size max 300GB)
  • df doesn't show the secondary disk, you need to create partition, format and mount disk first
[root@server me]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda2           103108896  91059600   6811588  94% /
tmpfs                  1987292         0   1987292   0% /dev/shm
/dev/xvda1               99150     49491     44539  53% /boot
  • to see all disks run fdisk
[root@server me]# fdisk -l
Disk /dev/xvdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00025cdb

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         261     2096451   82  Linux swap / Solaris

Disk /dev/xvdc: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/xvdc doesn't contain a valid partition table

Disk /dev/xvda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000cb5

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      102400   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              13       13055   104754176   83  Linux

primary disk is  /dev/xvda, and secondary is /dev/xvdc

run parted to create partition table, run mkfs to format

  • you will get into parted shell, run mklabel to set disk label (msdos for linux)
[root@server me]# parted /dev/xvdc mklabel msdos
Warning: The existing disk label on /dev/xvdc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
Information: You may need to update /etc/fstab.
  • run mkpart to create partition start from position 0 until end of disk -1, for ext3 filesystem
[root@server me]# parted /dev/xvdc mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext3
Start? 0
End? -1
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
Information: You may need to update /etc/fstab.
  • run fdisk to see partition num, now we see all disk normal at fdisk, but df still doesn't show secondary disk
[root@server me]# fdisk -l

Disk /dev/xvdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00025cdb

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1         261     2096451   82  Linux swap / Solaris

Disk /dev/xvdc: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003cf5d

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1               1       39163   314571823+  83  Linux

Disk /dev/xvda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000cb5

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      102400   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              13       13055   104754176   83  Linux
[root@server me]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda2           103108896  91019892   6851296  93% /
tmpfs                  1987292         0   1987292   0% /dev/shm
/dev/xvda1               99150     49491     44539  53% /boot
  • format partition xvdc1 by mkfs
[root@server me]# mkfs.ext3 /dev/xvdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78642955 blocks
3932147 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • mount disk
[root@server me]# mkdir /mnt/xvdc1
[root@server me]# mount /dev/xvdc1 /mnt/xvdc1
  • add mounted disk to fstab
[root@server me]# vim /etc/fstab
....
/dev/xvdc1              /mnt/xvdc1              ext3    defaults        0 0
  • check
[root@server me]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda2           103108896  63571080  34300108  65% /
tmpfs                  1987292         0   1987292   0% /dev/shm
/dev/xvda1               99150     49491     44539  53% /boot
/dev/xvdc1           309636140    195548 293712004   1% /mnt/xvdc1

Полезно: Шифрование флешки в Linux

среда, июня 13, 2012

Mount additional disk to VirtualBox image (centos 6)

  1. shut down you virtual machine
  2. open VirtualBox Manager
    • choose you machine
    • click Settings->Storage->SATA Contoller->icon Add Hard Disk
    • click "Create new disk"
    • choose format VMDK (Virtual Machine Disk) for example -> next
    • choose Dynamically allocated for example -> next
    • enter name, and choose size
    • click Create
    • click Ok
  3. run virtual machine
  4. > sudo fdisk -l

    Disk /dev/sda: 5475 MB, 5475663872 bytes
    4 heads, 32 sectors/track, 83552 cylinders
    Units = cylinders of 128 * 512 = 65536 bytes

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1       78125     4999984   83  Linux
    /dev/sda2           78126       79681       99584   83  Linux

    Disk /dev/sdb: 107.3 GB, 107374182400 bytes
    255 heads, 63 sectors/track, 13054 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Disk /dev/sdb doesn't contain a valid partition table
    • I added 100Gb disk that got name /dev/sdb
    • "Disk /dev/sdb doesn't contain a valid partition table" mean that you need to format this disk first
      • yum install gparted
      • run gparted (if you use graphical or see the manual)
      • choose you disk in right top corner dropdown
      • Device -> Create Partition Table -> choose ms-dos -> apply
      • right click on disk bar -> New -> +Add
      • right click on disk bar -> Format to.. -> choose ext3

  5. > mkdir /mnt/mydisk
  6. > mount -t ext3 /dev/sdb1 /mnt/mydisk
  7. > cd /mnt/mydisk
  8. > df 
  9. to mount automatically on boot, add disk to /etc/fstab my /etc/fstb for example, i added last line
    • LABEL=79d3d2d4  / ext4    defaults,noatime 0 0
      LABEL=e21a3e10  /boot ext3    defaults,noatime 0 0
      devpts     /dev/pts  devpts  gid=5,mode=620   0 0
      tmpfs      /dev/shm  tmpfs   defaults         0 0
      proc       /proc     proc    defaults         0 0
      sysfs      /sys      sysfs   defaults         0 0
      /dev/sdb1   /mnt/mydisk   ext3  defaults      0 0
  10. DONE