LNMP安装部署开源IP管理工具phpipam

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 //查看计划任务

 

 

 

 

 

猜你喜欢

转载自www.cnblogs.com/mranyun/p/phpipam.html