1. 程式人生 > >騰訊智雲bk-cmdb搭建

騰訊智雲bk-cmdb搭建

bk-cmdb

資源下載:https://github.com/Tencent/bk-cmdb

服務器配置(官網推薦)

  • 推薦采用nginx+php-fpm 的運行模式

  • php版本不低於5.6.9,nginx版本不低於1.8.0

  • nginx編譯參數,需編譯進pcre

  • php編譯參數擴展 ./configure --prefix= -enable-fpm,另還需要(mysql、curl、pcntl、mbregex、mhash、zip、mbstring、openssl)等擴展


0.準備工作

在本地新建了一個虛擬機,系統為centos7,最小化系統安裝,保證初始環境的幹凈。


yum groupinstall ‘development tools‘    # 安裝編譯工具
yum install -y epel-release    #安裝epel源

過程中涉及到軟件的編譯安裝,預先安裝編譯工具和環境:


1.Nginx安裝

由於是測試搭建,直接yum安裝Nginx的。若有需求,可自行編譯安裝。


2.php安裝

2.1 下載及編譯PHP

wget http://cn2.php.net/get/php-5.6.31.tar.gz  #自行選擇地址和版本
tar -zxvf php-5.6.31.tar.gz
cd  php-5.6.31
# 以下參數並非必須,官網要求的參數加上即可。
 ./configure --prefix=/usr/local/php --with-config-file-path=/etc  --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www  --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv  --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap  --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg  --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib  --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite  --with-pear


2.2 問題及解決

# 錯誤1:
configure: error: xml2-config not found. Please check your libxml2 installation

# 解決:
# 1、檢查是否安裝了libxml 包
rpm -qa|grep libxml2
 
# 2、如果沒有則安裝
yum install libxml2 
yum install libxml2-devel
 
# 3、檢查xml2-config文件是否存在
find / -name "xml2-config"

# 錯誤2:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

# 解決:
# 因為CentOs默認的yum源沒有 libmcrypt-devel這個包,只能借助epel的yum源,所以先安裝epel,再安裝libmcrypt。
yum install -y epel-release
yum install -y libmcrypt-devel

3.MySQL安裝

1.下載mysql源安裝包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安裝mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
# 檢查mysql源是否安裝成功
yum repolist enabled | grep "mysql.*-community.*"

2. 安裝MySQL
yum install mysql-community-server

3. 啟動MySQL
# 啟動MySQL服務
systemctl start mysqld
# 查看MySQL的啟動狀態
systemctl status mysqld
# 設置MySQL開機啟動
systemctl enable mysqld
systemctl daemon-reload

4. 修改root默認密碼
# 找到root默認密碼
grep ‘temporary password‘ /var/log/mysqld.log
# 進入mysql控制臺, 輸入上述查詢到的默認密碼
set password for ‘root‘@‘localhost‘=password(‘[email protected]‘);

5.添加遠程登錄用戶
默認只允許root帳戶在本地登錄,如果要在其它機器上連接mysql,必須修改root允許遠程連接,或者添加一個允許遠程連接的帳戶

# 添加遠程帳戶
GRANT ALL PRIVILEGES ON *.* TO ‘yourname‘@‘%‘ IDENTIFIED BY ‘[email protected]‘ WITH GRANT OPTION;

若想將密碼設置成簡單密碼,需要修改以下兩個參數

set global validate_password_policy=0;

set global validate_password_policy=4;


4.安裝bk-cmdb

4.1 創建一個分區或目錄,比如 /data/htdocs,將bk-cmdb內所有文件上傳至該目錄下。根據需要調整根目錄index.php文件內的環境模式(development/testing/production)。

4.2 修改nginx.conf文件

server {
        listen       80;
        server_name  cmdb.bk.com;
        root   /data/htdocs;
        

        #access_log  logs/host.access.log  main;

        location / {
            index  index.php index.html index.htm;
            if (!-e $request_filename) {
               rewrite ^(.*)$ /index.php?s=$1 last;
               break;}
        }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        # 
        #  location ~ \.php$ {
        #      proxy_pass   http://127.0.0.1;
        #  }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            fastcgi_connect_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 32 32k;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache‘s document root
        # concurs with nginx‘s one
        #
        location ~ /\.ht {
            deny  all;
        }
    }

4.3 數據庫服務器上創建數據庫cmdb,導入根目錄下bk-cmdb.sql文件。

4.4 修改./application/config/db.php 配置數據庫ip、用戶名、密碼、數據庫等信息。

4.5 修改./application/config/config.php中配置session訪問目錄,$config[‘sess_save_path‘] = ‘/data/session‘,(自己定義),保證配置的session目錄有可讀寫權限(chmod)。

4.6 根據4.1中配置的環境類型(development/testing/production)找到對應的常量文件,例如前面環境類型配置的為 development 則在/config/development/constants.php中定義


define(‘BASE_URL‘, ‘http://cmdb.bk.com‘); //訪問主域名,務必帶上http://
define(‘COMPANY_NAME‘, ‘公司名稱‘); //當前公司名
define(‘COOKIE_DOMAIN‘, ‘.bk.com‘); //cookie訪問域

4.7 切換到根目錄下執行:

php index.php /cli/Init/initUserData。

4.8 啟動nginx與php-fpm。

4.9 配置hosts,使用 admin/blueking賬號即可登錄訪問。


5.現有功能介紹

  • 用戶管理

  • 業務管理

  • 拓撲(集群、模塊)管理

  • 資源池管理

  • 主機管理

  • 日誌查詢

技術分享

技術分享


騰訊智雲bk-cmdb搭建