LNMP安裝部署開源IP管理工具phpipam

半盞流年發表於2018-11-20

1、資料庫mariadb安裝

//依賴安裝

yum install -y apr* autoconf automake bison bzip2 bzip2* compat*  

cpp curl curl-devel fontconfig fontconfig-devel freetype freetype*  

freetype-devel gcc gcc-c++ gd gettext gettext-devel glibc kernel  

kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_

err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel  

libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff  

libtiff* cmake mpfr ncurses* ntp openssl openssl-devel patch pcre-devel  

perl php-common  php-gd policycoreutils telnet t1lib t1lib* nasm nasm*  zlib-devel

 

//mariadb安裝

Screen               //是用Screen會話管理,避免異常(如果是遠端主機建議養成這個習慣)

groupadd -r mysql //建立使用者組mysqlmake

useradd -g mysql -s /sbin/nologin mysql //建立使用者mysql並指定使用者組,同時禁止登陸系統

 

mkdir /usr/local/mysql //建立mysql安裝目錄

mkdir -p /data/mysql //建立資料庫存放目錄

chown -Rf mysql:mysql /data/mysql/ //所有者、所有者修改為mysql

 

//開始編譯

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

-DMYSQL_DATADIR=/data/mysql

-DSYSCONFDIR=/etc

-DWITHOUT_TOKUDB=1

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STPRAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

-DWIYH_READLINE=1

-DWIYH_SSL=system

-DVITH_ZLIB=system

-DWITH_LOBWRAP=0

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock

-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

 

make

make install

 

說明:

-DCMAKE_INSTALL_PREFIX=             //指定安裝目錄

-DMYSQL_DATADIR=                   //指定資料庫存放目錄

-DSYSCONFDIR=                       //配置檔案所在目錄,一般 /etc

 

make && make install                      //生成二進位制檔案並安裝

 

rm -rf /etc/my.cnf //刪除預設配置檔案

 

//生成系統資料檔案、新的配置檔案

./scripts/mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql

 

cd /usr/local/mysql

 

 

//建立連線

ln -s my.cnf /etc/my.cnf

 

//複製開機程式到系統開機目錄

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

 

//賦予可執行許可權

chmod 755 /etc/rc.d/init.d/mysqld

 

//修改配置

vim /etc/rc.d/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql

 

service mysqld start          //啟動mysql資料庫

chkconfig mysqld on //新增到啟動項

 

vim /etc/profile         //在文末新增變數

export PATH=$PATH:/usr/local/mysql/bin

 

source /etc/profile //配置檔案即時生效

 

//建立連線檔案

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

mkdir /var/lib/mysql

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

ln -s /usr/local/mysql/include/mysql /usr/include/mysql

 

bin/mysql_secure_installation     //初始化mysql

 

mysql -u root -p         //回車輸入root密碼(資料庫root,不是登陸系統的root)我是root123

CREATE USER phpipam@localhost IDENTIFIED BY `phpipamadmin`;       //建立phpipam使用者及密碼

Exit / quit   //退出資料

 

2、PHP安裝

 

cd php-7.2.11

 

 

 

./configure –prefix=/usr/local/php

 

–with-config-file-path=/usr/local/php/etc

 

–with-mysql-sock=/tmp/mysql.sock

 

–with-pdo-mysql=/usr/local/mysql

 

–with-gd

 

–with-png-dir=/usr/share/libpng

 

–with-jpeg-dir=/usr/share/jpeg

 

–with-freetype-dir=/usr/share/freetype

 

–with-xpm-dir=/usr/  

 

–with-zlib-dir=/usr/share/zlib  

 

–with-iconv

 

–enable-libxml

 

–enable-xml

 

–enable-bcmath

 

–enable-shmop

 

–enable-sysvsem

 

–enable-inline-optimization

 

–enable-opcache

 

–enable-mbregex

 

–enable-fpm

 

–enable-mbstring

 

–enable-ftp  

 

–with-openssl

 

–enable-pcntl

 

