首先创建工程目录MyServer,在MyServer目录中再创建一个叫lib的目录,用于放第三方的库。
然后打开命令行进入lib目录,运行 git clone 命令开始下载skynet框架
sammys-MBP:lib qiuyukun$ git clone https://github.com/cloudwu/skynet.git
Cloning into 'skynet'...
remote: Counting objects: 8790, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 8790 (delta 9), reused 15 (delta 7), pack-reused 8762
Receiving objects: 100% (8790/8790), 2.96 MiB | 123.00 KiB/s, done.
Resolving deltas: 100% (5906/5906), done.
这里我把skynet放在lib当作第三方库来使用,而不是直接在skynet中加入自己的代码。避免搞乱skynet中的脚本,也便于管理项目。而本身skynet也可以通过配置路径,来加载脚本。所以我们自己的代码放在哪里可以由我们自己决定。
接下来进入skynet的目录开始编译skynet源码
sammys-MBP:lib qiuyukun$ cd skynet
sammys-MBP:skynet qiuyukun$ make 'macosx'
编译完成后用ls指令查询skynet根目录
sammys-MBP:skynet qiuyukun$ 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这一项,那么表示编译成功。
接着运行测试下,看能不能启动skyent的示例。示例在examples目录中。
sammys-MBP:skynet qiuyukun$ ./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:54242 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
运行./skynet examples/config,如果出现如上显示,那么表示skynet搭建成功