Jumpserver部署安装
$ yum update -y # Centos7.4环境下可不用执行升级命令
$ yum -y install vim*
$ systemctl stop firewalld.service
$ systemctl disable firewalld.service
$ vim /etc/selinux/config
$ SELINUX=disabled
$ setenforce 0
$ systemctl start firewalld
$ firewall-cmd --zone=public --add-port=80/tcp --permanent # nginx 端口
$ firewall-cmd --zone=public --add-port=2222/tcp --permanent # 用户SSH登录端口 koko
–permanent 永久生效, 没有此参数重启后失效
$ firewall-cmd --reload # 重新载入规则
$ setenforce 0
$ sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/selinux/config
$ yum -y install wget gcc epel-release git
$ yum -y install redis
$ systemctl enable redis
$ systemctl start redis
$ yum -y install mariadb mariadb-devel mariadb-server mariadb-shared # centos7下叫mariadb, 用法与mysql一致
$ systemctl enable mariadb
$ systemctl start mariadb
$ DB_PASSWORD=cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24
# 生成随机数据库密码
$ echo -e “\033[31m 你的数据库密码是 $DB_PASSWORD \033[0m”
$ mysql -uroot -e “create database jumpserver default charset ‘utf8’; grant all on jumpserver.* to ‘jumpserver’@‘127.0.0.1’ identified by ‘$DB_PASSWORD’; flush privileges;”
$ vi /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
$ systemctl enable nginx
$ yum -y install python36 python36-devel
$ cd /opt
$ python3.6 -m venv py3 # py3 为虚拟环境名称, 可自定义
$ source /opt/py3/bin/activate # 退出虚拟环境可以使用 deactivate 命令
(py3) [root@localhost py3]
$ cd /opt/
$ git clone --depth=1 https://github.com/jumpserver/jumpserver.git
$ yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt)
$ pip install --upgrade pip setuptools
$ pip install -r /opt/jumpserver/requirements/requirements.txt
$ cd /opt/jumpserver
$ cp config_example.yml config.yml
$ SECRET_KEY=cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50
# 生成随机SECRET_KEY
$ echo “SECRET_KEY=$SECRET_KEY” >> ~/.bashrc
$ BOOTSTRAP_TOKEN=cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16
# 生成随机BOOTSTRAP_TOKEN
$ echo “BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN” >> ~/.bashrc
$ 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
$ echo -e “\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m”
$ echo -e “\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m”
$ vi config.yml # 确认内容有没有错误
SECRET_KEY:
BOOTSTRAP_TOKEN:
DEBUG: false
LOG_LEVEL: ERROR
SESSION_EXPIRE_AT_BROWSER_CLOSE: true
DB_ENGINE: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USER: jumpserver
DB_PASSWORD:
DB_NAME: jumpserver
HTTP_BIND_HOST: 0.0.0.0
HTTP_LISTEN_PORT: 8080
REDIS_HOST: 127.0.0.1
REDIS_PORT: 6379
$ cd /opt/jumpserver
$ ./jms start all -d # 后台运行使用 -d 参数./jms start all -d
$ yum install -y yum-utils device-mapper-persistent-data lvm2
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ yum makecache fast
$ rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
$ yum -y install docker-ce
$ systemctl enable docker
$ curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
$ systemctl restart docker
$ firewall-cmd --permanent --add-rich-rule=“rule family=“ipv4” source address=“172.17.0.0/16” port protocol=“tcp” port=“8080” accept”
$ firewall-cmd --reload
$ Server_IP=ip addr | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1
$ echo -e “\033[31m 你的服务器IP是 $Server_IP \033[0m”
$ docker run --name jms_koko -d -p 2222:2222 -p 5000:5000 -e CORE_HOST=http:// S e r v e r I P : 8080 − e B O O T S T R A P T O K E N = Server_IP:8080 -e BOOTSTRAP_TOKEN= ServerIP:8080−eBOOTSTRAPTOKEN=BOOTSTRAP_TOKEN -e LOG_LEVEL=ERROR jumpserver/jms_koko:1.5.0
$ docker run --name jms_guacamole -d -p 8081:8081 -e JUMPSERVER_SERVER=http:// S e r v e r I P : 8080 − e B O O T S T R A P T O K E N = Server_IP:8080 -e BOOTSTRAP_TOKEN= ServerIP:8080−eBOOTSTRAPTOKEN=BOOTSTRAP_TOKEN jumpserver/jms_guacamole:1.5.0
$ 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
$ rm -rf /etc/nginx/conf.d/default.conf
$ vi /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;
}
}
$ nginx -t # 确保配置没有问题, 有问题请先解决
$ systemctl start nginx
$ cd /opt
$ python3.6 -m venv py3
$ source /opt/py3/bin/activate
$ cd /opt/jumpserver
$ ./jms start all -d
$ docker start jms_koko
$ docker start jms_guacamole
Docker 组件部署自启 (Centos 7)
$ vi /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
ExecReload=
ExecStop=/opt/jumpserver/jms stop
[Install]
WantedBy=multi-user.target
$ vi /opt/start_jms.sh
#!/bin/bash
set -e
export LANG=zh_CN.UTF-8
systemctl start jms
docker start jms_koko
docker start jms_guacamole
exit 0
$ vi /opt/stop_jms.sh
#!/bin/bash
set -e
export LANG=zh_CN.UTF-8
docker stop jms_koko
docker stop jms_guacamole
systemctl stop jms
exit 0
$ chmod +x /etc/rc.d/rc.local
$ if [ “$(cat /etc/rc.local | grep start_jms.sh)” == “” ]; then echo “sh /opt/start_jms.sh” >> /etc/rc.local; fi
多组件负载说明
$ docker run --name jms_koko01 -d -p 2223:2222 -p 5001:5000 -e CORE_HOST=http://
$ docker run --name jms_koko02 -d -p 2224:2222 -p 5002:5000 -e CORE_HOST=http://
…
$ docker run --name jms_guacamole01 -d -p 8082:8081 -e JUMPSERVER_SERVER=http://
$ docker run --name jms_guacamole02 -d -p 8083:8081 -e JUMPSERVER_SERVER=http://
…
$ vi /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
stream {
log_format proxy ' r e m o t e a d d r [ remote_addr [ remoteaddr[time_local] ’
‘$protocol $status $bytes_sent KaTeX parse error: Double superscript at position 41: … '̲session_time “KaTeX parse error: Double superscript at position 41: … '̲"upstream_bytes_sent” “ u p s t r e a m b y t e s r e c e i v e d " " upstream_bytes_received" " upstreambytesreceived""upstream_connect_time”’;
access_log /var/log/nginx/tcp-access.log proxy;
open_log_file_cache off;
upstream kokossh {
server localhost:2222 weight=1;
server localhost:2223 weight=1; # 多节点
server localhost:2224 weight=1; # 多节点
# 这里是 koko ssh 的后端ip
hash $remote_addr;
}
server {
listen 2220; # 不能使用已经使用的端口, 自行修改, 用户ssh登录时的端口
proxy_pass kokossh;
proxy_connect_timeout 10s;
}
}