Python/Diango
进行开发,遵循 Web 2.0 规范,配备了业界领先的 Web Terminal 解决方案,交互界面美观、用户体验好。特点:
JumpServer 实现的功能:
Authentication
| 账号管理 Account
| 授权控制 Authorization
| 安全审计 Audit
JumpServer 为管理后台,管理员可以通过 Web 页面进行资产管理、用户管理、资产授权等操作。
准备工作:
主机名 | 操作系统 | 硬件 | Python | MySQL | Mariadb | Redis |
---|---|---|---|---|---|---|
JumpServer | CentOS 7.4 | CPU 核心数:2 ,内存:4G ,硬盘:50G+ |
= 3.6.x |
≥ 5.6 |
≥ 5.5.56 |
1)上传安装包
[root@JumpServer ~]# ls
anaconda-ks.cfg jumpserver-master.zip jumpserver-packs.tar.gz pip-packs.tar.gz Python-3.6.8.tgz
[root@localhost ~]# tar xf jumpserver-packs.tar.gz
[root@localhost ~]# tar xf pip-packs.tar.gz
[root@localhost ~]# tar xf Python-3.6.8.tgz -C /usr/local/src/
[root@localhost ~]# cat <<END > /etc/yum.repos.d/jumpserver.repo
[JumpServer]
name=CentOS7
baseurl=file:///root/jumpserver-packs
enable=1
gpgcheck=0
END
[root@JumpServer ~]# yum makecache # 建立缓存
3)安装依赖包
[root@localhost ~]# yum -y install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel openldap-devel sshpass
4)编译安装
[root@localhost ~]# cd /usr/local/src/Python-3.6.8/
[root@localhost Python-3.6.8]# ./configure --prefix=/usr/local/python
[root@localhost Python-3.6.8]# make -j `cat /proc/cpuinfo | grep processor | wc -l` #根据 CPU 核心数来进行编译
[root@localhost Python-3.6.8]# make install #安装
5)配置软连接优化执行路径
[root@JumpServer ~]# ln -s /usr/local/python/bin/* /usr/local/bin/
[root@JumpServer ~]# python3 -V
Python 3.6.8
[root@JumpServer ~]# pip3 -V
pip 18.1 from /usr/local/python/lib/python3.6/site-packages/pip (python 3.6)
6/7
自带的是 Python2,而 yum
等工具依赖原来的 Python,目的就是为了不扰乱原来的环境。[root@JumpServer ~]# python3.6 -m venv /opt/py3 #创建 Py3 虚拟环境
[root@JumpServer ~]# source /opt/py3/bin/activate #进入 Py3 虚拟环境
(py3) [root@JumpServer ~]# echo "source /opt/py3/bin/activate" >> .bashrc #加入到开机自启
(py3) [root@JumpServer ~]# yum -y install unzip
(py3) [root@JumpServer ~]# unzip jumpserver-master.zip -d /opt/
(py3) [root@JumpServer ~]# mv /opt/jumpserver-master/ /opt/jumpserver
(py3) [root@JumpServer ~]# yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt) #安装依赖包
方式一:安装 Python 库(没网)
(py3) [root@JumpServer ~]# pip install --no-index --find-links=/root/pip-packs/ pyasn1 six cffi pytest-runner
(py3) [root@JumpServer ~]# pip install --no-index --find-links=/root/pip-packs/ -r /opt/jumpserver/requirements/requirements.txt
注解:
--no-index
:忽略包索引(仅仅从 --find-links
的链接地址中去查找包)--find-links
:如果指定为 IP 地址,就会从该地址进行查找依赖包并进行下载,如果指定的是本地文件,则直接从本地文件下载。方式二:安装 Python 库(有网)
(py3) [root@JumpServer ~]# mkdir /root/.pip
(py3) [root@JumpServer ~]# cat <<END> /root/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple #这个是清华源
[install]
trusted-host=mirrors.aliyun.com
END
(py3) [root@JumpServer ~]# pip install --upgrade pip #更新 pip
(py3) [root@JumpServer ~]# pip install -r /opt/jumpserver/requirements/requirements.txt
(py3) [root@JumpServer ~]# yum -y install redis
(py3) [root@JumpServer ~]# systemctl start redis
(py3) [root@JumpServer ~]# yum -y install mariadb mariadb-server mariadb-devel
(py3) [root@JumpServer ~]# systemctl start mariadb
(py3) [root@JumpServer ~]# mysql
MariaDB [(none)]> create database jumpserver default charset 'utf8';
MariaDB [(none)]> grant all on jumpserver.* to jumpserver@127.0.0.1 identified by 'jumpserver';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
(py3) [root@JumpServer ~]# cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 49;echo
tmctZBlMSF6TEo02tQL6qWNPDBduJ2dAN2eMO6DRDeGekDVro
(py3) [root@JumpServer ~]# cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16;echo
R9e1h2ZFuf8WDDbi
修改 JumpServer 配置文件
(py3) [root@JumpServer ~]# cd /opt/jumpserver/
(py3) [root@JumpServer jumpserver]# cp config_example.yml config.yml
(py3) [root@JumpServer jumpserver]# vim config.yml
# 配置密钥
SECRET_KEY: tmctZBlMSF6TEo02tQL6qWNPDBduJ2dAN2eMO6DRDeGekDVro
BOOTSTRAP_TOKEN: R9e1h2ZFuf8WDDbi
# 数据库设置
DB_ENGINE: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USER: jumpserver
DB_PASSWORD: jumpserver
DB_NAME: jumpserver
# Redis配置
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
# REDIS_PASSWORD:
生成数据库表结构和初始化数据
(py3) [root@JumpServer jumpserver]# cd utils/
(py3) [root@JumpServer utils]# sh make_migrations.sh
(py3) [root@JumpServer ~]# vim /usr/lib/systemd/system/jms.service
[Unit]
Description=jms
After=network.target mariadb.service redis.service docker.service
Wants=mariadb.service redis.service docker.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
ExecRestart=/opt/jumpserver/jms restart all -d
ExecStop=/opt/jumpserver/jms stop
[Install]
WantedBy=multi-user.target
(py3) [root@JumpServer ~]# systemctl daemon-reload
(py3) [root@JumpServer ~]# systemctl start jms
(py3) [root@JumpServer ~]# ls
anaconda-ks.cfg koko-master-6d4e69b-linux-amd64.tar.gz ...
(py3) [root@JumpServer ~]# tar xf koko-master-6d4e69b-linux-amd64.tar.gz -C /opt/
(py3) [root@JumpServer ~]# chown -R root:root /opt/kokodir/
(py3) [root@JumpServer ~]# cd /opt/kokodir/
(py3) [root@JumpServer kokodir]# cp config_example.yml config.yml
(py3) [root@JumpServer kokodir]# vim config.yml #密钥要跟 JumpServer 密钥一致
BOOTSTRAP_TOKEN: R9e1h2ZFuf8WDDbi
SECRET_KEY: tmctZBlMSF6TEo02tQL6qWNPDBduJ2dAN2eMO6DRDeGekDVro
(py3) [root@JumpServer kokodir]# nohup ./koko & #后台运行
(py3) [root@JumpServer kokodir]# netstat -anpt | egrep '2222|5000'
将 KoKo 加入到开启自启
(py3) [root@JumpServer kokodir]# echo "cd /opt/kokodir && nohup ./koko &" >> /etc/rc.local
(py3) [root@JumpServer kokodir]# chmod +x /etc/rc.local
(py3) [root@JumpServer ~]# ls
anaconda-ks.cfg luna.tar.gz ...
(py3) [root@JumpServer ~]# tar xf luna.tar.gz -C /opt/
(py3) [root@JumpServer ~]# chown -R root:root /opt/luna/
(py3) [root@JumpServer ~]# yum -y install nginx
(py3) [root@JumpServer ~]# vim /etc/nginx/nginx.conf
server {
...
client_max_body_size 100m; #录像及文件上传大小限制
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/;
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 / {
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;
}
......
(py3) [root@JumpServer ~]# nginx -t #检查配置文件是否正确
(py3) [root@JumpServer ~]# systemctl start nginx #启动 Nginx 服务
准备工作:(只需要开启两台机器即可,并不需要做相应配置)
主机名 | 操作系统 | IP 地址 |
---|---|---|
Docker | CentOS 7.4 | 192.168.1.2 |
Kubernetes | CentOS 7.4 | 192.168.1.3 |
1)添加被管理端 root
账号
2)添加资产
3)创建命令过滤器
4)创建过滤器规则
5)创建系统用户
1)使用 Web 终端验证
zhangsan
——
会话管理 ——
Web 终端(py3) [root@localhost ~]# ssh zhangsan@192.168.1.1 -p 2222