–enable-sockets

 

–with-xmlrpc

 

–enable-zip

 

–enable-soap

 

–with-pear

 

–with-gettext

 

–enable-session  

 

–with-curl

 

–enable-ctype

 

 

 

make && make install

 

 

 

rm -rf /etc/php.ini

 

 

 

ln -s /usr/local/php/etc/php.ini /etc/php.ini

 

 

 

cp php.ini-production /usr/local/php/etc/php.ini

 

 

 

cd  /usr/local/php/etc/

 

 

 

cp  php-fpm.conf.default  php-fpm.conf

 

ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

 

cp /usr/local/src/php-7.2.11/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

 

chmod 755 /etc/rc.d/init.d/php-fpm

 

chkconfig php-fpm on

 

 

 

vim php.ini

 

disable_functions = passthru,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

//開啟gmp模組

;extension=gmp 左邊分號去掉 

 

 

vim php-fpm.conf   ,找到 這一行 “;pid = run/php-fpm.pid”,去掉分號“;

 

在文末修改為 include=/usr/local/php/etc/php-fpm.d/www.conf.default

 

 

 

vim php-fpm.d/www.conf.default      找到

 

user = nobody  改成  user = www

 

group = nobody  改成 group = www

 

;listen.owner = nobody 改成 listen.owner = www

 

;listen.group = nobody 改成 listen.group = www

 

;listen.mode = 0660    改成 listen.mode = 0660

 

 

 

 

 

listen = 127.0.0.1:9000

 

listen = /var/run/php-fpm.sock

 

 

 

注:此時執行systemctl restart php-fpm會報錯,我們執行systemctl status -l  php-fpm.service可以看到報錯資訊

 

 

報錯提示找不到使用者www,所以我們要建立使用者及使用者組www

 

groupadd -r www

 

useradd -g www -s /sbin/nologin www

 

 

 

systemctl restart php-fpm //沒有報錯,說明成功重啟

 

systemctl status -l php-fpm //檢視狀態,如下圖

 

chmod 0660 /var/run/php-fpm.sock

 

chown www:www /var/run/php-fpm.sock

 

3、安裝幾個軟包

cd zlib-1.2.11

./configure –prefix=/usr/local/zlib

make && make install

 

cd pcre-8.42

./configure –prefix=/usr/local/pcre

make && make install

 

cd gmp-6.1.2

./configure –prefix=/usr/local/gmp

make && make install

 

cd openssl-1.0.1h

./config –prefix=/usr/local/openssl

make && make install

vim /etc/profile

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/openssl/bin

 

4、安裝Nginx

cd nginx-1.15.5

./configure

–prefix=/usr/local/nginx

–without-http_memcached_module

–user=www

–group=www

–with-http_stub_status_module

–with-http_ssl_module

–with-http_gzip_static_module

–with-openssl=/usr/local/src/openssl-1.0.1h

–with-zlib=/usr/local/src/zlib-1.2.11  

–with-pcre=/usr/local/src/pcre-8.42        

 

make && make install

 

vim /etc/rc.d/init.d/nginx               //Nginx 原始碼安裝會沒有啟動檔案,所以手動建立它

#!/bin/bash

# nginx – this script starts and stops the nginx daemon

# chkconfig: – 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /etc/nginx/nginx.conf

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ “$NETWORKING” = “no” ] && exit 0

nginx=”/usr/local/nginx/sbin/nginx”

prog=$(basename $nginx)

NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {

# make required directories

user=`$nginx -V 2>&1 | grep “configure arguments:” | sed `s/[^*]*–user=([^ ]*).*/1/g` -`

        if [ -z “`grep $user /etc/passwd`” ]; then

                useradd -M -s /bin/nologin $user

        fi

options=`$nginx -V 2>&1 | grep `configure arguments:“

for opt in $options; do

        if [ `echo $opt | grep `.*-temp-path“ ]; then

                value=`echo $opt | cut -d “=” -f 2`

                if [ ! -d “$value” ]; then

                        # echo “creating” $value

                        mkdir -p $value && chown -R $user $value

                fi

        fi

done

}

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

