1. 程式人生 > >jumpserver安裝與部署

jumpserver安裝與部署

格式 可能 header 安裝 wal pro data oot edge

1.簡介

Jumpserver 是一款由Python編寫開源的跳板機(堡壘機)系統,實現了跳板機應有的功能。基於ssh協議來管理,客戶端無需安裝agent。
特點:
完全開源,GPL授權
Python編寫,容易再次開發
實現了跳板機基本功能,認證、授權、審計
集成了Ansible,批量命令等
支持WebTerminal
Bootstrap編寫,界面美觀
自動收集硬件信息
錄像回放
命令搜索
實時監控
批量上傳下載

2.部署環境

系統:centos7
ip:192.168.199.218 關閉selinux 和防火墻 CentOS 7 setenforce
0 # 可以設置配置文件永久關閉 systemctl stop iptables.service systemctl stop firewalld.service 修改字符集,否則可能報 input/output error的問題,因為日誌裏打印了中文 localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 export LC_ALL=zh_CN.UTF-8echo LANG=zh_CN.UTF-8 > /etc/locale.conf CentOS6 setenforce 0 service iptables stop
2.1準備Python環境和Python虛擬環境

2.1.1安裝依賴包

yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git

2.1.2編譯安裝

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar xvf Python-3.6.1.tar.xz && cd Python-3.6.1
./configure && make && make install

# 這裏必須執行編譯安裝,否則在安裝 Python 庫依賴時會有麻煩...

2.1.3建立Python虛擬環境
centos 7 自帶的是 Python2,而 Yum 等工具依賴原來的 Python,為了不擾亂原來的環境我們來使用 Python 虛擬環境

cd /opt
python3 -m venv py3
source /opt/py3/bin/activate

# 看到下面的提示符代表成功,以後運行 Jumpserver 都要先運行以上 source 命令,以下所有命令均在該虛擬環境中運行

