环境:
CentOS 7、EPEL库、git、python3.8.0版本以上、podstgresql、redis、netbox、Nginx
安装步骤:
1、安装epel库
sudo yum -y install epel-release
2、在CentOS 7系统上禁用SELinux
sudo setenforce 0
sudo sed-i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
cat /etc/selinux/config | grep SELINUX=
3、安装Netbox安装的依赖项包
sudo yum -y install @"Development Tools"
sudo yum -y install wget vim gcc htdp git libxml2-devel libxslt libffi-devel graphviz libxslt-devel supervisor zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel gdbm-devel ncurses-devel
4、在CentOS 7上安装Python 3.8
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
解压:
tar xzf Python-3.8.0.tgz
进入python
cd Python-3.8.0
sudo ./configure --enable-optimizations
sudo make altinstall
创建python3.8到python3的软连接
sudo ln -fs /usr/local/bin/python3.7 /usr/bin/python3
sudo ln -fs /usr/local/bin/pip3.7 /usr/bin/pip3
sudo yum -y install download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安装数据库服务器
sudo yum -y install postgresql14 postgresql14-server
初始化数据库
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
设置开机自启动
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
例:配置数据库用于netbox(根据实际开发情况进行配置)
sudo su - postgres
-bash-4.2$ psql
psql (14.0)
Type "help" for help.
postgres=# CREATE DATABASE netbox;
CREATE DATABASE
postgres=# CREATE USER netbox WITH PASSWORD 'StrongPassword';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox;
GRANT
postgres=#
postgres=# \q
-bash-4.2$ exit
logout
启用密码登录PostgreSQL数据库
sudo sed -i -e 's/ident/md5/' /var/lib/pgsql/14/data/pg_hba.conf
重启pgsql
sudo systemctl restart postgresql-14
6、在CentOS 7上安装和配置Netbox
在opt文件夹下从git上拉取netbox
cd /opt/
sudo git clone -b master https://github.com/digitalocean/netbox.git
进入到netbox文件内对配置文件进行自配置
cd netbox/netbox/netbox/
sudo cp configuration_example.py configuration.py
编辑configuration.py文件
ALLOWED_HOSTS = [''] '内'进行IP指定
# PostgreSQL database configuration.
DATABASE = {
'NAME': 'netbox', # Database name
'USER': 'netbox', # PostgreSQL username
'PASSWORD': 'StrongPassword', # PostgreSQL password
'HOST': 'localhost', # Database server
'PORT': '', # Database port (leave blank for default)
}
创建一个netbox的虚拟环境
cd /opt/netbox/
sudo python3 -m venv /opt/netbox/venv
激活环境
source venv/bin/activate
环境内安装Django依赖
sudo python3 -m pip install -U pip
sudo python3 -m pip install -U setuptools
sudo pip3 install -r /opt/netbox/requirements.txt
sudo pip3 install --upgrade PyYAML --ignore-installed
配置Django环境变量
PYTHONPATH="/usr/local/lib/python3.8/site-packages/":"${PYTHONPATH}"
export PYTHONPATH
生成Django密钥
cd /opt/netbox/netbox
./generate_secret_key.py
再次编辑configuration.py文件,将SECRET_KEY填入密钥
创建框架
cd /opt/netbox/netbox/
sudo python3 manage.py migrate
创建Netbox Admin用户和静态文件
sudo python3 manage.py createsuperuser
通过运行以下命令移动静态文件
sudo python3 manage.py collectstatic
为Netbox配置gunicorn
sudo pip3 install gunicorn
sudo cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn_config.py
编辑gunicorn_config.py配置文件
sudo vim /opt/netbox/gunicorn_config.py
在配置文件顶部添加如下信息
command = '/usr/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
user = 'netbox'
创建一个netbox的超级管理员
sudo vim /etc/supervisord.d/netbox.ini
填入如下信息:
[program:netbox]
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
directory = /opt/netbox/netbox/
user = netbox
配置超级管理员信息
sudo groupadd --system netbox
sudo useradd --system netbox -g netbox
sudo chown -R netbox:netbox /opt/netbox/netbox/media/
配置开机自启动
sudo systemctl enable supervisord
sudo systemctl restart supervisord
配置端口:(以8001为例)
sudo ss -tunelp | grep 8001
安装redis
sudo yum -y install redis
sudo systemctl enable --now redis
systemctl status redis
7、将httpd或Nginx配置为Netbox的代理
1、安装Nginx
sudo yum -y install nginx
2、创建一个虚拟文件并写入如下内容
server {
listen 80;
server_name netbox.example.com;
client_max_body_size 25m;
location /static/ {
alias /opt/netbox/netbox/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
}
}
3、配置Nginx开机自启动
sudo nginx -t
sudo systemctl start nginx
sudo systemctl enable nginx
4、关闭防火墙
sudo firewall-cmd --permanent --add-port={80,443}/tcp
sudo firewall-cmd --reload
8、访问地址:
(根据自己配置)