基于centos7 部署 NetBox3

环境:

        Centos7  2c4g  50G

依赖、版本:

        PostgreSQL database  > v10
        Redis > v4.0
        NetBox components > v3
        Python 3.8 

1) install PostgreSQL 10

centos7 自带的PG数据库是9.2,而只有9.4才开始支持JSONB。

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y

yum install postgresql10-contrib postgresql10-server -y 



psql -V        # 查看版本号,验证安装是否成功

初始化数据库并设置开机启动:

/usr/pgsql-10/bin/postgresql-10-setup initdb        # 初始化数据库

sudo systemctl start postgresql-10        # 启动pgsql

sudo systemctl enable postgresql-10.service        # 添加开机启动

 

登陆pgsql并创建账户:

sudo -u postgres psql        # 创建 netbox 相关数据库信息:



CREATE DATABASE netbox;

CREATE USER netbox WITH PASSWORD '39tprXhrnELC';

GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;

列出所有用户:\du

退出: \q

 验证:

psql --username netbox --password --host localhost netbox



Password for user netbox:

psql (12.5 (Ubuntu 12.5-0ubuntu0.20.04.1))

SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)

Type "help" for help.



netbox=> \conninfo

You are connected to database "netbox" as user "netbox" on host "localhost" (address "127.0.0.1") at port "5432".

SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)

netbox=> \q

 最后修改vi /var/lib/pgsql/10/data/pg_hba.conf

将 ident 修改为 md5 或者 trust,如下:

# TYPE  DATABASE        USER            ADDRESS                 METHOD  
                                                                        
# "local" is for Unix domain socket connections only                    
local   all             all                                     trust   
# IPv4 local connections:                                               
host    all             all             127.0.0.1/32            trust   
# IPv6 local connections:                                               
host    all             all             ::1/128                 trust   
# Allow replication connections from localhost, by a user with the      
# replication privilege.                                                
local   replication     all                                     trust   
host    replication     all             127.0.0.1/32            trust   
host    replication     all             ::1/128                 trust   

重要: 更改完配置后,一定要重启pgsql

                 systemctl restart postgresql-10

2)Install Redis

CentOS 7 yum 默认安装的版本是3.2。

这里使用 Remi 的软件源,官网地址:http://rpms.famillecollet.com/。安装最新的 Redis :

​
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm 

yum --enablerepo=remi install redis -y

redis-server -v        # 确认 redis 版本

​

3)install Python3.8

yum install -y centos-release-scl        # 仓库注册

yum install -y rh-python38 which         # 安装python3.8



# 创建软连接

ln -s /opt/rh/rh-python38/root/usr/bin/python3 /usr/bin/python3

ln -s  /opt/rh/rh-python38/root/usr/bin/pip3 /usr/bin/pip3



python -V        # 确认版本

4)Install NetBox components

安装环境依赖:

yum install -y gcc libxml2-devel libxslt-devel libffi-devel libpq-devel openssl-devel redhat-rpm-config

源码安装:

​
wget https://github.com/netbox-community/netbox/archive/refs/tags/v3.1.7.tar.gz

tar -zxvf v3.1.7.tar.gz

mv netbox-3.1.7 && cd /opt

ln -s /opt/netbox-3.1.7 /opt/netbox

​

创建NetBox系统用户:

sudo groupadd --system netbox

sudo adduser --system -g netbox netbox

sudo chown --recursive netbox /opt/netbox/netbox/media/

配置:

1、cp配置文件

cd /opt/netbox/netbox/netbox/

sudo cp configuration.example.py configuration.py

2、打开 configuration.py 以开始配置 NetBox。NetBox 提供了许多配置参数,但新安装只需要以下四个:

ALLOWED_HOSTS = ['*']



DATABASE = {

    'NAME': 'netbox',               # Database name

    'USER': 'netbox',               # PostgreSQL username

    'PASSWORD': 'J5brHrAXFLQSif0K', # PostgreSQL password

    'HOST': 'localhost',            # Database server

    'PORT': '',                     # Database port (leave blank for default)

    'CONN_MAX_AGE': 300,            # Max database connection age (seconds)

}

3、redis 使用默认参数

REDIS = {

    'tasks': {

        'HOST': 'localhost',      # Redis server

        'PORT': 6379,             # Redis port

        'PASSWORD': '',           # Redis password (optional)

        'DATABASE': 0,            # Database ID

        'SSL': False,             # Use SSL (optional)

    },

    'caching': {

        'HOST': 'localhost',

        'PORT': 6379,

        'PASSWORD': '',

        'DATABASE': 1,            # Unique ID for second database

        'SSL': False,

    }

}

4、SECRET_KEY

cd  /opt/netbox/netbox/

python3 generate_secret_key.py


# 将 key 复制到 configuration.py 的

SECRET_KEY = 'a%X$8=!JyjMFXt19=CO2FHJehsp^S$t0i*9r5ALL$ZUho)*wDk'

运行升级脚本:

# 配置好 NetBox 后,将运行打包的升级脚本 ( upgrade.sh) 来执行以下操作:

    # 创建 Python 虚拟环境
    # 安装所有必需的 Python 包
    # 运行数据库架构迁移
    # 在本地构建文档(供离线使用)
    # 聚合磁盘上的静态资源文件

sudo /opt/netbox/upgrade.sh


# 如果默认的版本较低,可以使用环境变量来运行脚本:

sudo PYTHON=/usr/bin/python3.8 /opt/netbox/upgrade.sh

创建超级用户:

NetBox 没有默认账户,需要创建一个超级用户(管理帐户)才能登录 NetBox。

进入虚拟环境:

source /opt/netbox/venv/bin/activate

(venv) [root@localhost netbox]# cd /opt/netbox/netbox

(venv) [root@localhost netbox]# python3 manage.py createsuperuser

启用定时任务来清理过期会话:

调用此命令的 shell 脚本包含在contrib/netbox-housekeeping.sh. 它可以复制或链接到您系统的每日 cron 任务目录,或直接包含在 crontab 中。(如果将 NetBox 安装到非标准路径,请务必先更新此脚本中的系统路径。)

sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping

测试验证:

python3 manage.py runserver 0.0.0.0:8000 --insecure

此时浏览器如果无法访问 请关闭 防火墙:

systemctl stop firewalld

systemctl disable firewalld

或者放行端口:

firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload

pg_dump 备份 NetBox3的数据:

pg_dump --username netbox --password --host localhost netbox > netbox.sql

引用:

        Installing NetBox - NetBox Documentation
        https://netbox.readthedocs.io/en/stable/installation/

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值