(py3) [root@localhost py3
2.2安裝Jumpserver 1.0.0

2.2.1下載或 Clone 項目
#項目提交較多 git clone 時較大,你可以選擇去 Github 項目頁面直接下載zip包。直接下載unzip 修改文件名會更快(推薦)

cd /opt/
git clone --depth=1 https://github.com/jumpserver/jumpserver.git && cd jumpserver && git checkout master

2.2.2安裝依賴 RPM

cd /opt/jumpserver/requirements
yum -y install $(cat rpm_requirements.txt) # 如果沒有任何報錯請繼續

2.2.3安裝Python庫依賴

pip install -r requirements.txt # 不要指定-i參數,因為鏡像上可能沒有最新的包,如果沒有任何報錯請繼續

2.2.4安裝redis,jumpserver使用redis做cache和celery broke

yum -y install redis
systemctl start redis
# centos6
service redis start

2.2.5安裝 MySQL

#本教程使用 Mysql 作為數據庫,如果不使用 Mysql 可以跳過相關 Mysql 安裝和配置

# centos7
yum -y install mariadb mariadb-devel mariadb-server # centos7下安裝的是mariadb
systemctl enable mariadb
systemctl start mariadb # 報錯使用service mysqld start
# centos6
yum -y install mysql mysql-devel mysql-server
chkconfig mysqld on
service mysqld start

2.2.6創建數據庫jumpserver 並且授權

mysql 
create database jumpserver default charset utf8;
grant all on jumpserver.* to jumpserver@127.0.0.1 identified by somepassword;

2.2.7修改jumpserver 配置文件

cd /opt/jumpserver
cp config_example.py config.py
vi config.py
# 我們計劃修改 DevelopmentConfig 中的配置,因為默認 Jumpserver 使用該配置,它繼承自 Config
註意: 配置文件是 Python 格式,不要用 TAB,而要用空格
class DevelopmentConfig(Config):
DEBUG = True
DB_ENGINE = mysql
DB_HOST = 127.0.0.1
DB_PORT = 3306
DB_USER = jumpserver
DB_PASSWORD = somepassword
DB_NAME = jumpserver
...
config = DevelopmentConfig() # 確保使用的是剛才設置的配置文件

2.2.8 生成數據庫表結構和初始化數據

cd /opt/jumpserver/utils
bash make_migrations.sh

2.2.9運行jumpserver

cd /opt/jumpserver
./jms start all # 後臺運行使用 -d 參數./jms start all -d

# 新版本更新了運行腳本,使用方式./jms start|stop|status|restart all 後臺運行請添加 -d 參數

賬號密碼:admin

附上重啟的方法(這裏待優化)
ps axu | egrep ‘(gunicorn|celery|beat)‘
ps axu | egrep ‘(gunicorn|celery|beat)‘ | awk ‘{ print $2 }‘ | xargs kill -9

技術分享圖片

2.3安裝 ssh server 和websocket server:Coco

2.3.1下載或者克隆項目
新建終端,連接測試機 別忘了 source /opt/py3/bin/activate

cd /opt
source /opt/py3/bin/activate
git clone https://github.com/jumpserver/coco.git && cd coco && git checkout master

2.3.2安裝依賴

cd /opt/coco/requirements
yum -y install $(cat rpm_requirements.txt)
pip install -r requirements.txt

2.3.3 查看配置文件並運行

cd /opt/coco
cp conf_example.py conf.py
./cocod start # 後臺運行使用 -d 參數./cocod start -d

# 新版本更新了運行腳本,使用方式./cocod start|stop|status|restart 後臺運行請添加 -d 參數

這時需要去 Jumpserver 管理後臺-會話管理-終端管理(http://192.168.199.218:8080/terminal/terminal/)接受 Coco 的註冊
Coco version 1.0.0, more see https://www.jumpserver.org
Starting ssh server at 0.0.0.0:2222
Quit the server with CONTROL-C.
2.3.4測試連接(本IP是192.168.199.218)
ssh -p2222 [email protected]
密碼: admin
如果是用在 Windows 下,Xshell Terminal 登錄語法如下
ssh [email protected] 2222
密碼: admin
如果能登陸代表部署成功

2.4安裝 Web Terminal 前端: Luna

Luna 已改為純前端,需要 Nginx 來運行訪問
訪問(https://github.com/jumpserver/luna/releases)下載對應版本的 release 包,直接解壓,不需要編譯
2.4.1 解壓 Luna

pwd
/opt/

wget https://github.com/jumpserver/luna/releases/download/v1.0.0/luna.tar.gz
tar xvf luna.tar.gz
ls /opt/luna
2.5.安裝windows支持組件

因為手動安裝 guacamole 組件比較復雜,這裏提供打包好的 docker 使用, 啟動 guacamole
2.5.1 Docker安裝 (僅針對CentOS7,CentOS6安裝Docker相對比較復雜)

yum remove docker-latest-logrotate docker-logrotate docker-selinux dockdocker-engine
yum install docker.x86
yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge
yum-config-manager --enable docker-ce-test
yum-config-manager --disable docker-ce-edge
yum install docker-ce
systemctl status docker
systemctl start docker
systemctl status docker

2.5.2 啟動 Guacamole
這裏所需要註意的是 guacamole 暴露出來的端口是 8081,若與主機上其他端口沖突請自定義
修改 JUMPSERVER_SERVER 環境變量的配置,填上 Jumpserver 的內網地址, 啟動成功後去 Jumpserver 會話管理-終端管理
(http://192.168.199.218:8080/terminal/terminal/)接受[Gua]開頭的一個註冊
# 註意:這裏一定要改寫一下本機的IP地址, 否則會出錯, 帶寬有限, 下載時間可能有點長,可以喝杯咖啡,撩撩對面的妹子

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://<填寫本機的IP地址>:8080 \
registry.jumpserver.org/public/guacamole:1.0.0
2.6.配置 Nginx 整合各組件

2.6.1 安裝 Nginx 根據喜好選擇安裝方式和版本

yum -y install nginx

2.6.2 準備配置文件 修改 /etc/nginx/conf.d/jumpserver.conf

vim /etc/nginx/nginx.conf

... 省略
# 把默認server配置塊改成這樣

server {
listen 80;

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/ {
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/ {
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";
}

location /guacamole/ {
proxy_pass http://localhost:8081/; # 如果guacamole安裝在別的服務器,請填寫它的ip
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
access_log off;
}

location / {
proxy_pass http://localhost:8080; # 如果jumpserver安裝在別的服務器,請填寫它的ip
}
}

2.6.3 運行 Nginx

nginx -t # 確保配置沒有問題, 有問題請先解決

# CentOS 7

systemctl start nginx systemctl enable nginx #CentOS 6 service nginx start chkconfig nginx on

3.訪問效果

技術分享圖片

技術分享圖片

tips:

0. git太慢的時候選擇直接下載
unzip 解壓

1.沒有可用軟件包 Redis.
yum添加epel源:yum install epel-release
2.Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-8ew7s0ye/mysqlclient/

pip install --upgrade pip

3.Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.

service mysqld start

4.Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘

mysql -h 127.0.0.1

5.Command "python setup.py egg_info" failed with error code 1

python -m pip install --upgrade --force pip 
pip install setuptools==33.1.1 

6.最好用 163 的yum

7.沒有可用軟件包 docker-ce。
錯誤:無須任何處理


8.一定設置好或關閉防火墻等等

參考

把有道筆記分享

1.centos7 安裝jumpserver3.0跳板機
2.官方文檔

未來工作

詳細學習使用jumpserver介紹

jumpserver安裝與部署