如何在 Rocky Linux 9 上安装 NetBox

Linux命令 Edge插件网 2年前 (2023-03-10) 523次浏览 已收录 0个评论

NetBox是一个用于管理和记录计算机网络的开源Web应用程序。它是用Python编写的,并使用Django Web框架。它提供了网络基础结构的集中视图,包括 IP 地址、设备、虚拟机以及它们之间的连接。NetBox 还包括用于管理数据中心(包括机架、设备和虚拟机)的内置功能。如何在 Rocky Linux 9 上安装 NetBox

在 Rocky Linux 9 上安装 NetBox

第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:

<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update
sudo dnf install dnf</span><span class="pun">-</span><span class="pln">utils
sudo dnf install gcc libxml2</span><span class="pun">-</span><span class="pln">devel libxslt</span><span class="pun">-</span><span class="pln">devel libffi</span><span class="pun">-</span><span class="pln">devel libpq</span><span class="pun">-</span><span class="pln">devel openssl</span><span class="pun">-</span><span class="pln">devel redhat</span><span class="pun">-</span><span class="pln">rpm</span><span class="pun">-</span><span class="pln">config git</span>

第 2 步。安装 PostgreSQL。

默认情况下,PostgreSQL 在 Rocky Linux 9 基础存储库中不可用。现在运行以下命令将 PostgreSQL 稳定存储库添加到您的系统中:

<span class="pln">sudo dnf install http</span><span class="pun">:</span><span class="com">//apt.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm</span>

接下来,运行以下命令将最新的稳定版本的 PostgreSQL 安装到您的服务器上:

<span class="pln">sudo dnf check</span><span class="pun">-</span><span class="pln">update
sudo dnf install postgresql14</span><span class="pun">-</span><span class="pln">server postgresql14</span><span class="pun">-</span><span class="pln">docs</span>

安装完成后,启动PostgreSQL服务并使其在重新启动时自动启动:

<span class="pln">sudo systemctl enable postgresql</span><span class="pun">-</span><span class="lit">14</span> <span class="pun">--</span><span class="pln">now
sudo systemctl status postgresql</span><span class="pun">-</span><span class="lit">14</span>

现在通过以下命令登录到PostgreSQL shell:

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u postgres psql</span>

然后,为默认的PostgreSQL用户”设置一个新密码:postgres

<span class="pln">ALTER USER postgres WITH PASSWORD </span><span class="str">'Your-Strong-PostgreSQL-Passwd'</span><span class="pun">;</span>

之后,使用用户“”创建一个新的数据库“”,该数据库将用于NetBox安装:netboxdbnetbox

<span class="pln">CREATE DATABASE netboxdb</span><span class="pun">;</span><span class="pln">
CREATE USER netbox WITH ENCRYPTED PASSWORD </span><span class="str">'NetBoxRocks'</span><span class="pun">;</span><span class="pln">
GRANT ALL PRIVILEGES ON DATABASE netboxdb TO netbox</span><span class="pun">;</span>

最后,运行以下命令,通过新用户 ” 登录到新数据库 ” 的 PostgreSQL shell:netboxnetboxdb

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u postgres psql </span><span class="pun">--</span><span class="pln">username netbox </span><span class="pun">--</span><span class="pln">password </span><span class="pun">--</span><span class="pln">host localhost netboxdb</span>

接下来,运行以下查询以验证当前连接:

<span class="pln">\conninfo</span>

有关安装 PostgreSQL 的其他资源,请阅读下面的帖子:

  • 如何在 Rocky Linux √ 上安装 PostgreSQL

第 3 步。安装雷迪斯。

默认情况下,Redis 在 Rocky Linux 9 基础存储库中可用。现在运行以下命令,将最新的稳定版本的 Redis 安装到您的系统中:

<span class="pln">sudo dnf install redis</span>

接下来,启动 Redis 服务,并通过运行以下命令使其能够在引导时自动启动:

<span class="pln">sudo systemctl enable </span><span class="pun">--</span><span class="pln">now redis
sudo systemctl start redis
sudo systemctl status redis</span>

您可以通过运行以下命令来验证 Redis 安装:

<span class="pln">redis</span><span class="pun">-</span><span class="pln">server </span><span class="pun">--</span><span class="pln">version</span>

Redis 将其配置文件存储在 。可以根据需要编辑此文件。/etc/redis/redis.conf

<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">redis</span><span class="pun">/</span><span class="pln">redis</span><span class="pun">.</span><span class="pln">conf</span>

取消注释参数 ” 并输入 Redis 服务器的新密码:require pass

<span class="pln">requirepass </span><span class="typ">RedisPasswordNetBox</span>

保存并关闭文件,然后使用以下命令重新启动 Redis 服务器:

<span class="pln">sudo systemctl restart redis</span>

