CentOS 7 安装文档

说明

  • 开头的行表示注释

  • > 开头的行表示需要在 mysql 中执行
  • $ 开头的行表示需要执行的命令云服务器快速部署参考 极速安装

安装过程中遇到问题可参考 安装过程中常见的问题

环境

  • 系统: CentOS 7
  • IP: 192.168.244.144
  • 目录: /opt
  • 数据库: mariadb
  • 代理: nginx

开始安装

  1. $ yum update -y
  2.  
  3. # 防火墙 与 selinux 设置说明, 如果已经关闭了 防火墙 和 Selinux 的用户请跳过设置
  4. $ systemctl start firewalld
  5. $ firewall-cmd --zone=public --add-port=80/tcp --permanent # nginx 端口
  6. $ firewall-cmd --zone=public --add-port=2222/tcp --permanent # 用户SSH登录端口 coco
  7. --permanent 永久生效, 没有此参数重启后失效
  8.  
  9. $ firewall-cmd --reload # 重新载入规则
  10.  
  11. $ setenforce 0
  12. $ sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  13.  
  14. # 安装依赖包
  15. $ yum -y install wget gcc epel-release git
  16.  
  17. # 安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
  18. $ yum -y install redis
  19. $ systemctl enable redis
  20. $ systemctl start redis
  21.  
  22. # 安装 MySQL, 如果不使用 Mysql 可以跳过相关 Mysql 安装和配置, 支持sqlite3, mysql, postgres等
  23. $ yum -y install mariadb mariadb-devel mariadb-server MariaDB-shared # centos7下叫mariadb, 用法与mysql一致
  24. $ systemctl enable mariadb
  25. $ systemctl start mariadb
  26. # 创建数据库 Jumpserver 并授权
  27. $ DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` # 生成随机数据库密码
  28. $ echo -e "\033[31m 你的数据库密码是 $DB_PASSWORD \033[0m"
  29. $ mysql -uroot -e "create database jumpserver default charset 'utf8'; grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by '$DB_PASSWORD'; flush privileges;"
  30.  
  31. # 安装 Nginx, 用作代理服务器整合 Jumpserver 与各个组件
  32. $ vi /etc/yum.repos.d/nginx.repo
  33.  
  34. [nginx]
  35. name=nginx repo
  36. baseurl=http://nginx.org/packages/centos/7/$basearch/
  37. gpgcheck=0
  38. enabled=1
  39.  
  40. $ yum -y install nginx
  41. $ systemctl enable nginx
  42.  
  43. # 安装 Python3.6
  44. $ yum -y install python36 python36-devel
  45.  
  46. # 配置并载入 Python3 虚拟环境
  47. $ cd /opt
  48. $ python3.6 -m venv py3 # py3 为虚拟环境名称, 可自定义
  49. $ source /opt/py3/bin/activate # 退出虚拟环境可以使用 deactivate 命令
  50.  
  51. # 看到下面的提示符代表成功, 以后运行 Jumpserver 都要先运行以上 source 命令, 载入环境后默认以下所有命令均在该虚拟环境中运行
  52. (py3) [root@localhost py3]
  53.  
  54. # 下载 Jumpserver
  55. $ cd /opt/
  56. $ git clone https://github.com/jumpserver/jumpserver.git
  57. $ cd /opt/jumpserver
  58. $ git checkout 1.4.8
  59.  
  60. # 安装依赖 RPM 包
  61. $ yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
  62.  
  63. # 安装 Python 库依赖
  64. $ pip install --upgrade pip setuptools
  65. $ pip install -r /opt/jumpserver/requirements/requirements.txt
  1. # 修改 Jumpserver 配置文件
  2. $ cd /opt/jumpserver
  3. $ cp config_example.yml config.yml
  4.  
  5. $ SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50` # 生成随机SECRET_KEY
  6. $ echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc
  7. $ BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16` # 生成随机BOOTSTRAP_TOKEN
  8. $ echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc
  9.  
  10. $ sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml
  11. $ sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml
  12. $ sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml
  13. $ sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml
  14. $ sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml
  15. $ sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml
  16.  
  17. $ echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m"
  18. $ echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m"
  19.  
  20. $ vi config.yml # 确认内容有没有错误
  1. # SECURITY WARNING: keep the secret key used in production secret!
  2. # 加密秘钥 生产环境中请修改为随机字符串, 请勿外泄, PS: 纯数字不可以
  3. SECRET_KEY:
  4.  
  5. # SECURITY WARNING: keep the bootstrap token used in production secret!
  6. # 预共享Token coco和guacamole用来注册服务账号, 不在使用原来的注册接受机制
  7. BOOTSTRAP_TOKEN:
  8.  
  9. # Development env open this, when error occur display the full process track, Production disable it
  10. # DEBUG 模式 开启DEBUG后遇到错误时可以看到更多日志
  11. DEBUG: false
  12.  
  13. # DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/
  14. # 日志级别
  15. LOG_LEVEL: ERROR
  16. # LOG_DIR:
  17.  
  18. # Session expiration setting, Default 24 hour, Also set expired on on browser close
  19. # 浏览器Session过期时间, 默认24小时, 也可以设置浏览器关闭则过期
  20. # SESSION_COOKIE_AGE: 86400
  21. SESSION_EXPIRE_AT_BROWSER_CLOSE: true
  22.  
  23. # Database setting, Support sqlite3, mysql, postgres ....
  24. # 数据库设置
  25. # See https://docs.djangoproject.com/en/1.10/ref/settings/#databases
  26.  
  27. # SQLite setting:
  28. # 使用单文件sqlite数据库
  29. # DB_ENGINE: sqlite3
  30. # DB_NAME:
  31.  
  32. # MySQL or postgres setting like:
  33. # 使用Mysql作为数据库
  34. DB_ENGINE: mysql
  35. DB_HOST: 127.0.0.1
  36. DB_PORT: 3306
  37. DB_USER: jumpserver
  38. DB_PASSWORD:
  39. DB_NAME: jumpserver
  40.  
  41. # When Django start it will bind this host and port
  42. # ./manage.py runserver 127.0.0.1:8080
  43. # 运行时绑定端口
  44. HTTP_BIND_HOST: 0.0.0.0
  45. HTTP_LISTEN_PORT: 8080
  46.  
  47. # Use Redis as broker for celery and web socket
  48. # Redis配置
  49. REDIS_HOST: 127.0.0.1
  50. REDIS_PORT: 6379
  51. # REDIS_PASSWORD:
  52. # REDIS_DB_CELERY: 3
  53. # REDIS_DB_CACHE: 4
  54.  
  55. # Use OpenID authorization
  56. # 使用OpenID 来进行认证设置
  57. # BASE_SITE_URL: http://localhost:8080
  58. # AUTH_OPENID: false # True or False
  59. # AUTH_OPENID_SERVER_URL: https://openid-auth-server.com/
  60. # AUTH_OPENID_REALM_NAME: realm-name
  61. # AUTH_OPENID_CLIENT_ID: client-id
  62. # AUTH_OPENID_CLIENT_SECRET: client-secret
  63.  
  64. # OTP settings
  65. # OTP/MFA 配置
  66. # OTP_VALID_WINDOW: 0
  67. # OTP_ISSUER_NAME: Jumpserver
  1. # 运行 Jumpserver
  2. $ cd /opt/jumpserver
  3. $ ./jms start -d # 后台运行使用 -d 参数./jms start -d
  4. # 新版本更新了运行脚本, 使用方式./jms start|stop|status all 后台运行请添加 -d 参数
  1. # 安装 docker 部署 coco 与 guacamole
  2. $ yum install -y yum-utils device-mapper-persistent-data lvm2
  3. $ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. $ yum makecache fast
  5. $ rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  6. $ yum -y install docker-ce
  7. $ systemctl enable docker
  8. $ curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
  9. $ systemctl restart docker
  10.  
  11. # 允许 容器ip 访问宿主 8080 端口, (容器的 ip 可以进入容器查看)
  12. $ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.17.0.0/16" port protocol="tcp" port="8080" accept"
  13. $ firewall-cmd --reload
  14. # 172.17.0.x 是docker容器默认的IP池, 这里偷懒直接授权ip段了, 可以根据实际情况单独授权IP
  15.  
  16. # 获取当前服务器 IP
  17. $ Server_IP=`ip addr | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1`
  18. $ echo -e "\033[31m 你的服务器IP是 $Server_IP \033[0m"
  19.  
  20. # http://<Jumpserver_url> 指向 jumpserver 的服务端口, 如 http://192.168.244.144:8080
  21. # BOOTSTRAP_TOKEN 为 Jumpserver/config.yml 里面的 BOOTSTRAP_TOKEN
  22. $ docker run --name jms_coco -d -p 2222:2222 -p 5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_coco:1.4.8
  23. $ docker run --name jms_guacamole -d -p 8081:8081 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_guacamole:1.4.8
  1. # 安装 Web Terminal 前端: Luna 需要 Nginx 来运行访问 访问(https://github.com/jumpserver/luna/releases)下载对应版本的 release 包, 直接解压, 不需要编译
  2. $ cd /opt
  3. $ wget https://github.com/jumpserver/luna/releases/download/1.4.8/luna.tar.gz
  4.  
  5. # 如果网络有问题导致下载无法完成可以使用下面地址
  6. $ wget https://demo.jumpserver.org/download/luna/1.4.8/luna.tar.gz
  7.  
  8. $ tar xf luna.tar.gz
  9. $ chown -R root:root luna
  1. # 配置 Nginx 整合各组件
  2. $ rm -rf /etc/nginx/conf.d/default.conf
  1. $ vi /etc/nginx/conf.d/jumpserver.conf
  2.  
  3. server {
  4. listen 80;
  5.  
  6. client_max_body_size 100m; # 录像及文件上传大小限制
  7.  
  8. location /luna/ {
  9. try_files $uri / /index.html;
  10. alias /opt/luna/; # luna 路径, 如果修改安装目录, 此处需要修改
  11. }
  12.  
  13. location /media/ {
  14. add_header Content-Encoding gzip;
  15. root /opt/jumpserver/data/; # 录像位置, 如果修改安装目录, 此处需要修改
  16. }
  17.  
  18. location /static/ {
  19. root /opt/jumpserver/data/; # 静态资源, 如果修改安装目录, 此处需要修改
  20. }
  21.  
  22. location /socket.io/ {
  23. proxy_pass http://localhost:5000/socket.io/;
  24. proxy_buffering off;
  25. proxy_http_version 1.1;
  26. proxy_set_header Upgrade $http_upgrade;
  27. proxy_set_header Connection "upgrade";
  28. proxy_set_header X-Real-IP $remote_addr;
  29. proxy_set_header Host $host;
  30. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  31. access_log off;
  32. }
  33.  
  34. location /coco/ {
  35. proxy_pass http://localhost:5000/coco/;
  36. proxy_set_header X-Real-IP $remote_addr;
  37. proxy_set_header Host $host;
  38. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  39. access_log off;
  40. }
  41.  
  42. location /guacamole/ {
  43. proxy_pass http://localhost:8081/;
  44. proxy_buffering off;
  45. proxy_http_version 1.1;
  46. proxy_set_header Upgrade $http_upgrade;
  47. proxy_set_header Connection $http_connection;
  48. proxy_set_header X-Real-IP $remote_addr;
  49. proxy_set_header Host $host;
  50. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  51. access_log off;
  52. }
  53.  
  54. location / {
  55. proxy_pass http://localhost:8080;
  56. proxy_set_header X-Real-IP $remote_addr;
  57. proxy_set_header Host $host;
  58. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  59. }
  60. }
  1. # 运行 Nginx
  2. $ nginx -t # 确保配置没有问题, 有问题请先解决
  3. $ systemctl start nginx
  4.  
  5. # 访问 http://192.168.244.144 (注意 没有 :8080 通过 nginx 代理端口进行访问)
  6. # 默认账号: admin 密码: admin 到会话管理-终端管理 接受 coco Guacamole 等应用的注册
  7. # 测试连接
  8. $ ssh -p2222 admin@192.168.244.144
  9. $ sftp -P2222 admin@192.168.244.144
  10. 密码: admin
  11.  
  12. # 如果是用在 Windows 下, Xshell Terminal 登录语法如下
  13. $ ssh admin@192.168.244.144 2222
  14. $ sftp admin@192.168.244.144 2222
  15. 密码: admin
  16. 如果能登陆代表部署成功
  17.  
  18. # sftp默认上传的位置在资产的 /tmp 目录下
  19. # windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下

多组件负载说明

  1. # coco 服务默认运行在单核心下面, 当负载过高时会导致用户访问变慢, 这时可运行多个 docker 容器缓解
  2. $ docker run --name jms_coco01 -d -p 2223:2222 -p 5001:5000 -e CORE_HOST=http://<Jumpserver_url> -e BOOTSTRAP_TOKEN=****** jumpserver/jms_coco:1.4.8
  3. $ docker run --name jms_coco02 -d -p 2224:2222 -p 5002:5000 -e CORE_HOST=http://<Jumpserver_url> -e BOOTSTRAP_TOKEN=****** jumpserver/jms_coco:1.4.8
  4. ...
  5.  
  6. # guacamole 也是一样
  7. $ docker run --name jms_guacamole01 -d -p 8082:8081 -e JUMPSERVER_SERVER=http://<Jumpserver_url> -e BOOTSTRAP_TOKEN=****** jumpserver/jms_guacamole:1.4.8
  8. $ docker run --name jms_guacamole02 -d -p 8083:8081 -e JUMPSERVER_SERVER=http://<Jumpserver_url> -e BOOTSTRAP_TOKEN=****** jumpserver/jms_guacamole:1.4.8
  9. ...
  10.  
  11. # nginx 代理设置
  12. $ vi /etc/nginx/nginx.conf
  13. user nginx;
  14. worker_processes auto;
  15.  
  16. error_log /var/log/nginx/error.log warn;
  17. pid /var/run/nginx.pid;
  18.  
  19.  
  20. events {
  21. worker_connections 1024;
  22. }
  23.  
  24. # 加入 tcp 代理
  25. stream {
  26. log_format proxy '$remote_addr [$time_local] '
  27. '$protocol $status $bytes_sent $bytes_received '
  28. '$session_time "$upstream_addr" '
  29. '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
  30.  
  31. access_log /var/log/nginx/tcp-access.log proxy;
  32. open_log_file_cache off;
  33.  
  34. upstream cocossh {
  35. server localhost:2222 weight=1;
  36. server localhost:2223 weight=1; # 多节点
  37. server localhost:2224 weight=1; # 多节点
  38. # 这里是 coco ssh 的后端ip
  39. hash $remote_addr;
  40. }
  41. server {
  42. listen 2220; # 不能使用已经使用的端口, 自行修改, 用户ssh登录时的端口
  43. proxy_pass cocossh;
  44. proxy_connect_timeout 10s;
  45. }
  46. }
  47. # 到此结束
  48.  
  49. http {
  50. include /etc/nginx/mime.types;
  51. default_type application/octet-stream;
  52.  
  53. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  54. '$status $body_bytes_sent "$http_referer" '
  55. '"$http_user_agent" "$http_x_forwarded_for"';
  56.  
  57. access_log /var/log/nginx/access.log main;
  58.  
  59. sendfile on;
  60. # tcp_nopush on;
  61.  
  62. keepalive_timeout 65;
  63.  
  64. # 关闭版本显示
  65. server_tokens off;
  66.  
  67. include /etc/nginx/conf.d/*.conf;
  68. }
  69.  
  70. $ firewall-cmd --zone=public --add-port=2220/tcp --permanent
  71. $ firewall-cmd --reload
  72.  
  73. $ vi /etc/nginx/conf.d/jumpserver.conf
  74. upstream jumpserver {
  75. server localhost:8080;
  76. # 这里是 jumpserver 的后端ip
  77. }
  78.  
  79. upstream cocows {
  80. server localhost:5000 weight=1;
  81. server localhost:5001 weight=1; # 多节点
  82. server localhost:5002 weight=1; # 多节点
  83. # 这里是 coco ws 的后端ip
  84. ip_hash;
  85. }
  86.  
  87. upstream guacamole {
  88. server localhost:8081 weight=1;
  89. server localhost:8082 weight=1; # 多节点
  90. server localhost:8083 weight=1; # 多节点
  91. # 这里是 guacamole 的后端ip
  92. ip_hash;
  93. }
  94.  
  95. server {
  96. listen 80;
  97. server_name demo.jumpserver.org; # 自行修改成你的域名
  98.  
  99. client_max_body_size 100m; # 录像上传大小限制
  100.  
  101. location / {
  102. proxy_pass http://jumpserver;
  103. proxy_set_header X-Real-IP $remote_addr;
  104. proxy_set_header Host $host;
  105. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  106. access_log off;
  107. }
  108.  
  109. location /luna/ {
  110. try_files $uri / /index.html;
  111. alias /opt/luna/;
  112. }
  113.  
  114. location /media/ {
  115. add_header Content-Encoding gzip;
  116. root /opt/jumpserver/data/; # 录像位置, 如果修改安装目录, 此处需要修改
  117. }
  118.  
  119. location /static/ {
  120. root /opt/jumpserver/data/; # 静态资源, 如果修改安装目录, 此处需要修改
  121. }
  122.  
  123. location /socket.io/ {
  124. proxy_pass http://cocows/socket.io/; # coco
  125. proxy_buffering off;
  126. proxy_http_version 1.1;
  127. proxy_set_header Upgrade $http_upgrade;
  128. proxy_set_header Connection "upgrade";
  129. proxy_set_header X-Real-IP $remote_addr;
  130. proxy_set_header Host $host;
  131. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  132. access_log off;
  133. }
  134.  
  135. location /coco/ {
  136. proxy_pass http://cocows/coco/;
  137. proxy_set_header X-Real-IP $remote_addr;
  138. proxy_set_header Host $host;
  139. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  140. access_log off;
  141. }
  142.  
  143. location /guacamole/ {
  144. proxy_pass http://guacamole/; # guacamole
  145. proxy_buffering off;
  146. proxy_http_version 1.1;
  147. proxy_set_header Upgrade $http_upgrade;
  148. proxy_set_header Connection $http_connection;
  149. proxy_set_header X-Real-IP $remote_addr;
  150. proxy_set_header Host $host;
  151. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  152. access_log off;
  153. }
  154. }
  155.  
  156. $ nginx -t
  157. $ nginx -s reload

后续的使用请参考 快速入门如遇到问题可参考 FAQ