CentOS下安装beanstalkd服务



CentOS下安装beanstalkd服务
 
beanstalkd在CentOS下没有默认的安装包,需要手动编译安装,最新版本1.6,不过1.5版本后,取消了对libevent的依赖,但不能直接启动作为daemon进程,1.4.6还是可以使用参数 -d  启动为 daemon,所以选择编译1.4.6。安装后默认不带启动脚本,但fedora下可以使用yum安装,安装后生成 /etc/init.d/beanstalkd启动脚本,所以特地在虚拟机里livecd启动fedora17,安装后,挖出beanstalkd启动脚本。
 
切换到 root用户下:
yum install libevent libevent-devel 
  www.2cto.com  
所有版本地址: https://github.com/kr/beanstalkd/downloads  
 
下载地址:
wget   http://cloud.github.com/downloads/kr/beanstalkd/beanstalkd-1.4.6.tar.gz 
 
解压:
tar xzf beanstalkd-1.4.6.tar.gz 
 
cd beanstalkd-1.4.6 
 
./configure 
 
make 
 
make install 
 
默认安装路径 :/usr/local/bin/ 
 
查看版本:
 
/usr/local/bin/beanstalkd -v 
  www.2cto.com  
1.4.6 
 
添加用户组:
 
groupadd beanstalkd 
 
添加用户:
 
adduser -M -g beanstalkd -s /sbin/nologin beanstalkd 
 
添加启动脚本,放入 /etc/init.d/ 目录下
 
chmod 755 /etc/init.d/beanstalkd 
 
加入开机启动:
  www.2cto.com  
chkconfig beanstalkd  on
 
启动:
 
service beanstalkd start 
 
安装完毕
 
附:从Fedora下挖来的 startup 脚本:
 
001
#!/bin/sh
002
#
003
# beanstalkd - a simple, fast workqueue service
004  www.2cto.com  
#
005
# chkconfig:   - 57 47
006
# description: a simple, fast workqueue service
007
# processname:  beanstalkd
008
# config:       /etc/sysconfig/beanstalkd
009
#             
010
 
011
### BEGIN INIT INFO
012
# Provides: beanstalkd
013
# Required-Start: $local_fs $network $remote_fs
014
# Required-Stop: $local_fs $network $remote_fs
015
# Default-Stop: 0 1 2 6
016
# Short-Description: start and stop beanstalkd
017
# Description: a simple, fast work-queue service
018
### END INIT INFO
019
 
020
# Source function library.
021
. /etc/rc.d/init.d/functions
022
   www.2cto.com  
023
# Source networking configuration.
024
. /etc/sysconfig/network
025
 
026
# Check that networking is up.
027
[ "$NETWORKING" = "no" ] && exit
028
exec="/usr/local/bin/beanstalkd"
029
prog=$(basename $exec)
030
 
031
# default options, overruled by items in sysconfig
032
BEANSTALKD_ADDR=127.0.0.1
033
BEANSTALKD_PORT=11300
034
BEANSTALKD_USER=beanstalkd
035
 
036
[ -e /etc/sysconfig/beanstalkd ] && . /etc/sysconfig/beanstalkd
037
   www.2cto.com  
038
lockfile=/var/lock/subsys/beanstalkd
039
 
040
start() {
041
    [ -x $exec ] || exit 5
042
    echo -n $"Starting $prog: "
043
    # if not running, start it up here, usually something like "daemon $exec"
044
    options="-l ${BEANSTALKD_ADDR} -p ${BEANSTALKD_PORT} -u ${BEANSTALKD_USER}"
045
    if [ "${BEANSTALKD_MAX_JOB_SIZE}" != ""  ]; then
046
        options="${options} -z ${BEANSTALKD_MAX_JOB_SIZE}"
047
    fi
048
 
049
    if [ "${BEANSTALKD_BINLOG_DIR}" != "" ]; then
050  www.2cto.com  
        if [ ! -d "${BEANSTALKD_BINLOG_DIR}" ]; then
051
            echo "Creating binlog directory (${BEANSTALKD_BINLOG_DIR})"
052
            mkdir -p ${BEANSTALKD_BINLOG_DIR} && chown ${BEANSTALKD_USER}:${BEANSTALKD_USER} ${BEANSTALKD_BINLOG_DIR}
053
        fi
054
        options="${options} -b ${BEANSTALKD_BINLOG_DIR}"
055
        if [ "${BEANSTALKD_BINLOG_FSYNC_PERIOD}" != "" ]; then
056
            options="${options} -f ${BEANSTALKD_BINLOG_FSYNC_PERIOD}"
057
        else
058
            options="${options} -F"
059
        fi
060
        if [ "${BEANSTALKD_BINLOG_SIZE}" != "" ]; then
061
            options="${options} -s ${BEANSTALKD_BINLOG_SIZE}"
062
        fi
063
    fi
064
 
065
    daemon $exec -d $options
066  www.2cto.com  
    retval=$?
067
    echo
068
    [ $retval -eq 0 ] && touch $lockfile
069
    return $retval
070
}
071
 
072
stop() {
073
    echo -n $"Stopping $prog: "
074
    # stop it here, often "killproc $prog"
075
    killproc $prog -INT
076
    retval=$?
077  www.2cto.com  
    echo
078
    [ $retval -eq 0 ] && rm -f $lockfile
079
    return $retval
080
}
081
 
082
restart() {
083
    stop
084
    start
085
}
086
 
087
reload() {
088
    restart
089
}
090
 
091
force_reload() {
092  www.2cto.com  
    restart
093
}
094
 
095
rh_status() {
096
    # run checks to determine if the service is running or use generic status
097
    status $prog
098
}
099
 
100
rh_status_q() {
101
    rh_status >/dev/null 2>&1
102
}
103
 
104
 
105
case "$1" in
106  www.2cto.com  
    start)
107
        rh_status_q && exit 0
108
        $1
109
        ;;
110
    stop)
111
        rh_status_q || exit 0
112
        $1
113
        ;;
114
    restart)
115
        $1
116
        ;;
117
    reload)
118
        rh_status_q || exit 7
119  www.2cto.com  
        $1
120
        ;;
121
    force-reload)
122
        force_reload
123
        ;;
124
    status)
125
        rh_status
126
        ;;
127
    condrestart|try-restart)
128
        rh_status_q || exit 0
129
        restart
130  www.2cto.com  
        ;;
131
    *)
132
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
133
        exit 2
134
esac
135
exit $?
 

相关内容

    暂无相关文章