分布式部署文档 - nginx 代理部署

说明

  • # 开头的行表示注释
  • $ 开头的行表示需要执行的命令

环境

  • 系统: CentOS 7
  • IP: 192.168.100.100
Protocol ServerName IP Port Used By
TCP Nginx 192.168.100.100 80, 443, 2222 All
TCP Nginx 192.168.100.100 3306 Jumpserver

开始安装

  1. # 升级系统
  2. $ yum upgrade -y
  3. # 获取 epel-release 源
  4. $ yum -y install epel-release
  5. # 设置防火墙, 开放 80 443 2222 端口
  6. $ firewall-cmd --zone=public --add-port=80/tcp --permanent
  7. $ firewall-cmd --zone=public --add-port=443/tcp --permanent
  8. $ firewall-cmd --zone=public --add-port=2222/tcp --permanent
  9. $ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.0/24" port protocol="tcp" port="3306" accept"
  10. # 192.168.100.0/24 为整个 Jumpserver 网络网段, 这里就偷懒了, 自己根据实际情况修改即可
  11. $ firewall-cmd --reload
  12. # 设置 selinux
  13. $ setenforce 0
  14. $ sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  1. # 安装 nginx
  2. $ vi /etc/yum.repos.d/nginx.repo
  3. [nginx]
  4. name=nginx repo
  5. baseurl=http://nginx.org/packages/centos/7/$basearch/
  6. gpgcheck=0
  7. enabled=1
  1. # 非 Centos7 请参考 http://nginx.org/en/linux_packages.html#stable
  2. $ yum -y install nginx
  3. $ systemctl enable nginx
  4. # 下载 luna
  5. $ cd /opt
  6. $ wget https://github.com/jumpserver/luna/releases/download/1.4.8/luna.tar.gz
  7. # 如果网络有问题导致下载无法完成可以使用下面地址
  8. $ wget https://demo.jumpserver.org/download/luna/1.4.8/luna.tar.gz
  9. $ tar xf luna.tar.gz
  10. $ chown -R root:root luna
  1. # 配置 Nginx
  2. $ vi /etc/nginx/nginx.conf
  3. user nginx;
  4. worker_processes auto;
  5. error_log /var/log/nginx/error.log warn;
  6. pid /var/run/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. stream {
  11. log_format proxy '$remote_addr [$time_local] '
  12. '$protocol $status $bytes_sent $bytes_received '
  13. '$session_time "$upstream_addr" '
  14. '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
  15. access_log /var/log/nginx/tcp-access.log proxy;
  16. open_log_file_cache off;
  17. upstream MariaDB {
  18. server 192.168.100.10:3306;
  19. server 192.168.100.11:3306 backup; # 多节点
  20. server 192.168.100.12:3306 down; # 多节点
  21. # 这里是 Mariadb 的后端ip
  22. }
  23. upstream cocossh {
  24. server 192.168.100.40:2222;
  25. server 192.168.100.40:2223; # 多节点
  26. # 这里是 coco ssh 的后端ip
  27. least_conn;
  28. }
  29. server {
  30. listen 3306;
  31. proxy_pass MariaDB;
  32. proxy_connect_timeout 1s; # detect failure quickly
  33. }
  34. server {
  35. listen 2222;
  36. proxy_pass cocossh;
  37. proxy_connect_timeout 1s; # detect failure quickly
  38. }
  39. }
  40. http {
  41. include /etc/nginx/mime.types;
  42. default_type application/octet-stream;
  43. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  44. '$status $body_bytes_sent "$http_referer" '
  45. '"$http_user_agent" "$http_x_forwarded_for"';
  46. access_log /var/log/nginx/access.log main;
  47. sendfile on;
  48. # tcp_nopush on;
  49. keepalive_timeout 65;
  50. # 关闭版本显示
  51. server_tokens off;
  52. include /etc/nginx/conf.d/*.conf;
  53. }
  1. # 备份默认的配置文件
  2. $ mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.bak
  3. $ vi /etc/nginx/conf.d/jumpserver.conf
  4. upstream jumpserver {
  5. server 192.168.100.30:80;
  6. # 这里是 jumpserver 的后端ip
  7. }
  8. upstream cocows {
  9. server 192.168.100.40:5000 weight=1;
  10. server 192.168.100.40:5001 weight=1; # 多节点
  11. # 这里是 coco ws 的后端ip
  12. ip_hash;
  13. }
  14. upstream guacamole {
  15. server 192.168.100.50:8081 weight=1;
  16. server 192.168.100.50:8082 weight=1; # 多节点
  17. # 这里是 guacamole 的后端ip
  18. ip_hash;
  19. }
  20. server {
  21. listen 80;
  22. server_name www.jumpserver.org; # 自行修改成你的域名
  23. return 301 https://$server_name$request_uri;
  24. }
  25. server {
  26. # 推荐使用 https 访问, 如果不使用 https 请自行注释下面的选项
  27. listen 443;
  28. server_name www.jumpserver.org; # 自行修改成你的域名
  29. ssl on;
  30. ssl_certificate /etc/nginx/sslkey/1_jumpserver.org_bundle.crt; # 自行设置证书
  31. ssl_certificate_key /etc/nginx/sslkey/2_jumpserver.org.key; # 自行设置证书
  32. ssl_session_timeout 5m;
  33. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  34. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  35. ssl_prefer_server_ciphers on;
  36. client_max_body_size 100m; # 录像上传大小限制
  37. location / {
  38. proxy_pass http://jumpserver; # jumpserver
  39. proxy_set_header X-Real-IP $remote_addr;
  40. proxy_set_header Host $host;
  41. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  42. access_log off;
  43. }
  44. location /luna/ {
  45. try_files $uri / /index.html;
  46. alias /opt/luna/; # luna 路径, 如果修改安装目录, 此处需要修改
  47. }
  48. location /socket.io/ {
  49. proxy_pass http://cocows/socket.io/; # coco
  50. proxy_buffering off;
  51. proxy_http_version 1.1;
  52. proxy_set_header Upgrade $http_upgrade;
  53. proxy_set_header Connection "upgrade";
  54. proxy_set_header X-Real-IP $remote_addr;
  55. proxy_set_header Host $host;
  56. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  57. access_log off;
  58. }
  59. location /coco/ {
  60. proxy_pass http://cocows/coco/;
  61. proxy_set_header X-Real-IP $remote_addr;
  62. proxy_set_header Host $host;
  63. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  64. access_log off;
  65. }
  66. location /guacamole/ {
  67. proxy_pass http://guacamole/; # guacamole
  68. proxy_buffering off;
  69. proxy_http_version 1.1;
  70. proxy_set_header Upgrade $http_upgrade;
  71. proxy_set_header Connection $http_connection;
  72. proxy_set_header X-Real-IP $remote_addr;
  73. proxy_set_header Host $host;
  74. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  75. access_log off;
  76. }
  77. }
  1. # nginx 测试并启动, 如果报错请按报错提示自行解决
  2. $ nginx -t
  3. $ systemctl start nginx
  4. # 访问 http://192.168.100.100
  5. # 默认账号: admin 密码: admin 到会话管理-终端管理 接受 Coco Guacamole 等应用的注册
  6. # 测试连接
  7. $ ssh -p2222 admin@192.168.100.100
  8. $ sftp -P2222 admin@192.168.100.100
  9. 密码: admin
  10. # 如果是用在 Windows 下, Xshell Terminal 登录语法如下
  11. $ ssh admin@192.168.100.100 2222
  12. $ sftp admin@192.168.100.100 2222
  13. 密码: admin
  14. 如果能登陆代表部署成功
  15. # sftp默认上传的位置在资产的 /tmp 目录下
  16. # windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下

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