有关安装 Redis 的其他资源,请阅读下面的帖子:

  • 如何在 Rocky Linux √ 上安装 Redis

第 4 步。在 Rocky Linux 9 上安装 Netbox IRM。

首先,创建一个具有默认主目录 ” 的新系统用户 ”:netbox/opt/netbox

<span class="pln">sudo useradd </span><span class="pun">-</span><span class="pln">r </span><span class="pun">-</span><span class="pln">d </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">sbin</span><span class="pun">/</span><span class="pln">nologin netbox</span>

接下来,通过 git 命令下载最新版本的 NetBox 源代码:

<span class="pln">mkdir </span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">;</span><span class="pln"> cd </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox
sudo git clone </span><span class="pun">-</span><span class="pln">b master </span><span class="pun">--</span><span class="pln">depth </span><span class="lit">1</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//github.com/netbox-community/netbox.git</span>

将工作目录移动到”:/opt/netbox/netbox/netbox

<span class="pln">sudo chown </span><span class="pun">-</span><span class="pln">R netbox</span><span class="pun">:</span><span class="pln">netbox </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox
cd </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">netbox</span>

接下来,运行以下命令将默认 NetBox 配置复制到 ”:configuration.py

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u netbox cp configuration_example</span><span class="pun">.</span><span class="pln">py configuration</span><span class="pun">.</span><span class="pln">py
sudo </span><span class="pun">-</span><span class="pln">u netbox python3 </span><span class="pun">../</span><span class="pln">generate_secret_key</span><span class="pun">.</span><span class="pln">py</span>

然后,使用最喜欢的文本编辑器打开 NetBox 配置文件 ”:configuration.py

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u netbox nano configuration</span><span class="pun">.</span><span class="pln">py</span>

添加以下参数:

<span class="com"># domain and IP address</span><span class="pln">
ALLOWED_HOSTS </span><span class="pun">=</span> <span class="pun">[</span><span class="str">'your-domain.com'</span><span class="pun">,</span> <span class="str">'192.168.77.21'</span><span class="pun">]</span>

<span class="com"># database configuration</span><span class="pln">
DATABASE </span><span class="pun">=</span> <span class="pun">{</span><span class="pln">
    </span><span class="str">'NAME'</span><span class="pun">:</span> <span class="str">'netboxdb'</span><span class="pun">,</span><span class="pln">             </span><span class="com"># Database name</span><span class="pln">
    </span><span class="str">'USER'</span><span class="pun">:</span> <span class="str">'netbox'</span><span class="pun">,</span><span class="pln">               </span><span class="com"># PostgreSQL username</span><span class="pln">
    </span><span class="str">'PASSWORD'</span><span class="pun">:</span> <span class="str">'NetBoxRocks'</span><span class="pun">,</span>      <span class="com"># PostgreSQL password</span><span class="pln">
    </span><span class="str">'HOST'</span><span class="pun">:</span> <span class="str">'localhost'</span><span class="pun">,</span><span class="pln">            </span><span class="com"># Database server</span><span class="pln">
    </span><span class="str">'PORT'</span><span class="pun">:</span> <span class="str">''</span><span class="pun">,</span><span class="pln">                     </span><span class="com"># Database port (leave blank for default)</span><span class="pln">
    </span><span class="str">'CONN_MAX_AGE'</span><span class="pun">:</span> <span class="lit">300</span><span class="pun">,</span><span class="pln">            </span><span class="com"># Max database connection age (seconds)</span>
<span class="pun">}</span>

<span class="com"># Redis cache configuration</span><span class="pln">
REDIS </span><span class="pun">=</span> <span class="pun">{</span><span class="pln">
    </span><span class="str">'tasks'</span><span class="pun">:</span> <span class="pun">{</span><span class="pln">
        </span><span class="str">'HOST'</span><span class="pun">:</span> <span class="str">'localhost'</span><span class="pun">,</span><span class="pln">         </span><span class="com"># Redis server</span><span class="pln">
        </span><span class="str">'PORT'</span><span class="pun">:</span> <span class="lit">6379</span><span class="pun">,</span><span class="pln">                </span><span class="com"># Redis port</span><span class="pln">
        </span><span class="str">'PASSWORD'</span><span class="pun">:</span> <span class="str">'RedisPasswordNetBox'</span><span class="pun">,</span><span class="pln">           </span><span class="com"># Redis password (optional)</span><span class="pln">
        </span><span class="str">'DATABASE'</span><span class="pun">:</span> <span class="lit">0</span><span class="pun">,</span><span class="pln">               </span><span class="com"># Database ID</span><span class="pln">
        </span><span class="str">'SSL'</span><span class="pun">:</span> <span class="kwd">False</span><span class="pun">,</span><span class="pln">                </span><span class="com"># Use SSL (optional)</span><span class="pln">
    </span><span class="pun">},</span><span class="pln">
    </span><span class="str">'caching'</span><span class="pun">:</span> <span class="pun">{</span><span class="pln">
        </span><span class="str">'HOST'</span><span class="pun">:</span> <span class="str">'localhost'</span><span class="pun">,</span><span class="pln">
        </span><span class="str">'PORT'</span><span class="pun">:</span> <span class="lit">6379</span><span class="pun">,</span><span class="pln">
        </span><span class="str">'PASSWORD'</span><span class="pun">:</span> <span class="str">'RedisPasswordNetBox'</span><span class="pun">,</span><span class="pln">
        </span><span class="str">'DATABASE'</span><span class="pun">:</span> <span class="lit">1</span><span class="pun">,</span><span class="pln">            </span><span class="com"># Unique ID for the second database</span><span class="pln">
        </span><span class="str">'SSL'</span><span class="pun">:</span> <span class="kwd">False</span><span class="pun">,</span><span class="pln">
    </span><span class="pun">}</span>
<span class="pun">}</span>

