原文鏈接:Netbox 開源 IPAM 管理工具搭建詳細流程
參考資料:https://netbox.readthedocs.io/en/stable/
PostgreSQL數據庫安裝
1.yum 下載安裝
1)yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm 2)yum install -y postgresql96 postgresql96-server postgresql96-devel 3)/usr/pgsql-9.6/bin/postgresql96-setup initdb
2.修改配置
修改文件/var/lib/pgsql/9.6/data/pg_hba.conf
中ident
為md5
80 local all all peer 81 # IPv4 local connections: 82 host all all 10.44.196.30/32 md5 83 # IPv6 local connections: 84 host all all ::1/128 md5
3.修改listen_addresses參數/var/lib/pgsql/9.6/data/postgresql.conf
# /var/lib/pgsql/9.6/data/postgresql.conf listen_addresses = '10.249.104.83' # what IP address(es) to listen on;
3.啟動服務
systemctl start postgresql-9.6 systemctl enable postgresql-9.6
4.創建數據庫
1 # sudo -u postgres psql 2 psql (9.4.5) 3 Type "help" for help. 4 5 postgres=# CREATE DATABASE netbox; 6 CREATE DATABASE 7 postgres=# CREATE USER netbox WITH PASSWORD '123456'; 8 CREATE ROLE 9 postgres=# GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox; 10 GRANT 11 postgres=# \q
5.驗證狀態
psql -U netbox -W -h 10.44.196.30 netbox
[root@wangjunqiang ~]# psql -U netbox -W -h 10.44.196.30 netbox Password for user netbox: psql (9.6.18) Type "help" for help. netbox=> \d List of relations Schema | Name | Type | Owner --------+--------------------------------------------+----------+-------- public | auth_group | table | netbox public | auth_group_id_seq | sequence | netbox
Redis安裝
1.yum安裝
# yum install -y epel-release # yum install -y redis # systemctl start redis # systemctl enable redis
2.驗證狀態
1 $ redis-cli ping 2 PONG
NetBox安裝
1.依賴環境安裝
# yum install -y gcc python36 python36-devel python36-setuptools libxml2-devel libxslt-devel libffi-devel openssl-devel redhat-rpm-config # easy_install-3.6 pip
2.克隆git倉庫
mkdir -p /opt/netbox/ && cd /opt/netbox/ yum install -y git git clone -b master https://github.com/netbox-community/netbox.git .
或者 https://github.com/netbox-community/netbox/archive/v2.6.0.tar.gz
3.創建用戶(centos需要先建組)
groupadd netbox adduser -r netbox -g netbox chown --recursive netbox /opt/netbox/netbox/media/
4.設置python環境
python3 -m venv /opt/netbox/venv source venv/bin/activate pip3 install -r requirements.txt
5.配置文件設置
cd netbox/netbox/
cp configuration.example.py configuration.py
6.編輯configuration.py
文件,設置可訪問主機
ALLOWED_HOSTS = [‘127.0.0.1’] 如果全可以訪問就填入* 10 # Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local'] 11 ALLOWED_HOSTS = ['*'] 12 13 # PostgreSQL database configuration. See the Django documentation for a complete list of available parameters: 14 # https://docs.djangoproject.com/en/stable/ref/settings/#databases 15 DATABASE = { 16 'NAME': 'netbox', # Database name 17 'USER': 'netbox', # PostgreSQL username 18 'PASSWORD': '123456', # PostgreSQL password 19 'HOST': '10.44.196.30', # Database server 20 'PORT': '', # Database port (leave blank for default) 21 'CONN_MAX_AGE': 300, # Max database connection age 22 }
至少包含50個字母數字字符的隨機密鑰
[root@contrail03v netbox]# ./generate_secret_key.py
Y7yWCElz0dh%r*R)3q8GL+_jI4s#(SpO^mxVFJAu=ci&TwU@e9
56 SECRET_KEY = 'Y7yWCElz0dh%r*R)3q8GL+_jI4s#(SpO^mxVFJAu=ci&TwU@e9'
7.數據庫遷移
cd /opt/netbox/netbox/
python3 manage.py migrate
8.管理員用戶創建
(venv) # python3 manage.py createsuperuser
Username: admin
Email address: admin@example.com
Password:
Password (again):
Superuser created successfully.
python3 manage.py collectstatic --no-input
9.啟動程序
python3 manage.py runserver 0.0.0.0:8000 --insecure
10.應用測試
本地訪問可以通過http://10.44.196.30:8000/訪問到項目
