netbox
netbox的官方文档网址是NetBox Documentation
https://docs.netbox.dev/en/stable/
本文是在ubuntu20.04版本上进行安装
首先更新系统内软件
sudo apt update
其次安装postgresSQL数据库数据库版本最好应11以上版本
sudo apt install -y postgresql(注:这是安装最新版本的命令)
psql -V 查看数据库版本的命令
sudo -u postgres psql 以管理员身份进入数据库
(注:在创建默认数据库的时候要修改对应的用户名和密码)
CREATE DATABASE netbox;
CREATE USER netbox WITH PASSWORD 'J5brHrAXFLQSif0K';
ALTER DATABASE netbox OWNER TO netbox;
-- the next two commands are needed on PostgreSQL 15 and later
\connect netbox;
GRANT CREATE ON SCHEMA public TO netbox;
$ 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
安装redis
配置Gunicorn WSGI
Gunicorn 是一个 Python 的 WSGI HTTP 服务器。
sudo -u netbox cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
# 复制创建配置文件
sudo -u netbox vim /opt/netbox/gunicorn.py
# 可修改配置文件,更改监听端口,默认8001
cp -v /opt/netbox/contrib/*.service /etc/systemd/system/
# 复制到系统服务
systemctl daemon-reload
# 重新加载系统服务
systemctl enable --now netbox netbox-rq
# 配置启动并开机启动
systemctl status netbox
systemctl status netbox-rq
# 查看状态
配置Nginx 作为反向代理
dnf install nginx -y
# 安装Nginx
vim /etc/nginx/conf.d/netbox.conf
# 创建配置文件,注意修改netbox.songxwn.com 为自己的域名。反向代理到8001端口
server {
listen 80;
# CHANGE THIS TO YOUR SERVER'S NAME
server_name netbox.songxwn.com;
client_max_body_size 25m;
fastcgi_connect_timeout 1200s;
fastcgi_send_timeout 1200s;
fastcgi_read_timeout 1200s;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
location /static/ {
alias /opt/netbox/netbox/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
systemctl enable --now nginx
# 配置启动并开机启动
systemctl status nginx
# 查看状态