龙空技术网

JumpServer 安装及常见问题处理(很详细,docker,Firewall)

剪自在 693

前言:

现在兄弟们对“jumpservernginx”大概比较关注,姐妹们都需要了解一些“jumpservernginx”的相关资讯。那么小编同时在网络上收集了一些有关“jumpservernginx””的相关文章,希望小伙伴们能喜欢,朋友们一起来了解一下吧!

系统环境

Centos 7 x64

IP:192.168.21.129

一、防火墙 Selinux 设置

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  && if [ "$(getenforce)" != "Disabled" ]; then setsebool -P httpd_can_network_connect 1;	 fi

二、部署环境安装

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 \  && 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 \  && yum -y install wget gcc epel-release git \  && yum install -y yum-utils device-mapper-persistent-data lvm2 \  && yum-config-manager --add-repo  \  && yum makecache fast \  && rpm --import  \  && echo -e "[nginx-stable]\nname=nginx stable repo\nbaseurl=\$releasever/\$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=; > /etc/yum.repos.d/nginx.repo \  && rpm --import  \  && yum -y install redis mariadb mariadb-devel mariadb-server MariaDB-shared nginx docker-ce \  && systemctl enable redis mariadb nginx docker \  && systemctl start redis mariadb \  && yum -y install python36 python36-devel \  && python3.6 -m venv /opt/py3

三、下载组件

echo -e "\033[31m 3. 下载组件 \033[0m" \  && cd /opt \  && if [ ! -d "/opt/jumpserver" ]; then git clone --depth=1 ; fi \  && if [ ! -f "/opt/luna.tar.gz" ]; then wget ; tar xf luna.tar.gz; chown -R root:root luna; fi \  && yum -y install $(cat /opt/jumpserver/requirements/rpm_requirements.txt) \  && source /opt/py3/bin/activate \  && pip install --upgrade pip setuptools -i  \  && pip install $(cat /opt/jumpserver/requirements/requirements.txt | grep ansible) -i  \  && pip install $(cat /opt/jumpserver/requirements/requirements.txt | grep python-gssapi) -i  \  && pip install $(cat /opt/jumpserver/requirements/requirements.txt | grep python-keycloak) -i  \  && pip install -r /opt/jumpserver/requirements/requirements.txt -i  \  && curl -sSL  | sh -s  \  && systemctl restart docker \  && docker pull jumpserver/jms_koko:1.5.0 \  && docker pull jumpserver/jms_guacamole:1.5.0 \  && rm -rf /etc/nginx/conf.d/default.conf \  && wget -O /etc/nginx/conf.d/jumpserver.conf 

四、配置文件

