基于centos7 部署 NetBox3
环境 centos7
依赖、版本
PostgreSQL database > v10
Redis > v4.0
NetBox ponents > v3
Python 3.8
1) install PostgreSQL 10
centos7 自带的PG数据库是9.2,而只有9.4才开始支持JSONB。
yum install https://donload.postgresql./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 # 创建 box 相关数据库信息
CREATE DATAbase box;
CREATE USER box WITH PASSWORD '39tprXhrnELC';
GRANT ALL PRIVILEGES ON DATAbase box TO box;
列出所有用户du
退出 q
验证
psql --username box --passord --host localhost box
Passord for user box:
psql (12.5 (Ubuntu 12.5-0ubuntu0.20.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, pression: off)
Type "help" for help.
box=> conninfo
You are connected to database "box" as user "box" on host "localhost" (address "127.0.0.1") at port "5432".
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, pression: off)
box=> 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
# Allo replication connections from localhost, by a user ith 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./。安装最新的 Redis
yum install -y http://rpms.famillecollet./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 hich # 安装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 ponents
安装环境依赖
yum install -y g libxml2-devel libxslt-devel libffi-devel libpq-devel openssl-devel redhat-rpm-config
源码安装
get https://github./box-munity/box/archive/refs/tags/v3.1.7.tar.gz
tar -zxvf v3.1.7.tar.gz
mv box-3.1.7 && cd /opt
ln -s /opt/box-3.1.7 /opt/box
创建NetBox系统用户
sudo groupadd --system box
sudo adduser --system -g box box
sudo chon --recursive box /opt/box/box/media/
配置
1、cp配置文件
cd /opt/box/box/box/
sudo cp configuration.example.py configuration.py
2、打开 configuration.py 以开始配置 NetBox。NetBox 提供了许多配置参数,但新安装只需要以下四个
ALLOWED_HOSTS = ['']
DATAbase = {
'NAME': 'box', # Database name
'USER': 'box', # PostgreSQL username
'PASSWORD': 'J5brHrAXFLQSif0K', # PostgreSQL passord
'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 passord (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/box/box/
python3 generate_secret_key.py
将 key 复制到 configuration.py 的
SECRET_KEY = 'a%X$8=!JyjMFXt19=CO2FHJehsp^S$t0i9r5ALL$ZUho)Dk'
运行升级脚本
配置好 NetBox 后,将运行打包的升级脚本 ( upgrade.sh) 来执行以下操作
创建 Python 虚拟环境安装所有必需的 Python 包运行数据库架构迁移在本地构建文档(供离线使用)聚合磁盘上的静态资源文件
sudo /opt/box/upgrade.sh
如果默认的版本较低,可以使用环境变量来运行脚本
sudo PYTHON=/usr/bin/python3.8 /opt/box/upgrade.sh
创建超级用户
NetBox 没有默认账户,需要创建一个超级用户(管理帐户)才能登录 NetBox。
进入虚拟环境
source /opt/box/venv/bin/activate
(venv) [root@localhost box]# cd /opt/box/box
(venv) [root@localhost box]# python3 manage.py createsuperuser
启用定时任务来清理过期会话
调用此命令的 shell 脚本包含在contrib/box-housekeeping.sh. 它可以复制或链接到您系统的每日 cron 任务目录,或直接包含在 crontab 中。(如果将 NetBox 安装到非标准路径,请务必先更新此脚本中的系统路径。)
sudo ln -s /opt/box/contrib/box-housekeeping.sh /etc/cron.daily/box-housekeeping
测试验证
python3 manage.py runserver 0.0.0.0:8000 --insecure
此时浏览器如果无法访问 请关闭 防火墙
systemctl s firealld
systemctl disable firealld
或者放行端口
fireall-cmd --zone=public --add-port=8000/tcp --permanent
fireall-cmd --reload
空调维修
- 温岭冰箱全国统一服务热线-全国统一人工【7X2
- 荆州速热热水器维修(荆州热水器维修)
- 昆山热水器故障码5ER-昆山热水器故障码26
- 温岭洗衣机24小时服务电话—(7X24小时)登记报
- 统帅热水器售后维修服务电话—— (7X24小时)登
- 阳江中央空调统一电话热线-阳江空调官方售后电
- 乌鲁木齐阳春燃气灶厂家服务热线
- 珠海许昌集成灶售后服务电话-全国统一人工【
- 乌鲁木齐中央空调维修服务专线-乌鲁木齐中央空
- 新沂热水器故障电话码维修-新沂热水器常见故障
- 诸城壁挂炉24小时服务热线电话
- 靖江空调24小时服务电话-——售后维修中心电话
- 空调室外滴水管维修(空调室外排水管维修)
- 九江壁挂炉400全国服务电话-(7X24小时)登记报修
- 热水器故障码f.22怎么解决-热水器f0故障解决方法
- 营口热水器售后维修服务电话—— 全国统一人工