安裝前配置準備:
centos7安裝部署jumpserver
一、系統環境準備:
1、檢視系統版本
# cat /etc/redhat-release
// 檢視系統版本
CentOS Linux release 7。5。1804 (Core)
# uname -a
// 檢視系統資訊
Linux localhost。localdomain 3。10。0-862。el7。x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2、關閉selinux和防火牆
# getenforce
//檢視selinux的狀態
Disabled
// 如果是Enable需要修改為Disabled,命令是“setenforce 0”
# systemctl stop firewalld。service
// 關閉防火牆
3、修改字符集
因為日誌裡列印了中文,否則肯能報錯:input/output error問題
# localedef -c -f UTF-8 -i zh_CN zh_CN。UTF-8
# export LC_ALL=zh_CN。UTF-8
# echo ‘LANG=“zh_CN。UTF-8”’ > /etc/locale。conf
二、準備Python3和Python虛擬環境:
1、安裝依賴包
# yum -y install wget vim lrzsz xz gcc git epel-release python-pip python-devel mysql-devel automake autoconf sqlite-devel zlib-devel openssl-devel sshpass readline-devel
2、編譯安裝
# yum -y install python36 python36-devel
// 如果下載速度很慢, 可以換國內源
# wget -O /etc/yum。repos。d/epel。repo http://mirrors。aliyun。com/repo/epel-7。repo
# yum -y install python36 python36-devel
3、建立 Python 虛擬環境
CentOS 7 自帶的是 Python2,而 yum 等工具依賴原來的 Python,為了不擾亂原來的環境我們來使用 Python 虛擬環境
# cd /opt
# python3。6 -m venv py3
# source /opt/py3/bin/activate
(py3) [root@localhost opt]#
//看到這一行的提示符代表成功,以後執行 Jumpserver 都要先執行以上 source 命令
以下所有命令均在該虛擬環境中執行:
三、安裝部署 Redis:
安裝 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
(py3) [root@localhost opt]# yum -y install redis
(py3) [root@localhost opt]# systemctl enable redis
(py3) [root@localhost opt]# systemctl start redis
建立所需的檔案目錄
[root@jump src]# mkdir -p /usr/local/redis/{etc,logs,run,data}
修改配置檔案
[root@jump src]# cat << EOF > /usr/local/redis/etc/redis。conf
daemonize yes
port 6379
#指定埠號
bind 127。0。0。1
# 節點IP--改為本機實際的IP地址
protected-mode yes
pidfile “/usr/local/redis/run/redis。pid”
# 指定程序檔案PID位置
loglevel notice
logfile “/usr/local/redis/logs/redis。log”
# 指定日誌檔案位置
save 900 1
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump。rdb
dir “/usr/local/redis/data/rdb/”
timeout 0
tcp-keepalive 300
requirepass Linux@Shizhuang2020。。
# 指定密碼
EOF
啟動Redis並檢視服務啟用埠號
[root@jump src]# mkdir -p /usr/local/redis/data/rdb/
[root@jump src]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis。conf
[root@jump src]# netstat -anpl |grep redis
tcp 0 0 10。0。0。9:6379 0。0。0。0:* LISTEN 12565/redis-server
連線測試Redis
[root@jump src]# /usr/local/redis/bin/redis-cli -h 10。0。0。9 -p 6379 -a ‘Linux@Shizhuang2020。。’
如果沒有找到這個命令的話,可以透過 find / -name redis-cli 去進行查詢 /usr/bin/redis-cli
[root@jump src]# /usr/bin/redis-cli -h 10。0。0。9 -p 6379 -a ‘Linux@Shizhuang2020。。’
Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe。
10。0。0。9:6379> select 1
OK
10。0。0。9:6379[1]> exit
四、安裝部署 Mariadb:
Jumpserver使用資料庫,可以選擇MySQL或者Mariadb;
Mariadb版本需要大於等於5.5.56
,
MySQL版本需要大於等於5.6
這裡使用yum方式部署mariadb
配置Yum源,如果本地Yum源可用,此處可跳過
$ curl -o /etc/yum。repos。d/CentOS-Base-7。repo http://mirrors。aliyun。com/repo/Centos-7。repo
$ yum clean all && yum makecache
安裝並啟動“mariadb”
[root@jump src]# yum list | grep mariadb # 列出“mariadb”相關安裝包
[root@jump src]# yum install mariadb。x86_64 mariadb-devel。x86_64 mariadb-server。x86_64 -y # 安裝“mariadb”
[root@jump src]# systemctl enable mariadb && systemctl start mariadb # 啟動“mariadb”並加入開機自啟
Created symlink from /etc/systemd/system/multi-user。target。wants/mariadb。service to /usr/lib/systemd/system/mariadb。service。
連線“mariadb”資料庫修改“root”密碼
[root@jump src]# mysql -uroot -p
Enter password: #首次連線mariadb,直接回車進入資料庫
MariaDB [(none)]> set password for ‘root’@localhost=password(‘
Linux@Shizhuang2020..
’);
Query OK, 0 rows affected (0。00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0。00 sec)
建立“jumpserver”資料庫並進行授權
MariaDB [(none)]> create database jumpserver character set=‘utf8’ collate=‘utf8_general_ci’;
建立資料庫 jumpserver
Query OK, 1 row affected (0。00 sec)
MariaDB [(none)]> grant all on jumpserver。* to ‘jumpserver’@‘127。0。0。1’ identified by ‘
Linux@Shizhuang2020..
’;
Query OK, 0 rows affected (0。00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0。00 sec)
MariaDB [(none)]> exit;
Bye
五、獲取 JumpServer 程式碼:
載入 Python 虛擬環境
source /opt/py3/bin/activate
cd /opt && \
wget https://github。com/jumpserver/jumpserver/releases/download/v2。2。2/jumpserver-v2。2。2。tar。gz
tar xf jumpserver-v2。2。2。tar。gz
mv jumpserver-v2。2。2 jumpserver
安裝編譯環境依賴
cd /opt/jumpserver/requirements
Centos:
yum install -y $(cat rpm_requirements。txt)
pip install wheel && \
pip install ——upgrade pip setuptools && \
pip install -r requirements。txt
確保已經載入 py3 虛擬環境, 中間如果遇到報錯一般是依賴包沒裝全, 可以透過 搜尋引擎 解決:
cd /opt/jumpserver && \
cp config_example。yml config。yml && \
vi config。yml
注意不能使用純數字字串, 可以參考此模版
啟動 JumpServer:(
確保已經載入 py3 虛擬環境
)
cd /opt/jumpserver
。/jms start
可以 -d 引數在後臺執行
。/jms start -d
六、Docker 部署 KoKo 元件:
七、Docker 部署 Guacamole 元件:
八、配置 Nginx 整合各元件:
1、安裝nginx
(py3)[root@jumpserver opt]# yum install yum-utils
(py3)[root@jumpserver opt]# vi /etc/yum。repos。d/nginx。repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx。org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx。org/keys/nginx_signing。key
(py3)[root@jumpserver opt]# yum makecache fast
(py3)[root@jumpserver opt]# yum install -y nginx
(py3)[root@jumpserver opt]# rm -rf /etc/nginx/conf。d/default。conf
(py3)[root@jumpserver opt]# systemctl enable nginx
2、準備配置檔案,修改/etc/nginx/conf。d/jumpserver。conf
(py3)[root@jumpserver opt]# vim /etc/nginx/conf。d/jumpserver。conf
server {
listen 80;
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/;
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/;
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/;
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;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
3、執行 Nginx
(py3)[root@jumpserver opt]# nginx -t
# 確保配置沒有問題, 有問題請先解決
// centos 7
(py3)[root@jumpserver opt]# systemctl start nginx
(py3)[root@jumpserver opt]# systemctl enable nginx
九、測試jumpser功能:
1、檢查web頁面是否已經正常執行
服務全部啟動後, 訪問 http://192。168。0。1(ip地址是你配置的那臺機器的ip), 訪問nginx代理的埠, 不要再透過8080埠訪問
預設賬號: admin 密碼: admin
到Jumpserver 會話管理-終端管理 檢查 Coco Guacamole 等應用的註冊。
2、測試連線
如果登入客戶端是 macOS 或 Linux, 登入語法如下
$ ssh -p2222 admin@192。168。0。1
$ sftp -P2222 admin@192。168。0。1
密碼: admin
如果登入客戶端是 Windows, Xshell Terminal 登入語法如下
$ ssh admin@192。168。0。1 2222
$ sftp admin@192。168。0。1 2222
密碼: admin
如果能登陸代表部署成功
# sftp預設上傳的位置在資產的 /tmp 目錄下
# windows拖拽上傳的位置在資產的 Guacamole RDP上的 G 目錄下
十、錯誤集合:
錯誤1:
# pip install -r requirements。txt
Command “python setup。py egg_info” failed with error code 1 in /tmp/pip-build-fadyxpv4/mysqlclient/
You are using pip version 9。0。1, however version 19。1。1 is available。
You should consider upgrading via the ‘pip install ——upgrade pip’ command
解決方法:
# pip3 install ——upgrade pip
# pip3 install -r requirements。txt
如遇到執行的時候 PY報錯,請將
pip setuptools 這個版本限制在45。X以下 則可以解決 安裝時的報錯問題
如下
先解除安裝舊版本,再重新下載。
pip uninstall setuptools
pip install setuptools==45。1。0