make_dirs

echo -n $”Starting $prog: “

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $”Stopping $prog: “

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

#configtest || return $?

stop

sleep 1

start

}

reload() {

#configtest || return $?

echo -n $”Reloading $prog: “

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case “$1” in

start)

        rh_status_q && exit 0

        $1

        ;;

stop)

        rh_status_q || exit 0

        $1

        ;;

restart|configtest)

$1

;;

reload)

        rh_status_q || exit 7

        $1

        ;;

force-reload)

        force_reload

        ;;

status)

        rh_status

        ;;

condrestart|try-restart)

        rh_status_q || exit 0

        ;;

*)

echo $”Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}”

exit 2

esac

 

chmod 755 /etc/rc.d/init.d/nginx //賦予檔案執行許可權

/etc/rc.d/init.d/nginx restart //啟動ngin

chkconfig nginx on //新增開機啟動

 

systemctl status -l nginx //檢視ngin狀態

 

 

在瀏覽器輸入伺服器IP地址,這裡是192.168.20.10

 

iptables -F      //清空防火牆做測試,刷下網頁

 

在清空防火牆後,頁面刷出來了,至此:恭喜,Nginx安裝成功

 

 

 

vim /usr/local/nginx/conf/nginx.conf

 

#user  nobody;

 

user www www;

 

 

 

server {

 

        listen       80;

 

        server_name  localhost;

 

 

 

        #charset koi8-r;

 

 

 

        #access_log  logs/host.access.log  main;

 

 

 

        location / {

 

            root   html;

 

            index index.html index.htm index.php;

 

        }

 

 location /usr/local/nginx/html/api/{

 

                try_files $uri $uri/ /usr/local/nginx/html/api/index.php;      

 

 }

 

 

 

 

 

 

 

 

 

location ~ .php$ {

 

                fastcgi_pass    unix:/var/run/php-fpm.sock;

 

                fastcgi_index   index.php;

 

                include         fastcgi_params;

 

        }

 

 

 

vim /usr/local/nginx/conf/fastcgi_params             //文末加上如下兩行

 

 

 

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

 

fastcgi_param PATH_INFO                $fastcgi_script_name;

 

 

 

systemctl restart nginx

 

systemctl restart php-fpm

 

5、安裝 phpipam(主角登場)

cd phpipam

rm -rf /usr/local/nginx/html/{index.html,50x.html}*

mv ./* /usr/local/nginx/html/

chown -Rf www:www /usr/local/nginx/html

chmod -Rf 755 /usr/local/nginx/html

 

cd /usr/local/nginx/html/

cp config.dist.php config.php

 

此時重新整理瀏覽器頁面,頁面提示需要php-gmp擴充支援

 

cd /usr/src/php-7.2.11/ext/gmp

 

/usr/local/php/bin/phpize

 

./configure –with-php-config=/usr/local/php/bin/php-config –with-gmp=/usr/local/gmp/

 

make && make install

 

 

 

systemctl restart nginx

 

systemctl restart php-fpm

 

 

 

此時重新整理瀏覽器頁面,出現如圖就可以安裝phpipam

 

 

主機發現及線上檢測:這個在新增子網的時候可以勾選模組,但需要計劃任務來執行

 

Ping指令碼在:/usr/local/nginx/html/functions/scripts/pingCheck.php

 

檢測是否線上:/usr/local/nginx/html/functions/scripts/discoveryCheck.php

 

 

 

配置計劃任務:

 

systemctl start crond             //啟動計劃任務程式  crond

 

crontab -e   //編輯、建立計劃任務

 

*/5 * * * * /usr/local/nginx/html/functions/scripts/pingCheck.php

 

 

 

*/5 * * * * /usr/local/nginx/html/functions/scripts/discoveryCheck.php

 

crontab -l //檢視計劃任務

 

 

 

 

 

 

 

 

相關文章