首页
学习
活动
专区
工具
TVP
发布

蓝天

专栏作者
526
文章
828988
阅读量
41
订阅数
Zookeeper C++编程实战之主备切换
默认zookeeper日志输出到stderr, 可以调用zoo_set_log_stream(FILE*)设置输出到文件中 还可以调用zoo_set_debug_level(ZooLogLevel)控制日志级别!!! 类CZookeeperHelper提供基于zookeeper的主备切换接口和读取数据等接口: https://github.com/eyjian/libmooon/blob/master/include/mooon/net/zookeeper_helper.h 使用示例:
一见
2018-12-13
5920
Redis模块开发示例
实现一个Redis module,支持两个扩展命令: 1) 可同时对hash的多个field进行incr操作; 2) incrby同时设置一个key的过期时间 在没有module之前,需要借助eval+lua实现相同的功能。有了module,不但可以实现逻辑复杂,且性能高的扩展,同时享受Redis的持久化和容灾能力。
一见
2018-12-10
9240
几种修改Linux主机名的方法
在安装一些系统时,需要修改hostname,比如安装Hadoop时需要修改主机名,而且主机名不能包含下划线。
一见
2018-09-30
3.5K0
巧用NULL模式解耦依赖
由于需求的变化,应用B需要库libM.a的能力,以便和服务M交互。为了复用和简化,通过类A间接提供,应用B不用修改代码,只需要重新编译即可获得新的能力,其它用到类A的应用也是如此。
一见
2018-09-30
4990
Redis源码笔记-初步
Redis代码优美,注释也很到位,阅读起来会赏心悦目,大大降低了理解门槛。由于redis单线程几乎完成所有工作,整体逻辑是相当复杂的,涉及了太多状态,作者的技术深厚可见一斑。
一见
2018-09-30
2.1K0
Linux远程批量工具mooon_ssh和mooon_upload使用示例
https://github.com/eyjian/libmooon/releases
一见
2018-09-30
8620
Kafka常用命令收录
本文内容主要来自两个方面:一是网上的分享,二是自研的随手记。日记月累,收录kafka各种命令,会持续更新。
一见
2018-09-30
6.2K0
Redis-4.0.11集群配置
本文参考官方文档而成:http://redis.io/topics/cluster-tutorial。经测试,安装过程也适用于redis-3.2.0、redis-4.0.11等。
一见
2018-09-30
2.5K0
大压力下Redis参数调整要点
最重要的原因之一Redis的主从复制,两者复制共享同一线程,虽然是异步复制的,但因为是单线程,所以也十分有限。如果主从间的网络延迟不是在0.05左右,比如达到0.6,甚至1.2等,那么情况是非常糟糕的,因此同一Redis集群一定要部署在同一机房内。
一见
2018-09-30
1.4K0
查看Redis集群所有节点内存工具
指定集群中任意一个节点,查看集群中所有节点当前已用物理内存、配置的最大物理内存和系统物理内存。 源码(可从下载):
一见
2018-09-30
2.5K0
查看Redis集群主从对应关系工具
源代码(可从https://github.com/eyjian/redis-tools下载):
一见
2018-09-30
2.1K0
C/C++常见gcc编译链接错误解决方法
用“-Wl,-Bstatic”指定链接静态库,使用“-Wl,-Bdynamic”指定链接共享库,使用示例: -Wl,-Bstatic -lmysqlclient_r -lssl -lcrypto -Wl,-Bdynamic -lrt -Wl,-Bdynamic -pthread -Wl,-Bstatic -lgtest ("-Wl"表示是传递给链接器ld的参数,而不是编译器gcc/g++的参数。) 1) 下面是因为没有指定链接参数-lz(/usr/lib/libz.so,/usr/lib/libz.a ) /usr/local/mysql/lib/mysql/libmysqlclient.a(my_compress.c.o): In function `my_uncompress': /home/software/mysql-5.5.24/mysys/my_compress.c:122: undefined reference to `uncompress' /usr/local/mysql/lib/mysql/libmysqlclient.a(my_compress.c.o): In function `my_compress_alloc': /home/software/mysql-5.5.24/mysys/my_compress.c:71: undefined reference to `compress' 2) 下面是因为没有指定编译链接参数-pthread(注意不仅仅是-lpthraed) /usr/local/mysql/lib/mysql/libmysqlclient.a(charset.c.o): In function `get_charset_name': /home/zhangsan/mysql-5.5.24/mysys/charset.c:533: undefined reference to `pthread_once' 3) 下面这个是因为没有指定链接参数-lrt /usr/local/thirdparty/curl/lib/libcurl.a(libcurl_la-timeval.o): In function `curlx_tvnow': timeval.c:(.text+0xe9): undefined reference to `clock_gettime' 4) 下面这个是因为没有指定链接参数-ldl /usr/local/thirdparty/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup': dso_dlfcn.c:(.text+0x4c): undefined reference to `dlopen' dso_dlfcn.c:(.text+0x62): undefined reference to `dlsym' dso_dlfcn.c:(.text+0x6c): undefined reference to `dlclose' 5) 下面这个是因为指定了链接参数-static,它的存在,要求链接的必须是静态库,而不能是共享库 ld: attempted static link of dynamic object 如果是以-L加-l方式指定,则目录下必须有.a文件存在,否则会报-l的库文件找不到:ld: cannot find -lACE 6) GCC编译遇到如下的错误,可能是因为在编译时没有指定-fPIC,记住:-fPIC即是编译参数,也是链接参数 relocation R_x86_64_32S against `vtable for CMyClass` can not be used when making a shared object 7) 下面的错误表示gcc编译时需要定义宏__STDC_FORMAT_MACROS,并且必须包含头文件inttypes.h test.cpp:35: error: expected `)' before 'PRIu64' 8) 下面是因为在x86机器(32位)上编译没有指定编译参数-march=pentium4 ../../src/common/libmooon.a(logger.o): In function `atomic_dec_and_test': ../../include/mooon/sys/atomic_gcc.h:103: undefined reference to `__sync_sub_and_fetch_4' 9) 下列错误可能是因为多了个“}” error: expected d
一见
2018-08-10
7.6K0
GCC: error: expected `)' before 'PRIu64'
printf("UniqID: %"PRIu64"\n", uniq_id); test.cpp:35: error: expected `)' before 'PRIu64' make: *** [test.o] 错误 1 上述错误,gcc编译时需要定义宏__STDC_FORMAT_MACROS,并且必须包含头文件inttypes.h。
一见
2018-08-10
1.4K0
C++两种线程模式:委托和继承(附示例)
继承方式实现简单,请参见:https://github.com/eyjian/mooon/blob/master/common_library/include/mooon/sys/thread.h 在C++11标准之前的实现较为复杂(可参见:https://github.com/eyjian/mooon/blob/master/common_library/include/mooon/sys/thread_engine.h): 委托版本使用非常简单:
一见
2018-08-10
9070
代码中创建新终端
最常见于使用SecureCRT等工具远程创建打开终端,下面的代码演示在代码中创建打开终端:
一见
2018-08-10
6530
Thrift编译错误解决方法
下面这个错误可能是因为DOS(Windows)和Unix文件格式问题: checking whether g++ supports C++11 features by default... no checking whether g++ supports C++11 features with -std=c++11... no configure: No compiler with C++11 support was found ./configure: line 16746: syntax error near unexpected token `fi' ./configure: line 16746: `fi' 解决方法是设置好git: [core] autocrlf = false safecrlf = true eol = lf 对应的命令为: git config --global core.autocrlf false git config --global core.safecrlf true git config --global core.eol lf 完成后,删除再重新从git上clone出来。 下面这个错误原因暂不清楚(configure时指定了--with-qt4=no,按理代码应当不会进入才对): checking for ranlib... (cached) ranlib checking whether g++ supports C++11 features by default... no checking whether g++ supports C++11 features with -std=c++11... no configure: No compiler with C++11 support was found ./configure: line 17658: syntax error near unexpected token `QT,' ./configure: line 17658: `    PKG_CHECK_MODULES(QT, QtCore >= 4.3, QtNetwork >= 4.3, have_qt=yes, have_qt=no)' 但可以编辑configure文件,然后将相应的行注释掉,如: #  if test "$with_qt4" = "yes";  then #    PKG_CHECK_MODULES(QT, QtCore >= 4.3, QtNetwork >= 4.3, have_qt=yes, have_qt=no) #  fi 其它类似的错误都可以这样处理。 下面这个错误发生在x86_64上,也根据提示来操作: /usr/local/thirdparty/openssl/include/openssl/sha.h:184: error: ISO C++ does not support 'long long' /usr/local/thirdparty/openssl/include/openssl/sha.h:185: error: ISO C++ does not support 'long long' /usr/local/thirdparty/openssl/include/openssl/sha.h:187: error: ISO C++ does not support 'long long' 修改sha.h的相应代码行,将SHA_LONG64改成int64_t(需要#include )或long即可。
一见
2018-08-10
2.2K0
Linux开发环境第三方库规划
让工作变得有条理,不乱糟糟,即使存在大量的第三方,也有章可循。简而言之,就是要保持目录的干净(如/usr/local目录),保持文件的干净(如profile文件)
一见
2018-08-10
1.3K0
automake编译和安装方式说明
作为良好的习惯,建议为第三方库建立专门的目录,目录取名为thirdparty。然后,再在thirdparty下建立名叫src_package,用来存放第三方库的源码包,如没有特别说明,第三方库默认均为automake编译和安装方式。并且,一般建议将第三方库安装在thirdparty目录下,而不是系统的/usr/local目录下,目的是尽量减少对系统目录的污染,保持系统目录的整洁。 【automake编译和安装方式说明】 通常Linux系统自带automake编译工具,C/C++开源库一般都采用automake编译。 假设源代码库文件名为protobuf-2.4.1.tar.gz,则编译和安装操作步骤如下: 1) 将源代码包文件protobuf-2.4.1.tar.gz上传到Linux机上,这里假设上传到Linux机的/tmp目录 2) 进入/tmp目录 3) 解压源代码包文件:tar xzf protobuf-2.4.1.tar.gz,完成后会在/tmp目录下会出现一个子目录protobuf-2.4.1 4) 进入/tmp的子目录子目录protobuf-2.4.1 5) 执行configure命令,以生成Makefile文件:./configure --prefix=/usr/local/protobuf-2.4.1,这里假设将Protocol Buffers安装到/usr/local/protobuf-2.4.1 6) 上一步会生成编译用的Makefile文件,接下来执行make编译:make 7) make成功后,再执行make install安装 8) 成功后,就可以ls /usr/local/protobuf-2.4.1查看安装结果了; 9) 建立不带版本号的软链接:ln -s /usr/local/protobuf-2.4.1 /usr/local/protobuf 【automake编译和安装方式补充说明】 a) 源代码包如果是protobuf-2.4.1.tar.bz2形式,则表示是bzip2压缩包,而protobuf-2.4.1.tar.gz是gzip压缩包,对于bzip2压缩包,tar解压参数请由xzf改成xjf b) 上述第9步不是必须的,但会是一个良好的Linux风俗,建议保持 c) 注意第5步,如果生成的静态库会被其它共享库使用,则可能需要为configure增加参数,否则在链接生成共享库时,可能会报被链接的静态库需要带-fPIC参数重新编译,这个问题不难解决,如下变通一下即可: ./configure --prefix=/usr/local/protobuf-2.4.1 CXXFLAGS=-fPIC LDFLAGS=-fPIC d) 开源的C/C++库源代码包文件一般都采用类似于protobuf-2.4.1.tar.gz的命名方式 【推荐的编译环境目录结构】 假设有一项目mooon,它的目录结构如下,和SVN目录结构保持一致,但SVN上不存放中间目录和文件,mooon本身可以基于用户主目录,或者其它合适的目录,如/data目录下: mooon |-- doc |-- src `-- thirdparty     |-- apr-util     |-- boost     |-- gflags     |-- protobuf     |-- sqlite     |-- src_package     |   |-- apr-util-1.5.1.tar.gz     |   |-- boost_1_53_0.tar.gz     |   |-- cgicc-3.2.10.tar.gz     |   |-- gflags-2.0.tar.gz     |   |-- protobuf-2.4.1.tar.gz     |   |-- sqlite-autoconf-3071401.tar.gz     |   `-- thrift-0.9.0.tar.gz     `-- thrift 安装openssl:  # ./config --prefix=/usr/local/thirdparty/openssl-1.0.2a shared threads 安装httpd(apache),支持https:  # ./configure --with-apr=/usr/local/thirdparty/apr-1.4.6 --with-apr-util=/usr/local/thirdparty/apr-util-1.5.1 --with-ssl=/usr/local/thirdparty/openssl-1.0.2a --with-pcre=/usr/local/thirdpar
一见
2018-08-10
1.8K0
linux unzip: End-of-central-directory signature not found
在linux上使用unzip解压一个.zip文件时,如果遇到下面这样的错误: Archive:  common_library.zip   End-of-central-directory signature not found.  Either this file is not   a zipfile, or it constitutes one disk of a multi-part archive.  In the   latter case the central directory and zipfile comment will be found on   the last disk(s) of this archive. unzip:  cannot find zipfile directory in one of common_library.zip or         common_library.zip.zip, and cannot find common_library.zip.ZIP, period. 原因有两种: 1) 以ASCII格式上传了.zip文件 2) .zip文件大小超过了2G。
一见
2018-08-10
2.9K0
C++资源编译工具,用于将任何格式的文件编译成C++代码
resource_maker.zip          linux自带了一个名叫xxd的工具,带参数-i运行时,效果类似,如:xxd -i /bin/ls。
一见
2018-08-10
9830
点击加载更多
社区活动
腾讯技术创作狂欢月
“码”上创作 21 天,分 10000 元奖品池!
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档