系統環境
系統:CentOS 7
IP:192.168.11.207
關閉selinux和防火牆
Yum 源設置請參考 <http://mirrors.163.com/.help/centos.html>
yum -y install epel-release # epel源
#CentOS 7
[root@test4-8g ~]# systemctl stop firewalld #臨時關閉,重啓後失效
[root@test4-8g ~]# systemctl disable firewalld
[root@test4-8g ~]# cat /etc/selinux/config
SELINUX=disabled
[root@test4-8g ~]# setenforce 0#臨時關閉,重啓後失效
[root@test4-8g ~]# getenforce 0
Permissive
#修改字符集,否則可能報輸入/輸出錯誤的問題,因爲日誌裏打印了中文
[root@test4-8g ~]# localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
[root@test4-8g ~]# export LC_ALL=zh_CN.UTF-8
[root@test4-8g ~]# echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf
#CentOS6
[root@test4-8g ~]# setenforce 0#臨時關閉,重啓後失效
[root@test4-8g ~]# service iptables stop#臨時關閉,重啓後失效
#修改字符集,否則可能報輸入/輸出錯誤的問題,因爲日誌裏打印了中文
[root@test4-8g ~]# localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8
[root@test4-8g ~]# export LC_ALL = zh_CN.UTF-8
[root@test4-8g ~]# echo'LANG = zh_CN.UTF-8'> / etc / sysconfig / i18n
一,準備Python3和Python虛擬環境
1.1 安裝依賴包
[root@test4-8g ~]# yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git
1.2編譯安裝
[root@test4-8g ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
[root@test4-8g ~]# tar xvf Python-3.6.1.tar.xz && cd Python-3.6.1
[root@test4-8g Python-3.6.1]# ./configure && make && make instal
#這裏必須執行編譯安裝,否則在安裝Python庫依賴時會有麻煩...
1.3建立Python虛擬環境
[root@test4-8g Python-3.6.1]# cd /opt/
[root@test4-8g opt]# python3 -m venv py3
[root@test4-8g opt]# source /opt//py3/bin/activate
#看到下面的提示符代表成功,以後運行Jumpserver都要先運行以上source命令,以下所有命令均在該虛擬環境中運行
(py3) [root@test4-8g opt]#
二,安裝 Jumpserver
2.1 下載或 Clone 項目
(py3) [root@test4-8g opt]# cd /opt/
(py3) [root@test4-8g opt]# git clone https://github.com/jumpserver/jumpserver.git
(py3) [root@test4-8g opt]# cd jumpserver && git checkout master
$ echo "source /opt/py3/bin/activate" > /opt/jumpserver/.env # 進入 jumpserver 目錄時將自動載入 python 虛擬環境
2.2 安裝依賴 RPM 包
(py3) [root@test4-8g opt]# cd /opt/jumpserver/requirements
(py3) [root@test4-8g requirements]# yum -y install $(cat rpm_requirements.txt) # 如果沒有任何報錯請繼續
2.3 安裝 Python 庫依賴
#pip國內源地址
#pip install pip -U
#pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple # 清華鏡像源
(py3) [root@test4-8g requirements]# pip install -r requirements.txt # pip國外源下載緩慢,強烈建議使用國內源
2.4 安裝 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
(py3) [root@test4-8g requirements]# yum -y install redis
(py3) [root@test4-8g requirements]# systemctl enable redis
(py3) [root@test4-8g requirements]# systemctl start redis
2.5 安裝 MySQL
(py3) [root@test4-8g ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
(py3) [root@test4-8g ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
(py3) [root@test4-8g ~]# yum install mysql-server -y
(py3) [root@test4-8g ~]# systemctl start mysqld
(py3) [root@test4-8g ~]# systemctl enable mysqld
2.6 創建數據庫 Jumpserver 並授權
MySq首次登陸數據庫密碼 #
grep passw /var/log/mysql.log
Root密碼修改後進行以下操作 #mysqladmin -uroot -p'password' password 'password'
(py3) [root@test4-8g ~]# mysql -uroot -p
> create database jumpserver default charset 'utf8'; # 建庫
> grant all on jumpserver.* to 'jumpserver'@'%' identified by 'Jumpserver@123'; #創建用戶並授權
> flush privileges;
2.7 修改 Jumpserver 配置文件
(py3) [root@test4-8g ~]# cd /opt/jumpserver/
(py3) [root@test4-8g jumpserver]# cp config_example.py config.py
(py3) [root@test4-8g jumpserver]# vim config.py
# 去掉以下注釋並修改(留意數據庫用戶名以及密碼的修改)
# MySQL or postgres setting like:
DB_ENGINE = os.environ.get("DB_ENGINE") or 'mysql'
DB_HOST = os.environ.get("DB_HOST") or '127.0.0.1'
DB_PORT = os.environ.get("DB_PORT") or 3306
DB_USER = os.environ.get("DB_USER") or 'jumpserver'
DB_PASSWORD = os.environ.get("DB_PASSWORD") or 'Jumpserver@123'
DB_NAME = os.environ.get("DB_NAME") or 'jumpserver'
# When Django start it will bind this host and port
# Django 監聽的ip和端口
# ./manage.py runserver 127.0.0.1:8080
HTTP_BIND_HOST = '192.168.11.207' # 本機IP
HTTP_LISTEN_PORT = 8080
2.8 生成數據庫表結構和初始化數據
(py3) [root@test4-8g jumpserver]# cd /opt/jumpserver/utils/
(py3) [root@test4-8g utils]# bash make_migrations.sh
2.9 運行 Jumpserver
(py3) [root@test4-8g utils]# cd /opt/jumpserver/
(py3) [root@test4-8g jumpserver]# ./jms start all # 後臺運行使用 -d 參數./jms start all -d
運行不報錯,請瀏覽器訪問 http://192.168.11.207:8080/ 默認賬號: admin 密碼: admin 頁面顯示不正常先不用處理,繼續往下操作,後面搭建 nginx 代理後即可正常訪問,原因是因爲 django 無法在非 debug 模式下加載靜態資源
三. 安裝 SSH Server 和 WebSocket Server: Coco
3.1 下載或 Clone 項目
新開一個終端,別忘了 source /opt/py3/bin/activate
(py3) [root@test4-8g ~]# cd /opt/
(py3) [root@test4-8g opt]# git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master
(py3) [root@test4-8g coco]# echo "source /opt/py3/bin/activate" > /opt/coco/.env # 進入 coco 目錄時將自動載入 python 虛擬環境
3.2 安裝依賴
(py3) [root@test4-8g opt]# cd /opt/coco/requirements/
(py3) [root@test4-8g requirements]# yum -y install $(cat rpm_requirements.txt)
(py3) [root@test4-8g requirements]# pip install -r requirements.txt
注:
pip install -r requirements.txt
遇到一個包jumpserver-python-sdk
版本不對
解決辦法:好像是國內的鏡像同步不到最新的版本,我把之前的pip國內鏡像源先註釋掉,然後就下載成功
3.3 修改配置文件並運行
(py3) [root@test4-8g requirements]# cd /opt/coco/
(py3) [root@test4-8g coco]# mkdir keys
(py3) [root@test4-8g coco]# cp conf_example.py conf.py # 如果 coco 與 jumpserver 分開部署,請手動修改 conf.py
(py3) [root@test4-8g coco]# vim conf.py
# 項目名稱, 會用來向Jumpserver註冊, 識別而已, 不能重複
# NAME = "localhost"
NAME = "coco"
# Jumpserver項目的url, api請求註冊會使用
# CORE_HOST = os.environ.get("CORE_HOST") or 'http://127.0.0.1:8080'
CORE_HOST = os.environ.get("CORE_HOST") or 'http://192.168.11.207:8080'
# 設置日誌級別 ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'CRITICAL']
# LOG_LEVEL = 'INFO'
LOG_LEVEL = 'WARN'
#其他默認
3.4 啓動coco
(py3) [root@test4-8g coco]# ./cocod start -d # 後臺運行使用 -d
啓動時遇到問題
FileNotFoundError: [Errno 2] No such file or directory: '/opt/coco/logs/coco.log'
解決 : 創建'/opt/coco/logs/coco.log'
文件
啓動成功後去Jumpserver 會話管理-終端管理 http://192.168.11.207:8080/terminal/terminal/ 接受coco的註冊
四. 安裝 Web Terminal 前端: Luna
Luna 已改爲純前端,需要 Nginx 來運行訪問
訪問(https://github.com/jumpserver/luna/releases) 下載對應版本的 release 包,直接解壓,不需要編譯
4.1 解壓 Luna
(py3) [root@test4-8g coco]# cd /opt/
(py3) [root@test4-8g opt]# wget https://github.com/jumpserver/luna/releases/download/1.4.3/luna.tar.gz
(py3) [root@test4-8g opt]# tar xvf luna.tar.gz
(py3) [root@test4-8g opt]# chown -R root:root luna
五. 安裝 Windows 支持組件(如果不需要管理 windows 資產,可以直接跳過這一步)
6.1 Docker安裝 (僅針對CentOS7,CentOS6安裝Docker相對比較複雜)
(py3) [root@test4-8g opt]# yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
(py3) [root@test4-8g opt]# yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加docker官方源
(py3) [root@test4-8g opt]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
(py3) [root@test4-8g opt]# yum makecache fast
(py3) [root@test4-8g opt]# yum -y install docker-ce
(py3) [root@test4-8g opt]# systemctl start docker
(py3) [root@test4-8g opt]# systemctl status docker
6.2 啓動 Guacamole
這裏所需要注意的是 guacamole 暴露出來的端口是 8081,若與主機上其他端口衝突請自定義
(py3) [root@test4-8g opt]# docker run --name jms_guacamole -d \
-p 8081:8080 -v /opt/guacamole/key:/config/guacamole/key \
-e JUMPSERVER_KEY_DIR=/config/guacamole/key \
-e JUMPSERVER_SERVER=http://192.168.11.207:8080 \ #填寫jumpserver的url地址
jumpserver/guacamole:latest
啓動成功後去Jumpserver 會話管理-終端管理 http://192.168.11.207:8080/terminal/terminal/ 接受[Gua]開頭的一個註冊
六. 配置 Nginx 整合各組件
6.1 下載Nginx
(py3) [root@test4-8g opt]# yum -y install nginx
6.2 準備配置文件 修改 /etc/nginx/nginx.conf
(py3) [root@test4-8g ~]# vim /etc/nginx/nginx.conf
# 注意註釋 nginx.conf 裏面的 server {} 內容 ,CentOS 6 需要修改文件 /etc/nginx/cond.f/default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://192.168.11.207: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;
}
location /luna/ { # luna 路徑,如果修改安裝目錄,此處需要修改
try_files $uri / /index.html;
alias /opt/luna/;
}
location /media/ { # 錄像位置,如果修改安裝目錄,此處需要修改
add_header Content-Encoding gzip;
root /opt/jumpserver/data/;
}
location /static/ { # 靜態資源,如果修改安裝目錄,此處需要修改
root /opt/jumpserver/data/;
}
location /socket.io/ { # 如果coco安裝在別的服務器,請填寫它的ip
proxy_pass http://192.168.11.207:5000/socket.io/;
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/ { # 如果coco安裝在別的服務器,請填寫它的ip
proxy_pass http://192.168.11.207:5000/coco/;
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/ { # 如果guacamole安裝在別的服務器,請填寫它的ip
proxy_pass http://192.168.11.207:8081/;
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;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
6.3 運行 Nginx
(py3) [root@test4-8g ~]# nginx -t # 確保配置沒有問題, 有問題請先解決
# CentOS 7
(py3) [root@test4-8g ~]# systemctl start nginx
(py3) [root@test4-8g ~]# systemctl enable nginx
# CentOS 6
$ service nginx start
$ chkconfig nginx on
6.4 開始使用 Jumpserver
檢查應用是否已經正常運行
(py3) [root@test4-8g ~]# cd /opt/jumpserver
(py3) [root@test4-8g jumpserver]# ./jms status # 確定jumpserver已經運行,如果沒有運行請重新啓動jumpserver
(py3) [root@test4-8g ~]# cd /opt/coco
(py3) [root@test4-8g coco]# ./cocod status # 確定jumpserver已經運行,如果沒有運行請重新啓動coco
# 如果安裝了 Guacamole
(py3) [root@test4-8g ~]# docker ps # 檢查容器是否已經正常運行,如果沒有運行請重新啓動Guacamole
服務全部啓動後,訪問 http://192.168.11.207,訪問nginx代理的端口,不要再通過8080端口訪問
默認賬號: admin 密碼: admin
如果部署過程中沒有接受應用的註冊,需要到Jumpserver 會話管理-終端管理 接受 Coco Guacamole 等應用的註冊
測試連接
如果登錄客戶端是 macOS 或 Linux ,登錄語法如下
$ ssh -p2222 [email protected]
$ sftp -P2222 [email protected]
密碼: admin
如果登錄客戶端是 Windows ,Xshell Terminal 登錄語法如下
$ ssh [email protected] 2222
$ sftp [email protected] 2222
密碼: admin
如果能登陸代表部署成功
# sftp默認上傳的位置在資產的 /tmp 目錄下
# windows拖拽上傳的位置在資產的 Guacamole RDP上的 G 目錄下