echo -e "\033[31m 4. 处理配置文件 \033[0m" \  && 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 inet | egrep -v '(127.0.0.1|inet6|docker)' | awk '{print $2}' | tr -d "addr:" | head -n 1 | cut -d / -f1`; fi \  && 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

配置数据库密码:

从/opt/jumpserver/config.yml复制DB_PASSWORD

#mysql	> create database jumpserver default charset 'utf8';	> grant all on jumpserver.* to 'jumpserver'@'127.0.0.1' identified by 'DB_PASSWORD';	> flush privileges;

五、启动JumpServer服务

echo -e "\033[31m 5. 启动 Jumpserver \033[0m" \  && systemctl start nginx \  && cd /opt/jumpserver \  && ./jms start all -d \  && docker run --name jms_koko -d -p 2222:2222 -p 5000:5000 -e CORE_HOST= -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN -e LOG_LEVEL=ERROR jumpserver/jms_koko:1.5.0 \  && docker run --name jms_guacamole -d -p 8081:8081 -e JUMPSERVER_SERVER= -e BOOTSTRAP_TOKEN=$BOOTSTRAP_TOKEN jumpserver/jms_guacamole:1.5.0 \  && 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" \  && echo -e "\033[31m 请打开浏览器访问  用户名:admin 密码:admin \033[0m"

六、设置开机启动

echo -e "\033[31m 6. 配置自启 \033[0m" \  && if [ ! -f "/usr/lib/systemd/system/jms.service" ]; then wget -O /usr/lib/systemd/system/jms.service ; chmod 755 /usr/lib/systemd/system/jms.service; fi \  && if [ ! -f "/opt/start_jms.sh" ]; then wget -O /opt/start_jms.sh ; fi \  && if [ ! -f "/opt/stop_jms.sh" ]; then wget -O /opt/stop_jms.sh ; fi \  && if [ "$(cat /etc/rc.local | grep start_jms.sh)" == "" ]; then echo "sh /opt/start_jms.sh" >> /etc/rc.local; chmod +x /etc/rc.d/rc.local; fi \  && echo -e "\033[31m 启动停止的脚本在 /opt 目录下, 如果自启失败可以手动启动 \033[0m"

七、Docker常用命令

1、查看所有镜像

	$ docker images

2、查看所有创建的容器

	$ docker ps -a

3、查看正在运行的容器

	$ docker ps

4、进入正在运行的容器

	$ docker exec -it <容器的 CONTAINER ID 或者 容器 NAMES > /bin/bash

# 例:

	$ docker ps	CONTAINER ID    IMAGE                        COMMAND    CREATED        STATUS       PORTS                     NAMES	ecda634206af    jumpserver/guacamole:test    "/init"    12 days ago    Up 3 days    0.0.0.0:8081->8080/tcp    jms_guacamole
	$ docker exec -it ecda634206af /bin/bash 或 docker exec -it jms_guacamole /bin/bash

5、开始 停止 重启 容器

	$ docker start <容器的 CONTAINER ID 或者 容器 NAMES >	$ docker stop <容器的 CONTAINER ID 或者 容器 NAMES >	$ docker restart <容器的 CONTAINER ID 或者 容器 NAMES >

# 例:

	$ docker ps	CONTAINER ID    IMAGE                        COMMAND    CREATED        STATUS       PORTS                     NAMES	ecda634206af    jumpserver/guacamole:test    "/init"    12 days ago    Up 3 days    0.0.0.0:8081->8080/tcp    jms_guacamole	$ docker start ecda634206af 或 docker start jms_guacamole	$ docker stop ecda634206af 或 docker stop jms_guacamole	$ docker restart ecda634206af 或 docker restart jms_guacamole

6、查看容器 log

	$ docker logs -f <容器的 CONTAINER ID 或者 容器 NAMES >

# 例:

	$ docker ps	CONTAINER ID    IMAGE                        COMMAND    CREATED        STATUS       PORTS                     NAMES	ecda634206af    jumpserver/guacamole:test    "/init"    12 days ago    Up 3 days    0.0.0.0:8081->8080/tcp    jms_guacamole	$ docker logs -f ecda634206af 或 docker logs -f jms_guacamole

7、删除容器

	$ docker rm <容器的 CONTAINER ID 或者 容器 NAMES >

# 例:

	$ docker ps	CONTAINER ID    IMAGE                        COMMAND    CREATED        STATUS       PORTS                     NAMES	ecda634206af    jumpserver/guacamole:test    "/init"    12 days ago    Up 3 days    0.0.0.0:8081->8080/tcp    jms_guacamole	$ docker rm ecda634206af 或 docker rm jms_guacamole

8、删除镜像

	$ docker rmi <镜像的 CONTAINER ID>

# 例:

	$ docker images	REPOSITORY             TAG     IMAGE ID        CREATED        SIZE	jumpserver/guacamole   test    e0c2ec53a8fd    13 days ago    1.23GB	$ docker rmi e0c2ec53a8fd

9、更新镜像

	$ docker pull <镜像地址:版本>

# 例:

	$ docker pull jumpserver/jms_all:latest	$ docker pull jumpserver/jms_koko:1.5.0	$ docker pull jumpserver/jms_guacamole:1.5.0

八、端口及JumpServer状态检查

1、端口

对外Web 80

8080

5000

jms_koko组件 2222

jms_guacamole组件 8081

netstat -anltp

2、JumpServer状态

	#source /opt/py3/bin/activate	#cd /opt/jumpserver	#./jms status

九、Firewalld 使用说明

1、打开 firewalld

	$ systemctl start firewalld

2、端口允许被某固定 IP 访问

	$ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="允许访问的IP" port protocol="tcp" port="端口" accept"	$ firewall-cmd --reload  # 重载规则, 才能生效	$ firewall-cmd --list-all  # 查看使用中的规则

# 举例

# 允许 192.168.100.166 访问 6379 端口

	$ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.100.166" port protocol="tcp" port="6379" accept"

# 允许 172.16.10.166 访问 3306 端口

	$ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="172.16.10.166" port protocol="tcp" port="3306" accept"

# 允许 10.10.10.166 访问 8080 端口

	$ firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.10.10.166" port protocol="tcp" port="8080" accept"

$ firewall-cmd --reload # 重载规则, 才能生效

# 删除规则( add 改成 remove )

	$ firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.100.166" port protocol="tcp" port="6379" accept"	$ firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="172.16.10.166" port protocol="tcp" port="3306" accept"	$ firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="10.10.10.166" port protocol="tcp" port="8080" accept"
	$ firewall-cmd --reload  # 重载规则, 才能生效

3、端口允许所有 IP 访问

	$ firewall-cmd --zone=public --add-port=端口/tcp --permanent	$ firewall-cmd --reload  # 重载规则, 才能生效	$ firewall-cmd --list-all  # 查看使用中的规则

# 举例

# 允许访问 2222 端口

	$ firewall-cmd --zone=public --add-port=2222/tcp --permanent

# 允许访问 8080 端口

	$ firewall-cmd --zone=public --add-port=8080/tcp --permanent

# 删除规则( add 改成 remove )

	$ firewall-cmd --zone=public --remove-port=2222/tcp --permanent	$ firewall-cmd --zone=public --remove-port=8080/tcp --permanent	$ firewall-cmd --reload  # 重载规则, 才能生效

标签: #jumpservernginx #nginx129安装 #jumpserver怎么安装nginx #jumpserver安装配置