<span class="com"># Secret key</span><span class="pln">
SECRET_KEY </span><span class="pun">=</span> <span class="str">'-BMW#USk(!-6hAEF-8Ng0detz6ex&+j0Kbe46bi=*jsF9T888*'</span>

保存并关闭文件,然后运行以下脚本 ‘ 以启动 NetBox IRM 安装:/opt/netbox/upgrade.sh

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u netbox </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">upgrade</span><span class="pun">.</span><span class="pln">sh</span>

第5步。配置 NetBox IRM。

首先,运行以下命令以激活 NetBox 安装的 Python 虚拟环境:

<span class="pln">source </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">venv</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">activate</span>

之后,将工作目录移动到 ” 并运行 Django 脚本 ” 来创建一个新的 NetBox 管理员用户:/opt/netbox/netboxmanage.py

<span class="pln">cd </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">netbox
python3 manage</span><span class="pun">.</span><span class="pln">py createsuperuser</span>

接下来,我们设置每天运行的 cron。脚本 ” 用于清理您的 NetBox 环境,这将删除过期的任务、旧会话或任何过期的记录:netbox-housekeeping.sh

<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">contrib</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">-</span><span class="pln">housekeeping</span><span class="pun">.</span><span class="pln">sh </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">cron</span><span class="pun">.</span><span class="pln">daily</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">-</span><span class="pln">housekeeping</span>

现在设置 NetBox 以与 Gunicorn 一起运行:

<span class="pln">sudo </span><span class="pun">-</span><span class="pln">u netbox cp </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">contrib</span><span class="pun">/</span><span class="pln">gunicorn</span><span class="pun">.</span><span class="pln">py </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">gunicorn</span><span class="pun">.</span><span class="pln">py
sudo </span><span class="pun">-</span><span class="pln">u netbox nano </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">gunicorn</span><span class="pun">.</span><span class="pln">py</span>

使用以下行更改 ” 参数:bind

<span class="pln">bind </span><span class="pun">=</span> <span class="str">'127.0.0.1:8000'</span>

保存并关闭文件,然后将 NetBox 的默认服务复制到 ” 目录。这将复制将用于管理 NetBox 的服务文件“”和“”:systemd/etc/systemd/systemnetboxnetbox-rq

<span class="pln">sudo cp </span><span class="pun">-</span><span class="pln">v </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">netbox</span><span class="pun">/</span><span class="pln">contrib</span><span class="com">/*.service /etc/systemd/system/</span>

最后,运行命令实用程序以重新加载 systemd 管理器并将新的更改应用于系统:systemctl

<span class="pln">sudo systemctl daemon</span><span class="pun">-</span><span class="pln">reload
sudo systemctl start netbox netbox</span><span class="pun">-</span><span class="pln">rq
sudo systemctl enable netbox netbox</span><span class="pun">-</span><span class="pln">rq</span>

第 6 步。配置防火墙。

如果使用防火墙,请允许端口通过防火墙:

<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">port</span><span class="pun">={</span><span class="lit">80</span><span class="pun">,</span><span class="lit">443</span><span class="pun">,</span><span class="lit">8000</span><span class="pun">}/</span><span class="pln">tcp
sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>

您可以通过列出当前防火墙设置进行验证:

<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">list</span><span class="pun">-</span><span class="pln">all</span>

步骤 7.访问网络盒子网页界面。

成功安装后,打开您的 Web 浏览器并使用 URL 访问 NetBox WebUI。您应该看到以下页面:http://.your-IP-address:8000

如何在 Rocky Linux 9 上安装 NetBox

感谢您使用本教程在 Rocky Linux 9 系统上安装 NetBox IRM。有关其他帮助或有用信息,我们建议您查看 NetBox 官方网站


Edge插件网 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何在 Rocky Linux 9 上安装 NetBox
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址