2. 安装

2.1. Linux源码编译

2.1.1. 确认依赖包已安装

  1. yum install -y telnet
  2. yum install -y nmap-ncat
  3. yum install -y bridge-utils
  4. yum install -y man-pages
  5. yum install -y supermin5

2.1.2. 确认内核转发功能已开启

临时开启

  1. # echo "1" >/proc/sys/net/ipv4/ip_forward

或永久开启

  1. # echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
  2. # sysctl -p

2.1.3. 准备cocker源码

下载cocker源码包,解开,进入

  1. # tar xvzf cocker-X.X.X.tar.gz
  2. # cd cocker-X.X.X

或克隆cocker源码库,进入

  1. # git clone https://gitee.com/calvinwilliams/cocker
  2. # cd cocker

or

  1. # git clone https://github.com/calvinwilliams/cocker
  2. # cd cocker

2.1.4. 编译安装

注意:如果你在非root用户编译源码,确认sudo无需输入密码。

清理中间文件

  1. # make -f makefile.Linux clean
  2. make[1]:进入目录“/home/calvin/src/cocker/shbin
  3. make[1]:离开目录“/home/calvin/src/cocker/shbin
  4. make[1]:进入目录“/home/calvin/src/cocker/src
  5. make[2]:进入目录“/home/calvin/src/cocker/src/util
  6. rm -f list.o
  7. rm -f LOGC.o
  8. rm -f version.o
  9. rm -f file.o
  10. rm -f string.o
  11. rm -f socket.o
  12. rm -f pts.o
  13. rm -f libcocker_util.so
  14. make[2]:离开目录“/home/calvin/src/cocker/src/util
  15. make[2]:进入目录“/home/calvin/src/cocker/src/cocker
  16. rm -f util.o
  17. rm -f main.o
  18. rm -f env.o
  19. rm -f show_images.o
  20. rm -f show_containers.o
  21. rm -f action_create.o
  22. rm -f action_destroy.o
  23. rm -f action_boot.o
  24. rm -f action_shutdown.o
  25. rm -f action_version.o
  26. rm -f action_vip.o
  27. rm -f action_port_mapping.o
  28. rm -f action_volume.o
  29. rm -f action_attach.o
  30. rm -f action_install_test.o
  31. rm -f action_to_container.o
  32. rm -f action_to_image.o
  33. rm -f action_copy_image.o
  34. rm -f action_del_image.o
  35. rm -f action_export.o
  36. rm -f action_import.o
  37. rm -f show_ssearch.o
  38. rm -f action_spush.o
  39. rm -f action_spull.o
  40. rm -f cocker
  41. make[2]:离开目录“/home/calvin/src/cocker/src/cocker
  42. make[2]:进入目录“/home/calvin/src/cocker/src/cockerinit
  43. rm -f main.o
  44. rm -f server.o
  45. rm -f pty.o
  46. rm -f pts_and_tcp_bridge.o
  47. rm -f cockerinit
  48. make[2]:离开目录“/home/calvin/src/cocker/src/cockerinit
  49. make[1]:离开目录“/home/calvin/src/cocker/src

编译并安装到系统目录里

