当前位置: 首页 > 工具软件 > UCMQ > 使用案例 >

零起步6-CentOS7.6源码编译安装http轻量级消息队列ucmq

梁丘俊人
2023-12-01
先安装libevent,最新版本号 libevent-2.1.11-stable.tar.gz
 
[root@localhost ~]# ls -al /usr/lib | grep libevent
[root@localhost ~]#  yum install libtool -y
[root@localhost ~]# wget https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stable.tar.gz
[root@localhost ~]# cd libevent-2.1.11-stable
[root@localhost libevent-2.1.11-stable]# ./configure --prefix=/usr/lib/libevent
[root@localhost libevent-2.1.11-stable]# make && make install
[root@localhost libevent-2.1.11-stable]# ls -al /usr/lib | grep libevent
drwxr-xr-x.  5 root root    43 Feb 11 02:48 libevent

ucmq和memcache都依赖libevent,同时ucmq还依赖libtool

 
安装完libtool、libevent,接下来依次安装 ucmq和memcached
 
安装ucmq
官网及相关说明
 
[root@localhost ~]# git clone git://github.com/zhanglei/ucmq.git
[root@localhost ~]# cp -R ucmq /root/ucmq
[root@localhost ~]# cd /root/ucmq/
[root@localhost ucmq]# chmod +x .
[root@localhost ucmq]# ./genall.sh
[root@localhost ucmq]# ./configure --with-libevent=/usr/lib/libevent --prefix=/usr/local/ucmq
[root@localhost ucmq]# make && make install
[root@localhost ucmq]# make clean

错误:./genall.sh:行13: libtoolize: 未找到命令,安装libtool即可

 
安装ucmq遇到一个很吐血的问题
/usr/bin/ld: ucmq-util.o: undefined reference to symbol ' pthread_ sigmask@@GLIBC_2.2.5'
//usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
 
找遍天涯海角,终于觅出一条生机(差点就放弃了),感谢CSDN“南冥之鸟”,原文如下
问题原因
出现该问题的原因:pthread不是linux下的默认的库,也就是在链接的时候,无法找到phread库中线程函数的入口地址,于是链接会失败。
 
解决方法如下(依葫芦画样)
据错误提示在当前路径下搜索grep -r ucmq-util.o找到如下路径Makefile文件并依次打开这些文件
source/Makefile.in:ucmq-util.o: util.c
source/Makefile:ucmq-util.o: util.c
source/.deps/ucmq-util.Po:ucmq-util.o: util.c
在这三个文件中分别查找LIBS,定位到如下行,你发现了什么?是不是没有 “ -lpthread ”?再对比回报错信息,发现问题了吧
LIBS = -lz -lrt -lresolv -lnsl -lm -ldl -lbz2
然后将这行加上-lpthread,修改后如下(保存退出):
LIBS = -lz -lrt -lresolv -lnsl -lm -ldl -lbz2 -lpthread
记得同时修改这两个文件
[root@localhost ucmq]# vi source/Makefile
[root@localhost ucmq]# vi Makefile

修改后再编译,一切顺利!!

[root@localhost ucmq]# make && make install
[root@localhost ucmq]# ll /usr/local/ucmq/
总用量 0
drwxr-xr-x. 2 root root  18 12月 21 10:13 bin
drwxr-xr-x. 2 root root  22 12月 21 10:13 conf
drwxr-xr-x. 2 root root  41 12月 21 10:13 include
drwxr-xr-x. 2 root root 103 12月 21 10:13 lib
drwxr-xr-x. 2 root root  86 12月 21 10:13 test
 
配置ucmq
 
ucmq.ini配置文件说明
[server]
http_listen_addr=0.0.0.0         //监听地址,设置0.0.0.0为通用访问,也可设置为127.0.0.1或192.168.x.x
http_listen_port=18180           //监听端口,设置超过10000,避免冲突  
allow_exec_ip=0                  //允许执行运维指令的ip,0为不限制  
binlog_file_path=/log/ucmq.binlog //binlog目录(暂未实现主从)  
output_log_path=/log/ucmq.log    //日志目录  
output_log_level=DEBUG           //日志记录级别  
keep_alive=300                   //长连接有效时间(单位:秒)  
conf_file=/data/conf/ucmq.ini    //配置文件路径  
pid_file=/var/run/ucmq.pid       //进程保护文件  
res_store_space=4                //预留磁盘空间(单位:GB)  
[rtag]
sync_interval=10                 //数据文件内存映射持久化操作间隔(写操作次数)  
sync_time_interval=100           //间隔n秒后持久化rtag和DB的信息,会调用fsync。  
[queue]
def_max_queue=1000000            //队列允许积压消息量,设置为0则不限制  
#延时只能设置更大
def_delay=0                      //队列延时时间  
#以下内容自从启动后不允许修改
[db]
data_file_path=/data/ucmq/       //data文件存放路径  
#文件大小不允许超过64,必须是系统页大小的倍数
db_file_max_size=64              //允许的data文件的最大限制(单位:MB)

将ucmq加入系统服务,并设置开启自启动

 
以下是ucmq的shell脚本,请加入到 /etc/init.d/ucmq文件中
#! /bin/sh
#
# ucmq this script starts and stops the ucmq daemon
#
# chkconfig: 345 86 16
# description: ucmq is a non-relational database storage system.
# processname: ucmq
# config: /data/conf/ucmq.ini
# pidfile: /var/run/ucmq.pid

PATH=/usr/local/bin:/sbin:/usr/bin:/bin
EXEC=/usr/local/ucmq/bin/ucmq
CONF=/data/conf/ucmq.ini
PIDFILE=/var/run/ucmq.pid
   
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting ucmq server..."
                $EXEC -c $CONF -d
        fi
    while [ ! -x ${PIDFILE} ]
                do
                    echo "Waiting for ucmq to starting ..."
                    sleep 1
        done
        echo "ucmq is running..."
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
            PID=$(cat $PIDFILE)
                echo "Stopping ..."
                kill -2 $PID;
                while [ -x ${PIDFILE} ]
                do
                    echo "Waiting for ucmq to shutdown ..."
                    sleep 1
                done
                echo "ucmq stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/ucmq {start|stop|restart|force-reload}" >&2
        exit 1
esac

设置为开机服务

[root@localhost ~]# vi /etc/init.d/ucmq
[root@localhost ~]# chmod +x /etc/init.d/ucmq
[root@localhost ~]# chkconfig ucmq on
[root@localhost ~]# service ucmq start
[root@localhost ~]# ps aux |grep ucmq         
root      75568  0.0  0.0  22608  1000 pts/3    S    13:33   0:00 /usr/local/ucmq/bin/ucmq -c /data/conf/ucmq.ini
root      75759  0.0  0.0 112728   992 pts/2    S+   13:37   0:00 grep --color=auto ucmq

test ucmq

 
Monitor, please access the below address in your web browser
 类似资料: