1、基礎設置
# 版本說明
操作系統:centos7.6 jumpserver:1.5.0
# 升級所有包同時也升級軟件和系統內核
yum update -y
# selinux配置
setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# 安裝依賴包
yum -y install wget gcc epel-release git vim
2、安裝Redis
# 安裝 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
yum -y install redis
systemctl enable redis
systemctl start redis
3、安裝MySQL
# 安裝 MySQL(centos7下叫mariadb)
yum -y install mariadb mariadb-devel mariadb-server MariaDB-shared
systemctl enable mariadb
systemctl start mariadb
# 創建數據庫 Jumpserver 並授權
mysql -uroot create database jumpserver default charset 'utf8'; grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'wmq20151118'; flush privileges;
4、配置Python環境
# 安裝 Python3.6
yum -y install python36 python36-devel
# 配置並載入 Python3 虛擬環境
cd /opt python3.6 -m venv py3 source /opt/py3/bin/activate
# 看到下面的提示符代表成功, 以后運行 Jumpserver 都要先運行以上 source 命令, 載入環境后默認以下所有命令均在該虛擬環境中運行
(py3) [root@localhost py3]
5、安裝Jumpserver
# 下載 Jumpserver
cd /opt/ git clone --depth=1 https://github.com/jumpserver/jumpserver.git
# 安裝依賴 RPM 包
yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
# 安裝 Python 庫依賴
pip install --upgrade pip setuptools
pip install -r /opt/jumpserver/requirements/requirements.txt
# 復制 Jumpserver 配置文件
cd /opt/jumpserver
cp config_example.yml config.yml
# 生成隨機SECRET_KEY
加密秘鑰 生產環境中請修改為隨機字符串, 請勿外泄, PS: 純數字不可以
SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50` echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc
# 生成隨機BOOTSTRAP_TOKEN
預共享Token coco和guacamole用來注冊服務賬號, 不在使用原來的注冊接受機制
BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16` echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc
# 查看SECRET_KEY、BOOTSTRAP_TOKEN
cat ~/.bashrc SECRET_KEY=c1NVKkBQonam9CqX8AWqLiCt4PMGmJTr3DYFGePG0Nz3QD9uY4 BOOTSTRAP_TOKEN=nfmBa3WkbQ8leRRb
# 修改配置文件
sed -i "s/SECRET_KEY:/SECRET_KEY: $SECRET_KEY/g" /opt/jumpserver/config.yml sed -i "s/BOOTSTRAP_TOKEN:/BOOTSTRAP_TOKEN: $BOOTSTRAP_TOKEN/g" /opt/jumpserver/config.yml sed -i "s/# DEBUG: true/DEBUG: false/g" /opt/jumpserver/config.yml sed -i "s/# LOG_LEVEL: DEBUG/LOG_LEVEL: ERROR/g" /opt/jumpserver/config.yml sed -i "s/# SESSION_EXPIRE_AT_BROWSER_CLOSE: false/SESSION_EXPIRE_AT_BROWSER_CLOSE: true/g" /opt/jumpserver/config.yml sed -i "s/DB_PASSWORD: /DB_PASSWORD: $DB_PASSWORD/g" /opt/jumpserver/config.yml
# 查看完整 config.yml 配置文件
cat /opt/jumpserver/config.yml
# SECURITY WARNING: keep the secret key used in production secret! # 加密秘鑰 生產環境中請修改為隨機字符串,請勿外泄, 可使用命令生成 # $ cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 49;echo SECRET_KEY: c1NVKkBQonam9CqX8AWqLiCt4PMGmJTr3DYFGePG0Nz3QD9uY4 # SECURITY WARNING: keep the bootstrap token used in production secret! # 預共享Token coco和guacamole用來注冊服務賬號,不在使用原來的注冊接受機制 BOOTSTRAP_TOKEN: nfmBa3WkbQ8leRRb # Development env open this, when error occur display the full process track, Production disable it # DEBUG 模式 開啟DEBUG后遇到錯誤時可以看到更多日志 DEBUG: false # DEBUG, INFO, WARNING, ERROR, CRITICAL can set. See https://docs.djangoproject.com/en/1.10/topics/logging/ # 日志級別 LOG_LEVEL: ERROR # LOG_DIR: # Session expiration setting, Default 24 hour, Also set expired on on browser close # 瀏覽器Session過期時間,默認24小時, 也可以設置瀏覽器關閉則過期 # SESSION_COOKIE_AGE: 86400 SESSION_EXPIRE_AT_BROWSER_CLOSE: true # Database setting, Support sqlite3, mysql, postgres .... # 數據庫設置 # See https://docs.djangoproject.com/en/1.10/ref/settings/#databases # SQLite setting: # 使用單文件sqlite數據庫 # DB_ENGINE: sqlite3 # DB_NAME: # MySQL or postgres setting like: # 使用Mysql作為數據庫 DB_ENGINE: mysql DB_HOST: 127.0.0.1 DB_PORT: 3306 DB_USER: jumpserver DB_PASSWORD: wmq20151118 DB_NAME: jumpserver # When Django start it will bind this host and port # ./manage.py runserver 127.0.0.1:8080 # 運行時綁定端口 HTTP_BIND_HOST: 0.0.0.0 HTTP_LISTEN_PORT: 8080 # Use Redis as broker for celery and web socket # Redis配置 REDIS_HOST: 127.0.0.1 REDIS_PORT: 6379 # REDIS_PASSWORD: # REDIS_DB_CELERY: 3 # REDIS_DB_CACHE: 4 # Use OpenID authorization # 使用OpenID 來進行認證設置 # BASE_SITE_URL: http://localhost:8080 # AUTH_OPENID: false # True or False # AUTH_OPENID_SERVER_URL: https://openid-auth-server.com/ # AUTH_OPENID_REALM_NAME: realm-name # AUTH_OPENID_CLIENT_ID: client-id # AUTH_OPENID_CLIENT_SECRET: client-secret # # Use Radius authorization # 使用Radius來認證 # AUTH_RADIUS: false # RADIUS_SERVER: localhost # RADIUS_PORT: 1812 # RADIUS_SECRET: # OTP settings # OTP/MFA 配置 # OTP_VALID_WINDOW: 0 # OTP_ISSUER_NAME: Jumpserver
# 運行 Jumpserver
cd /opt/jumpserver
./jms start all -d
# 開機自啟
vim /usr/lib/systemd/system/jms.service [Unit] Description=jms After=network.target mariadb.service redis.service Wants=mariadb.service redis.service [Service] Type=forking Environment="PATH=/opt/py3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" ExecStart=/opt/jumpserver/jms start all -d ExecReload= ExecStop=/opt/jumpserver/jms stop [Install] WantedBy=multi-user.target
6、安裝coco
cd /opt/ git clone https://github.com/jumpserver/coco.git cd /opt/coco yum -y install $(cat /opt/coco/requirements/rpm_requirements.txt) pip install -r /opt/coco/requirements/requirements.txt
# 復制配置文件
cp config_example.yml config.yml
# 配置文件完整配置
cat /opt/coco/config.yml
# 項目名稱, 會用來向Jumpserver注冊, 識別而已, 不能重復 # NAME: {{ Hostname }} # Jumpserver項目的url, api請求注冊會使用 CORE_HOST: http://127.0.0.1:8080 # Bootstrap Token, 預共享秘鑰, 用來注冊coco使用的service account和terminal # 請和jumpserver 配置文件中保持一致,注冊完成后可以刪除 BOOTSTRAP_TOKEN: nfmBa3WkbQ8leRRb # 啟動時綁定的ip, 默認 0.0.0.0 # BIND_HOST: 0.0.0.0 # 監聽的SSH端口號, 默認2222 # SSHD_PORT: 2222 # 監聽的HTTP/WS端口號,默認5000 # HTTPD_PORT: 5000 # 項目使用的ACCESS KEY, 默認會注冊,並保存到 ACCESS_KEY_STORE中, # 如果有需求, 可以寫到配置文件中, 格式 access_key_id:access_key_secret # ACCESS_KEY: null # ACCESS KEY 保存的地址, 默認注冊后會保存到該文件中 # ACCESS_KEY_FILE: data/keys/.access_key # 加密密鑰 # SECRET_KEY: null # 設置日志級別 [DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL] LOG_LEVEL: ERROR # 日志存放的目錄 # LOG_DIR: logs # SSH白名單 # ALLOW_SSH_USER: all # SSH黑名單, 如果用戶同時在白名單和黑名單,黑名單優先生效 # BLOCK_SSH_USER: # - # 和Jumpserver 保持心跳時間間隔 # HEARTBEAT_INTERVAL: 5 # Admin的名字,出問題會提示給用戶 # ADMINS: '' # SSH連接超時時間 (default 15 seconds) # SSH_TIMEOUT: 15 # 語言 [en,zh] # LANGUAGE_CODE: zh # SFTP的根目錄, 可選 /tmp, Home其他自定義目錄 # SFTP_ROOT: /tmp # SFTP是否顯示隱藏文件 # SFTP_SHOW_HIDDEN_FILE: false # 是否復用和用戶后端資產已建立的連接(用戶不會復用其他用戶的連接) # REUSE_CONNECTION: true
# 后台啟動coco
/opt/coco/cocod start -d
# 開機自啟
vim /usr/lib/systemd/system/coco.service [Unit] Description=coco After=network.target jms.service [Service] Type=forking PIDFile=/opt/coco/coco.pid Environment="PATH=/opt/py3/bin" ExecStart=/opt/coco/cocod start -d ExecReload= ExecStop=/opt/coco/cocod stop [Install] WantedBy=multi-user.target
7、下載Luna
# 安裝 Web Terminal 前端: Luna 需要 Nginx 來運行訪問 訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包, 直接解壓, 不需要編譯
cd /opt wget https://github.com/jumpserver/luna/releases/download/1.5.0/luna.tar.gz
# 如果網絡有問題導致下載無法完成可以使用下面地址
wget https://demo.jumpserver.org/download/luna/1.5.0/luna.tar.gz
# 解壓
tar xf luna.tar.gz
chown -R root:root luna
8、安裝Nginx
# 安裝 Nginx, 用作代理服務器整合 Jumpserver 與各個組件
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
yum -y install nginx
# 配置 Nginx 整合各組件
rm -rf /etc/nginx/conf.d/default.conf
vim /etc/nginx/conf.d/jumpserver.conf server { # http自動跳轉到https listen 80; server_name jump.wmqhealth.com; rewrite ^ https://$http_host$request_uri? permanent; } server { # 代理端口, 以后將通過此端口進行訪問, 不再通過8080端口 listen 443 ssl; ssl_certificate ssl/jump.wmqhealth.com.pem; ssl_certificate_key ssl/jump.wmqhealth.com.key; server_name jump.wmqhealth.com; # 修改成你的域名或者注釋掉 client_max_body_size 100m; # 錄像及文件上傳大小限制 location /luna/ { try_files $uri / /index.html; alias /opt/luna/; # luna 路徑, 如果修改安裝目錄, 此處需要修改 } location /media/ { add_header Content-Encoding gzip; root /opt/jumpserver/data/; # 錄像位置, 如果修改安裝目錄, 此處需要修改 } location /static/ { root /opt/jumpserver/data/; # 靜態資源, 如果修改安裝目錄, 此處需要修改 } location /socket.io/ { proxy_pass http://localhost:5000/socket.io/; # 如果coco安裝在別的服務器, 請填寫它的ip proxy_buffering off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location /coco/ { proxy_pass http://localhost:5000/coco/; # 如果coco安裝在別的服務器, 請填寫它的ip proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location /guacamole/ { proxy_pass http://localhost:8081/; # 如果guacamole安裝在別的服務器, 請填寫它的ip proxy_buffering off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; access_log off; } location / { proxy_pass http://localhost:8080; # 如果jumpserver安裝在別的服務器, 請填寫它的ip proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
# 運行 Nginx
nginx -t
systemctl enable nginx
systemctl start nginx
9、訪問
# 訪問 UI (注意 沒有 :8080 通過 nginx 代理端口進行訪問):
http://192.168.244.144
默認賬號: admin 密碼: admin 到會話管理-終端管理 接受 coco 等應用的注冊
# 測試ssh連接
ssh -p2222 admin@192.168.244.144
密碼: admin
10、附啟動命令
#啟動
systemctl start mariadb
systemctl start redis
systemctl start jms
systemctl start coco
systemctl start nginx