注意:如果你在非root用户编译源码,前面加上sudo -E

  1. # make -f makefile.Linux install
  2. make[1]:进入目录“/home/calvin/src/cocker/src
  3. make[2]:进入目录“/home/calvin/src/cocker/src/util
  4. rm -f list.o
  5. rm -f LOGC.o
  6. rm -f version.o
  7. rm -f file.o
  8. rm -f string.o
  9. rm -f socket.o
  10. rm -f pts.o
  11. rm -f libcocker_util.so
  12. make[2]:离开目录“/home/calvin/src/cocker/src/util
  13. make[2]:进入目录“/home/calvin/src/cocker/src/cocker
  14. rm -f util.o
  15. rm -f main.o
  16. rm -f env.o
  17. rm -f show_images.o
  18. rm -f show_containers.o
  19. rm -f action_create.o
  20. rm -f action_destroy.o
  21. rm -f action_boot.o
  22. rm -f action_shutdown.o
  23. rm -f action_version.o
  24. rm -f action_vip.o
  25. rm -f action_port_mapping.o
  26. rm -f action_volume.o
  27. rm -f action_attach.o
  28. rm -f action_install_test.o
  29. rm -f action_to_container.o
  30. rm -f action_to_image.o
  31. rm -f action_copy_image.o
  32. rm -f action_del_image.o
  33. rm -f action_export.o
  34. rm -f action_import.o
  35. rm -f show_ssearch.o
  36. rm -f action_spush.o
  37. rm -f action_spull.o
  38. rm -f cocker
  39. make[2]:离开目录“/home/calvin/src/cocker/src/cocker
  40. make[2]:进入目录“/home/calvin/src/cocker/src/cockerinit
  41. rm -f main.o
  42. rm -f server.o
  43. rm -f pty.o
  44. rm -f pts_and_tcp_bridge.o
  45. rm -f cockerinit
  46. make[2]:离开目录“/home/calvin/src/cocker/src/cockerinit
  47. make[1]:离开目录“/home/calvin/src/cocker/src
  48. make[1]:进入目录“/home/calvin/src/cocker/shbin
  49. make[1]:离开目录“/home/calvin/src/cocker/shbin
  50. make[1]:进入目录“/home/calvin/src/cocker/src
  51. make[2]:进入目录“/home/calvin/src/cocker/src/util
  52. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c list.c
  53. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c LOGC.c
  54. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c version.c
  55. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c file.c
  56. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c string.c
  57. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c socket.c
  58. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -c pts.c
  59. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -o libcocker_util.so list.o LOGC.o version.o file.o string.o socket.o pts.o -shared -L.-L/lib64 -L/usr/lib64 -L/usr/lib
  60. rm -f /lib64/libcocker_util.so
  61. cp -rf libcocker_util.so /lib64/
  62. rm -f /usr/include/cocker_in/list.h
  63. cp -rf list.h /usr/include/cocker_in/
  64. rm -f /usr/include/cocker_in/LOGC.h
  65. cp -rf LOGC.h /usr/include/cocker_in/
  66. rm -f /usr/include/cocker_in/cocker_util.h
  67. cp -rf cocker_util.h /usr/include/cocker_in/
  68. make[2]:离开目录“/home/calvin/src/cocker/src/util
  69. make[2]:进入目录“/home/calvin/src/cocker/src/cocker
  70. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c util.c
  71. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c main.c
  72. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c env.c
  73. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c show_images.c
  74. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c show_containers.c
  75. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_create.c
  76. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_destroy.c
  77. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_boot.c
  78. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_shutdown.c
  79. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_version.c
  80. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_vip.c
  81. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_port_mapping.c
  82. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_volume.c
  83. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_attach.c
  84. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_install_test.c
  85. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_to_container.c
  86. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_to_image.c
  87. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_copy_image.c
  88. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_del_image.c
  89. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_export.c
  90. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_import.c
  91. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c show_ssearch.c
  92. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_spush.c
  93. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c action_spull.c
  94. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -o cocker util.o main.o env.o show_images.o show_containers.o action_create.o action_destroy.o action_boot.o action_shutdown.o action_version.o action_vip.o action_port_mapping.o action_volume.o action_attach.o action_install_test.o action_to_container.o action_to_image.o action_copy_image.o action_del_image.o action_export.o action_import.o show_ssearch.o action_spush.o action_spull.o -L.-L/lib64 -L/usr/lib64 -L/usr/lib -L/lib64 -lcocker_util -lcrypto
  95. rm -f /bin/cocker
  96. cp -rf cocker /bin/
  97. make[2]:离开目录“/home/calvin/src/cocker/src/cocker
  98. make[2]:进入目录“/home/calvin/src/cocker/src/cockerinit
  99. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c main.c
  100. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c server.c
  101. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c pty.c
  102. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -I.-I/usr/include -I/usr/include -std=gnu99 -I/usr/include/cocker_in -c pts_and_tcp_bridge.c
  103. gcc -g -fPIC -O2 -Wall-Werror-fno-strict-aliasing -o cockerinit main.o server.o pty.o pts_and_tcp_bridge.o -L.-L/lib64 -L/usr/lib64 -L/usr/lib -L/lib64 -lcocker_util -lcrypto
  104. rm -f /bin/cockerinit
  105. cp -rf cockerinit /bin/
  106. make[2]:离开目录“/home/calvin/src/cocker/src/cockerinit
  107. make[1]:离开目录“/home/calvin/src/cocker/src
  108. make[1]:进入目录“/home/calvin/src/cocker/shbin
  109. rm -f /bin/cocker_ldd_and_cp_lib64.sh
  110. cp -rf cocker_ldd_and_cp_lib64.sh /bin/
  111. rm -f /bin/cocker_profile_template.sh
  112. cp -rf cocker_profile_template.sh /bin/
  113. rm -f /bin/cocker_etc_profile_template.sh
  114. cp -rf cocker_etc_profile_template.sh /bin/
  115. rm -f /bin/cocker_install_test.sh
  116. cp -rf cocker_install_test.sh /bin/
  117. rm -f /bin/cocker_create_image_rhel-7.4-x86_64.sh
  118. cp -rf cocker_create_image_rhel-7.4-x86_64.sh /bin/
  119. rm -f /bin/cocker_create_image_rhel-7.4-gcc-x86_64.sh
  120. cp -rf cocker_create_image_rhel-7.4-gcc-x86_64.sh /bin/
  121. make[1]:离开目录“/home/calvin/src/cocker/shbin

如果没有发生错误则表明编译安装成功,从以上命令行获知:

  • 构建出开发内部使用头文件src/cocker/*.h安装到/usr/include/cocker_in,库文件libcocker_util.so安装到/lib64。开发内部文件仅用于编译。
  • 构建出可执行文件cockercockerinit安装到/bin
  • 自带脚本shbin/*.sh安装到/bin