Skynet服务器框架(三) Mac OS X环境安装

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://linsh-tech.blog.csdn.net/article/details/70185858

Mac os x下安装sky net:

安装:

相比于Linux系统,Mac系统下安装skynet显然要简单得多,打开Mac的终端,大致步骤如下:

  • 先检查本地是否已安装了git工具,假如已经安装:

    bogon:~ linshuhe$ git --version
    git version 2.8.1
  • 通过gitskynet源码克隆到本地:

    bogon:project linshuhe$ git clone https://github.com/cloudwu/skynet.git
    Cloning into 'skynet'...
    remote: Counting objects: 8087, done.
    remote: Total 8087 (delta 0), reused 0 (delta 0), pack-reused 8086
    Receiving objects: 100% (8087/8087), 2.66 MiB | 31.00 KiB/s, done.
    Resolving deltas: 100% (5463/5463), done.
    Checking connectivity... done.
  • 进入skynet根目录:

    bogon:project linshuhe$ cd skynet/
    bogon:skynet linshuhe$ ls
    3rd     Makefile    lualib      service     test
    HISTORY.md  README.md   lualib-src  service-src
    LICENSE     examples    platform.mk skynet-src
  • 开始使用 make 指令编译源码,需要指定当前编译的操作系统为 "macosx"

    bogon:skynet linshuhe$ make 'macosx'
    /Applications/Xcode.app/Contents/Developer/usr/bin/make all PLAT=macosx SKYNET_LIBS="-lpthread -lm -ldl" SHARED="-fPIC -dynamiclib -Wl,-undefined,dynamic_lookup" EXPORT="" MALLOC_STATICLIB="" SKYNET_DEFINES="-DNOUSE_JEMALLOC"
    cd 3rd/lua && /Applications/Xcode.app/Contents/Developer/usr/bin/make CC='cc -std=gnu99' macosx
    /Applications/Xcode.app/Contents/Developer/usr/bin/make all SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" CC=cc
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lapi.o lapi.c
    2017-04-15 17:46:23.097 xcodebuild[1399:22760] [MT] PluginLoading: Required plug-in compatibility UUID F41BD31E-2683-44B8-AE7F-5F09E919790E for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin' not present in DVTPlugInCompatibilityUUIDs
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lcode.o lcode.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lctype.o lctype.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ldebug.o ldebug.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ldo.o ldo.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ldump.o ldump.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lfunc.o lfunc.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lgc.o lgc.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o llex.o llex.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lmem.o lmem.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lobject.o lobject.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lopcodes.o lopcodes.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lparser.o lparser.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lstate.o lstate.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lstring.o lstring.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ltable.o ltable.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ltm.o ltm.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lundump.o lundump.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lvm.o lvm.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lzio.o lzio.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lauxlib.o lauxlib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lbaselib.o lbaselib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lbitlib.o lbitlib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lcorolib.o lcorolib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ldblib.o ldblib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o liolib.o liolib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lmathlib.o lmathlib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o loslib.o loslib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lstrlib.o lstrlib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o ltablib.o ltablib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lutf8lib.o lutf8lib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o loadlib.o loadlib.c
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o linit.o linit.c
    ar rcu liblua.a lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o 
    ranlib liblua.a
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o lua.o lua.c
    cc -o lua   lua.o liblua.a -lm -lreadline 
    cc -O2 -Wall -Wextra -DLUA_USE_MACOSX -I../../skynet-src   -c -o luac.o luac.c
    cc -o luac   luac.o liblua.a -lm -lreadline 
    cc -g -O2 -Wall -I3rd/lua  -o skynet skynet-src/skynet_main.c skynet-src/skynet_handle.c skynet-src/skynet_module.c skynet-src/skynet_mq.c skynet-src/skynet_server.c skynet-src/skynet_start.c skynet-src/skynet_timer.c skynet-src/skynet_error.c skynet-src/skynet_harbor.c skynet-src/skynet_env.c skynet-src/skynet_monitor.c skynet-src/skynet_socket.c skynet-src/socket_server.c skynet-src/malloc_hook.c skynet-src/skynet_daemon.c skynet-src/skynet_log.c 3rd/lua/liblua.a -Iskynet-src -I3rd/jemalloc/include/jemalloc   -lpthread -lm -ldl -DNOUSE_JEMALLOC
    mkdir cservice
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup service-src/service_snlua.c -o cservice/snlua.so -Iskynet-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup service-src/service_logger.c -o cservice/logger.so -Iskynet-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup service-src/service_gate.c -o cservice/gate.so -Iskynet-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup service-src/service_harbor.c -o cservice/harbor.so -Iskynet-src
    mkdir luaclib
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-skynet.c lualib-src/lua-seri.c -o luaclib/skynet.so -Iskynet-src -Iservice-src -Ilualib-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-socket.c -o luaclib/socketdriver.so -Iskynet-src -Iservice-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-bson.c -o luaclib/bson.so -Iskynet-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-mongo.c -o luaclib/mongo.so -Iskynet-src
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -I3rd/lua-md5 3rd/lua-md5/md5.c 3rd/lua-md5/md5lib.c 3rd/lua-md5/compat-5.2.c -o luaclib/md5.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-netpack.c -Iskynet-src -o luaclib/netpack.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-clientsocket.c -o luaclib/clientsocket.so -lpthread
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-memory.c -o luaclib/memory.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-profile.c -o luaclib/profile.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-multicast.c -o luaclib/multicast.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-cluster.c -o luaclib/cluster.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-crypt.c lualib-src/lsha1.c -o luaclib/crypt.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-sharedata.c -o luaclib/sharedata.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-stm.c -o luaclib/stm.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Ilualib-src/sproto lualib-src/sproto/sproto.c lualib-src/sproto/lsproto.c -o luaclib/sproto.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -I3rd/lpeg 3rd/lpeg/lpcap.c 3rd/lpeg/lpcode.c 3rd/lpeg/lpprint.c 3rd/lpeg/lptree.c 3rd/lpeg/lpvm.c -o luaclib/lpeg.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup lualib-src/lua-mysqlaux.c -o luaclib/mysqlaux.so 
    cc -g -O2 -Wall -I3rd/lua  -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup -Iskynet-src lualib-src/lua-debugchannel.c -o luaclib/debugchannel.so
  • 编译成功后,使用指令查询skynet根目录,可以看到多出了一个可执行文件 skynet表示编译成功:

    bogon:skynet linshuhe$ ls
    3rd     README.md   lualib      service-src test
    HISTORY.md  cservice    lualib-src  skynet
    LICENSE     examples    platform.mk skynet-src
    Makefile    luaclib     service     skynet.dSYM

