参考资料https://docs.jumpserver.org/zh/1.4.8/setup_by_centos7.html?tdsourcetag=s_pcqq_aiomsg
环境
系统: CentOS 7
IP: 192.168.244.144
目录: /opt
数据库: mariadb
代理: nginx
安装堡垒主机jumpsever
首先
#更新yum $ yum update -y
$ systemctl start firewalld
$ firewall-cmd --zone=public --add-port=80/tcp --permanent # nginx 端口
$ firewall-cmd --zone=public --add-port=2222/tcp --permanent # 用户SSH登录端口 coco
–permanent 永久生效, 没有此参数重启后失效
$ firewall-cmd --reload # 重新载入规则
$ setenforce 0
$ sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/selinux/config
1.# 安装依赖包
$ yum -y install wget gcc epel-release git
2.# 安装 Redis, Jumpserver 使用 Redis 做 cache 和 celery broke
$ yum -y install redis
$ systemctl enable redis
$ systemctl start redis
3.# 安装 MySQL, 如果不使用 Mysql 可以跳过相关 Mysql 安装和配置, 支持sqlite3, mysql, postgres等
$ 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;”
4.# 安装 Nginx, 用作代理服务器整合 Jumpserver 与各个组件
$ 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
5.# 安装 Python3.6
$ 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 https://github.com/jumpserver/jumpserver.git
$ cd /opt/jumpserver
$ git checkout 1.4.8
$ 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 -d # 后台运行使用 -d 参数./jms start -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_coco -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 jumpserver/jms_coco:1.4.8
$ 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.4.8
$ cd /opt
$ wget https://github.com/jumpserver/luna/releases/download/1.4.8/luna.tar.gz
$ wget https://demo.jumpserver.org/download/luna/1.4.8/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
=============================================================
$ ssh -p2222 [email protected]
$ sftp -P2222 [email protected]
密码: admin
$ ssh [email protected] 2222
$ sftp [email protected] 2222
密码: admin
如果能登陆代表部署成功
多组件负载说明
$ docker run --name jms_coco01 -d -p 2223:2222 -p 5001:5000 -e CORE_HOST=http://
$ docker run --name jms_coco02 -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 cocossh {
server localhost:2222 weight=1;
server localhost:2223 weight=1; # 多节点
server localhost:2224 weight=1; # 多节点
# 这里是 coco ssh 的后端ip
hash $remote_addr;
}
server {
listen 2220; # 不能使用已经使用的端口, 自行修改, 用户ssh登录时的端口
proxy_pass cocossh;
proxy_connect_timeout 10s;
}
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
# tcp_nopush on;
keepalive_timeout 65;
# 关闭版本显示
server_tokens off;
include /etc/nginx/conf.d/*.conf;
}
$ firewall-cmd --zone=public --add-port=2220/tcp --permanent
$ firewall-cmd --reload
$ vi /etc/nginx/conf.d/jumpserver.conf
upstream jumpserver {
server localhost:8080;
# 这里是 jumpserver 的后端ip
}
upstream cocows {
server localhost:5000 weight=1;
server localhost:5001 weight=1; # 多节点
server localhost:5002 weight=1; # 多节点
# 这里是 coco ws 的后端ip
ip_hash;
}
upstream guacamole {
server localhost:8081 weight=1;
server localhost:8082 weight=1; # 多节点
server localhost:8083 weight=1; # 多节点
# 这里是 guacamole 的后端ip
ip_hash;
}
server {
listen 80;
server_name demo.jumpserver.org; # 自行修改成你的域名
client_max_body_size 100m; # 录像上传大小限制
location / {
proxy_pass http://jumpserver;
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 /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://cocows/socket.io/; # coco
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://cocows/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://guacamole/; # guacamole
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;
}
}
$ nginx -t
$ nginx -s reload