1. [root@lzone_zkong_cluster_01 scripts]# cat docker-install-and-uninstall.sh
    2. #!/bin/bash
    3. # Version: v0.0.1                                 
    4. # Debian/Ubuntu Linux systems. (May 10, 2019)
    5. # (GNU/General Public License version 2.0)
    6. # For Centos 7 and up, Linux lzone_zkong_cluster_01 3.10.0-862.el7.x86_64.
    7. # ...And away we go!
    8. Package='/server/tools'
    9. function tools {
    10. if [ ! -d "$Package" ]; then
    11. mkdir "$Package" -p
    12. fi
    13. }
    14. function INSTALL {
    15. cp /usr/local/esl/scripts/docker-19.03.9.tgz $Package
    16. cd $Package && tar xf docker-19.03.9.tgz
    17. mv $Package/docker/* /usr/bin/
    18. cat >/etc/systemd/system/docker.service <<-EOF
    19. [Unit]
    20. Description=Docker Application Container Engine
    21. Documentation=https://docs.docker.com
    22. After=network-online.target firewalld.service
    23. Wants=network-online.target
    24. [Service]
    25. Type=notify
    26. # the default is not to use systemd for cgroups because the delegate issues still
    27. # exists and systemd currently does not support the cgroup feature set required
    28. # for containers run by docker
    29. ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
    30. ExecReload=/bin/kill -s HUP $MAINPID
    31. # Having non-zero Limit*s causes performance problems due to accounting overhead
    32. # in the kernel. We recommend using cgroups to do container-local accounting.
    33. LimitNOFILE=infinity
    34. LimitNPROC=infinity
    35. LimitCORE=infinity
    36. # Uncomment TasksMax if your systemd version supports it.
    37. # Only systemd 226 and above support this version.
    38. #TasksMax=infinity
    39. TimeoutStartSec=0
    40. # set delegate yes so that systemd does not reset the cgroups of docker containers
    41. Delegate=yes
    42. # kill only the docker process, not all processes in the cgroup
    43. KillMode=process
    44. # restart the docker process if it exits prematurely
    45. Restart=on-failure
    46. StartLimitBurst=3
    47. StartLimitInterval=60s
    48. [Install]
    49. WantedBy=multi-user.target
    50. EOF
    51. chmod +x /etc/systemd/system/docker.service
    52. systemctl daemon-reload && systemctl start docker && systemctl enable docker.service >/dev/null 2>&1
    53. systemctl status docker >/dev/null 2>&1
    54. echo "当前Docker版本: `docker -v`"
    55. }
    56. function UNINSTALL {
    57. cd /usr/local/esl/ && docker-compose stop && systemctl stop docker
    58. rpm -qa | grep docker | xargs yum remove -y >/dev/null 2>&1
    59. rm -rf /var/lib/docker
    60. }
    61. echo '
    62. Please enter the action you want to perform:"install" | "uninstall"
    63. 请输入您要执行的操作:“安装install” 或者 “卸载uninstall”'
    64. read -p "Please enter the action you want to perform: " action
    65. case $action in
    66. install)
    67. tools
    68. INSTALL
    69. ;;
    70. uninstall)
    71. UNINSTALL && echo 'Docker uninstall Successfully'
    72. ;;
    73. *)
    74. echo '
    75. The action you entered is not supported.
    76. Please enter the following format: install | uninstall'
    77. exit 1
    78. esac