启动:

  • 运行服务器:
    确保当前处于skynet的根目录下,运行以下指令:

    bogon:skynet linshuhe$ ./skynet examples/config
    [:01000001] LAUNCH logger 
    [:01000002] LAUNCH snlua bootstrap
    [:01000003] LAUNCH snlua launcher
    [:01000004] LAUNCH snlua cmaster
    [:01000004] master listen socket 0.0.0.0:2013
    [:01000005] LAUNCH snlua cslave
    [:01000005] slave connect to master 127.0.0.1:2013
    [:01000006] LAUNCH harbor 1 16777221
    [:01000004] connect from 127.0.0.1:51132 4
    [:01000004] Harbor 1 (fd=4) report 127.0.0.1:2526
    [:01000005] Waiting for 0 harbors
    [:01000005] Shakehand ready
    [:01000007] LAUNCH snlua datacenterd
    [:01000008] LAUNCH snlua service_mgr
    [:01000009] LAUNCH snlua main
    [:01000009] Server start
    [:0100000a] LAUNCH snlua protoloader
    [:0100000b] LAUNCH snlua console
    [:0100000c] LAUNCH snlua debug_console 8000
    [:0100000c] Start debug console at 127.0.0.1:8000
    [:0100000d] LAUNCH snlua simpledb
    [:0100000e] LAUNCH snlua watchdog
    [:0100000f] LAUNCH snlua gate
    [:0100000f] Listen on 0.0.0.0:8888
    [:01000009] Watchdog listen on 8888
    [:01000009] KILL self
    [:01000002] KILL self

    按键盘快捷键ctrl+c停止服务器运行。

  • 运行客户端:
    保持服务端处于启动状态,新起一个终端,定位到当前项目根目录下,运行客户端测试脚本:

    ./3rd/lua/lua examples/client.lua
    • 假如运行正确,在服务端的终端会输出接收到socket连接的日志:

      [:0100000e] New client from : 127.0.0.1:51696
      [:01000010] LAUNCH snlua agent
      set hello   world
    • 并且此时客户端也会输出:

      bogon:skynet linshuhe$ ./3rd/lua/lua examples/client.lua
      Request:    1
      Request:    2
      RESPONSE    1
      msg Welcome to skynet, I will send heartbeat every 5 sec.
      RESPONSE    2
      REQUEST heartbeat
      REQUEST heartbeat
      REQUEST heartbeat
      REQUEST heartbeat
      REQUEST heartbeat

其他:

有的网友还对skynet进行了适配,提供了skynet对Windows环境支持的版本:Windows版skynet

展开阅读全文

没有更多推荐了,返回首页