$ echo -e "\033[31m 1. 防火墙 Selinux 设置 \033[0m" \
&& if [ "$(systemctl status firewalld | grep running)" != "" ]; then firewall-cmd --zone=public --add-port=80/tcp --permanent; firewall-cmd --zone=public --add-port=2222/tcp --permanent; 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; fi \ #设置防火墙,这台机器需要被访问80端口和2222端口,容器的8080跟宿主机通信accept;
&& if [ "$(getenforce)" != "Disabled" ]; then setsebool -P httpd_can_network_connect 1; fi #关闭selinux;
- end
- end
- end
$ echo -e "\033[31m 2. 部署环境 \033[0m" \
&& yum update -y \ #把系统更新到最新;
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ #时间设置;
&& yum -y install kde-l10n-Chinese \ #语言方面的支持;Chinese (Simplified Chinese) language support for KDE;
&& localedef -c -f UTF-8 -i zh_CN zh_CN.UTF-8 \ #语言方面的支持;The glibc-common package includes common binaries for the GNU libc libraries, as well as national language (locale) support;
&& export LC_ALL=zh_CN.UTF-8 \ #语言方面的支持;LC_ALL是最上级设定或者强制设定;LC_ALL > LC_* >LANG;
&& echo 'LANG="zh_CN.UTF-8"' > /etc/locale.conf \ #语言方面的支持;Specifies the default locale for all unset locale variables;Locale是根据计算机用户所使用的语言,所在国家或者地区,以及当地的文化传统所定义的一个软件运行时的语言环境。;
&& yum -y install wget gcc epel-release git \ #库文件和一些工具;
&& yum install -y yum-utils device-mapper-persistent-data lvm2 \ #另外一些工具;为什么需要lvm2呢?更好的使用硬盘空间?
#yum-utils is a collection of utilities and examples for the yum package manager. It includes utilities by different authors that make yum easier and more powerful to use. These tools include: debuginfo-install, find-repos-of-install, needs-restarting, package-cleanup, repoclosure, repodiff, repo-graph, repomanage, repoquery, repo-rss, reposync, repotrack, show-installed, show-changed-rco, verifytree, yumdownloader, yum-builddep, yum-complete-transaction, yum-config-manager, yum-debug-dump, yum-debug-restore and yum-groups-manager.;
#Device mapper是Linux2.6内核中提供的一种从逻辑设备到物理设备的映射机制,在该机制下,用户能够很方便的根据自己的需要实现对存储资源的管理。在具体管理时需要用到Linux下的逻辑卷管理器,当前比较流行的逻辑卷管理器有 LVM2(Linux Volume Manager 2 version)、EVMS(Enterprise Volume Management System)、dmraid(Device Mapper Raid Tool)等;
#mapper简单说明:为了方便叙述,假设一台服务器有三块硬盘分别为a,b,c,每块硬盘的容量为1T。在安装Linux的时候,先根据系统及自身的需要建立基本的分区,假设对硬盘a进行了分区,分出去了0.1T的空间挂载在/boot目录下,其他硬盘未进行分区。系统利用Device mapper机制建立了一个卷组(volume group,VG),你可以把VG当做一个资源池来看待,最后在VG上面再创建逻辑卷(logical volume,LV)。若要将硬盘a的剩余空间、硬盘b和硬盘c都加入到VG中,则硬盘a的剩余空间首先会被系统建立为一个物理卷(physical volume,PV),并且这个物理卷的大小就是0.9T,之后硬盘a的剩余的空间、硬盘b和硬盘c以PV的身份加入到VG这个资源池中,然后你需要多大的空间,就可以从VG中划出多大的空间(当然最大不能超过VG的容量)。比如此时池中的空间就是2.9T,此时你就可以建立一个1T以上的空间出来,而不像以前最大的容量空间只能为1T。
#/dev/mapper/Volume-lv_root的意思是说你有一个VG (volume group卷组)叫作Volume, 这个Volume里面有一个LV叫作lv_root。其实这个/dev/mapper/Volume-lv_root文件是一个连接文件,是连接到/dev/dm-0的,你可以用命令ll /dev/mapper/Volume-lv_root进行查看。
#其实在系统里/dev/Volume/lv_root 和 /dev/mapper/Volume-lv_root以及/dev/dm-0都是一个东西,都可当作一个分区来对待。
&& yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo \ #yum-config-manager - manage yum configuration options and yum repositories;添加一个yum源;
&& yum makecache fast \ #much like "yum clean expire-cache";
&& rpm --import https://mirrors.aliyun.com/docker-ce/linux/centos/gpg \ #安装GPG公钥,确保安装与安装密钥相同的软件;
&& echo -e "[nginx-stable]\nname=nginx stable repo\nbaseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=https://nginx.org/keys/nginx_signing.key" > /etc/yum.repos.d/nginx.repo \ #安装nginx的yum源;
&& rpm --import https://nginx.org/keys/nginx_signing.key \ #安装nginx的公钥;
&& yum -y install redis mariadb mariadb-devel mariadb-server MariaDB-shared nginx docker-ce \ #安装数据库相关和docker;
&& systemctl enable redis mariadb nginx docker \ #设置开机启动;
&& systemctl start redis mariadb \ #启动redis mariadb;
&& yum -y install python36 python36-devel \ #安装python相关模块;开发包;
&& python3.6 -m venv /opt/py3 #建立虚拟python3.6环境;虚拟的python3.6环境区别于系统的python环境;
- end
- end
- end
$ echo -e "\033[31m 3. 下载组件 \033[0m" \
&& cd /opt \ #进入python环境目录;
&& if [ ! -d "/opt/jumpserver" ]; then git clone --depth=1 https://github.com/jumpserver/jumpserver.git; fi \ #下载jumpserver项目内容;
&& if [ ! -f "/opt/luna.tar.gz" ]; then wget https://demo.jumpserver.org/download/luna/1.5.6/luna.tar.gz; tar xf luna.tar.gz; chown -R root:root luna; fi \ #安装luna;
#Luna 是一款开源的自动化web漏洞扫描工具,利用最轻量的代码构建被动式扫描框架。主要用途是实现对漏洞扫描策略的快速验证,验证源来自burpsuite中收集的httplog,扫描策略来自独立的python插件。;
&& yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt) \ #安装大量devel文件,支持后续的安装和一些工具;
#包括gcc krb5-devel libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel sshpass openldap-devel mariadb-devel mysql-devel libffi-devel openssh-clients telnet openldap-clients ;
&& echo -e "[easy_install]\nindex_url = https://mirrors.aliyun.com/pypi/simple/" > ~/.pydistutils.cfg \ #应该是告诉pip从哪个镜像安装软件;
&& source /opt/py3/bin/activate \ #启动python虚拟环境;
&& pip install wheel -i https://mirrors.aliyun.com/pypi/simple/ \ #应该是使用后面的镜像安装wheel,wheel用于python模块(软件)的安装;
&& pip install --upgrade pip setuptools -i https://mirrors.aliyun.com/pypi/simple/ \ #更新pip, setuptools;
&& pip install -r /opt/jumpserver/requirements/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ \ #安装文件里所有软件;
#包括92个不列出,可自己查看;
&& curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io \ #curl -s silent模式,-S 显示错误, -L跟踪链接指向其他链接;下载脚本,脚本用于给不同版本的系统配置好docker的daemon.json; 修改的值为后面的链接;
&& systemctl restart docker \ #重启docker;
&& docker pull jumpserver/jms_koko:1.5.6 \ #下载镜像;
&& docker pull jumpserver/jms_guacamole:1.5.6 \
&& rm -rf /etc/nginx/conf.d/default.conf \ #删除默认配置文件;
&& wget -O /etc/nginx/conf.d/jumpserver.conf https://demo.jumpserver.org/download/nginx/conf.d/jumpserver.conf #下载nginx配置文件;
- end
-
end
- end
server {
listen 80;
# server_name _;
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 /koko/ {
proxy_pass http://localhost:5000; #转到koko容器;
proxy_buffering off;
proxy_http_version 1.1;
proxy_request_buffering off;
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 /guacamole/ {
proxy_pass http://localhost:8081/; #转到guacamole容器;
proxy_buffering off;
proxy_http_version 1.1;
proxy_request_buffering off;
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 /ws/ {
proxy_pass http://localhost:8070; #转到一个python进程;
proxy_buffering off;
proxy_http_version 1.1;
proxy_request_buffering off;
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;
}
location / {
proxy_pass http://localhost:8080; #转到一个python进程;
proxy_request_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
- end
- end
- end
$ echo -e "\033[31m 4. 处理配置文件 \033[0m" \
&& source ~/.bashrc \
&& if [ "$DB_PASSWORD" = "" ]; then DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24`; fi \
&& if [ "$SECRET_KEY" = "" ]; then SECRET_KEY=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 50`; echo "SECRET_KEY=$SECRET_KEY" >> ~/.bashrc; fi \ #生成密钥存为文件,保存在配置文件;
&& if [ "$BOOTSTRAP_TOKEN" = "" ]; then BOOTSTRAP_TOKEN=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 16`; echo "BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN" >> ~/.bashrc; fi \
&& if [ "$Server_IP" = "" ]; then Server_IP=`ip addr | grep 'state UP' -A2 | grep inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1`; fi \ #找到本机IP存为变量;
&& if [ ! -d "/var/lib/mysql/jumpserver" ]; then 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;"; fi \ #目录不存在生成密码;那应该是生成密码后就会生成目录,而有目录后就不运行此命令,密码搞乱了就麻烦;
&& if [ ! -f "/opt/jumpserver/config.yml" ]; then cp /opt/jumpserver/config_example.yml /opt/jumpserver/config.yml; 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; fi #修改jumperserver的配置文件,把密钥等更新上去;
- end
- end
- end
$ echo -e "\033[31m 5. 启动 Jumpserver \033[0m" \
&& systemctl start nginx \ #启动nginx;
&& cd /opt/jumpserver \ #进入目录;
&& ./jms start -d \ #后台启动jumperserver;
&& docker run --name jms_koko -d -p 2222:2222 -p 127.0.0.1:5000:5000 -e CORE_HOST=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN --restart=always jumpserver/jms_koko:1.5.6 \ #-e传入变量, 宿主机2222端口需要开通访问;访问/koko/转到容器的5000端口;
&& docker run --name jms_guacamole -d -p 127.0.0.1:8081:8080 -e JUMPSERVER_SERVER=http://$Server_IP:8080 -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN --restart=always jumpserver/jms_guacamole:1.5.6 \ #访问/guacamole/转到容器8080; docker服务启动,容器自动启动;
&& echo -e "\033[31m 你的数据库密码是 $DB_PASSWORD \033[0m" \
&& echo -e "\033[31m 你的SECRET_KEY是 $SECRET_KEY \033[0m" \
&& echo -e "\033[31m 你的BOOTSTRAP_TOKEN是 $BOOTSTRAP_TOKEN \033[0m" \
&& echo -e "\033[31m 你的服务器IP是 $Server_IP \033[0m" \ #显示内网IP,如是公网,自行更换;
&& echo -e "\033[31m 请打开浏览器访问 http://$Server_IP 用户名:admin 密码:admin \033[0m"
- end
- end
- end
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
43403abb934e jumpserver/jms_guacamole:1.5.6 "/init" 3 minutes ago Up 3 minutes 127.0.0.1:8081->8080/tcp jms_guacamole
f4ea0c649e87 jumpserver/jms_koko:1.5.6 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 0.0.0.0:2222->2222/tcp, 33060/tcp, 127.0.0.1:5000->5000/tcp jms_koko
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# docker port 43403a
8080/tcp -> 127.0.0.1:8081
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# docker port f4ea0c
5000/tcp -> 127.0.0.1:5000
2222/tcp -> 0.0.0.0:2222
- end
- end
- end
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8070 0.0.0.0:* LISTEN 5421/python3.6
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 5468/docker-proxy
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1999/mysqld
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1747/redis-server 1
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 5364/python3.6
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5330/nginx: master
tcp 0 0 127.0.0.1:8081 0.0.0.0:* LISTEN 5571/docker-proxy
tcp 0 0 0.0.0.0:5555 0.0.0.0:* LISTEN 5407/python3.6
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1136/sshd
tcp6 0 0 :::2222 :::* LISTEN 5482/docker-proxy
tcp6 0 0 :::5555 :::* LISTEN 5407/python3.6
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# ps aux |grep 5421 #8070端口进程;
root 4702 0.0 0.0 112728 972 pts/0 S+ 12:21 0:00 grep --color=auto 5421
root 5421 0.2 2.7 527068 101656 pts/0 S 12:06 0:02 /opt/py3/bin/python3.6 /opt/py3/bin/daphne jumpserver.asgi:application -b 0.0.0.0 -p 8070
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# ps aux |grep 5364 #8080端口进程;
root 4716 0.0 0.0 112728 972 pts/0 S+ 12:21 0:00 grep --color=auto 5364
root 5364 0.0 0.5 225612 20792 pts/0 S 12:06 0:00 /opt/py3/bin/python3.6 /opt/py3/bin/gunicorn jumpserver.wsgi -b 0.0.0.0:8080 -k gthread --threads 10 -w 4 --max-requests 4096 --access-logformat %(h)s %(t)s "%(r)s" %(s)s %(b)s --access-logfile -
(py3) [root@iZwz9f4eav9pv0pyv0vg4gZ jumpserver]# ps aux |grep 5482
root 4940 0.0 0.0 112728 972 pts/0 S+ 12:36 0:00 grep --color=auto 5482
root 5482 0.0 0.1 216928 5764 ? Sl 12:06 0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 2222 -container-ip 172.17.0.2 -container-port 2222 #docker-proxy应该是实现容器端口暴露;
- end
- end
- end
$ echo -e "\033[31m 6. 配置自启 \033[0m" \
&& if [ ! -f "/usr/lib/systemd/system/jms.service" ]; then wget -O /usr/lib/systemd/system/jms.service https://demo.jumpserver.org/download/shell/centos/jms.service; chmod 755 /usr/lib/systemd/system/jms.service; systemctl enable jms; fi #下载服务脚本到相应路径并修改权限;
- end
- end
- end
<tany@linux0 ~>$ cat ./.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK2NCvnDvfjqj46xnrn/6s//8jIy+yhiUTuDU24/uvlfC1tn2YGxjXqbd9xNPVao/AcTJyrVVuS7K8Sbx2tlsK2la3qsmVR/mJHxp6qt0sGyZtgVOtLEtohDNCyAJaHuLK2oxkMNRT5WSPqMJx8PrB1Inj+teCvZEB+McnvOX2q8eRWoKtFzZGOMqTDyaLZk1DkSa7ONol5I1y9XB976m7g8T4qHexJsBdwO/2zC9lV9oOmwAl1x3E7uEHwhSBYV7Hxy8ZPgWe4hvWlIgcq0DdYXShxPSyX09J8x/RhkGGg/XdLu+SLDvALFK6Wx9 tany@linux0
- end
- end
- end
<tany@linux0 ~>$ ssh [email protected] -p 2222
handsome, 欢迎使用Jumpserver开源堡垒机系统
1) 输入 部分IP、主机名、备注 进行搜索登录(如果唯一).
2) 输入 / + IP,主机名 or 备注 进行搜索,如:/192.168.
3) 输入 p 进行显示您有权限的主机.
4) 输入 g 进行显示您有权限的节点.
5) 输入 d 进行显示您有权限的数据库.
6) 输入 r 进行刷新最新的机器和节点信息.
7) 输入 h 进行显示帮助.
8) 输入 q 进行退出.
Opt>
- end
- end
- end
使用ssh-keygen生成一对密钥,把 私钥 上传到以下界面
把 公钥 内容放到要被管理的机器 /home/管理用户名/.ssh/authorized_keys 里
这样jumpserver就能通过密钥访问机器
简便来说,应该固定使用这个公钥放置到不同的服务器里,即使用一个管理用户可登陆很多机器
另外文件的权限为600, 属主属组为登陆帐号 “管理用户”
开发用户 - web系统用户 - web资产
开发用户 - 测试系统用户 - 测试资产
如果把一个系统用户部署到几种资产上,感觉增加风险
开发用户 - web系统用户 - web资产
开发用户 - web系统用户 - 测试资产
如果把几个系统用户部署到同一个资产上,在一条规则上,也不太好(没必要添加两个系统用户)
开发用户 - web系统用户 & 测试系统用户 - web资产
<tany@linux0 ~>$ ssh [email protected] -p 2222
beauty, 欢迎使用Jumpserver开源堡垒机系统
1) 输入 部分IP、主机名、备注 进行搜索登录(如果唯一).
2) 输入 / + IP,主机名 or 备注 进行搜索,如:/192.168.
3) 输入 p 进行显示您有权限的主机.
4) 输入 g 进行显示您有权限的节点.
5) 输入 d 进行显示您有权限的数据库.
6) 输入 r 进行刷新最新的机器和节点信息.
7) 输入 h 进行显示帮助.
8) 输入 q 进行退出.
Opt> p
ID | 主机名 | IP | 备注
+-------+-------------------------------+------------------------------------+---------------------------+
1 | web1 | 172.18.13.137 |
页码:1,每页行数:20,总页数:1,总数量:1
提示:输入资产ID直接登录,二级搜索使用 // + 字段,如://192 上一页:b 下一页:n
搜索: 所有
Opt> 1 #选择编号直接登陆;
开始连接到 [email protected] 2.1
Last failed login: Sun Jan 19 20:53:46 CST 2020 from 172.18.13.147 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Sun Jan 19 18:29:22 2020 from 172.18.13.147
Welcome to Alibaba Cloud Elastic Compute Service !
[jump@iZwz9f4eav9pv0pyv0vg4gZ ~]$
[jump@iZwz9f4eav9pv0pyv0vg4gZ user1]$ sudo visudo
jump ALL=(ALL) NOPASSWD: /bin/whoami, ALL #web界面的sudo设置,添加到文件的最后一行;
- end
- end
- end