lnmp

搭建lnmp,动态显示zabbix网站


环境说明

系统平台IP服务
redhat7192.168.233.129MySQL、PHP
redhat7192.168.233.128nginx
  • 192.168.233.129
//安装mysql
/安装依赖包
[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g 306 mysql
[root@localhost ~]# id mysql
uid=996(mysql) gid=306(mysql) 组=306(mysql)
//下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
apr-1.6.5          apr-util-1.6.1          debug         httpd-2.4.37.tar.bz2  mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
apr-1.6.5.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.37  kernels
//解压软件至/usr/local/
[root@localhost src]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.23-linux-glibc2.12-x86_64  sbin  share  src
//修改目录/usr/local/mysql的属主属组
[root@localhost src]# cd /usr/local/
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql-5.7.23-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.23-linux-glibc2.12-x86_64/"
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 2月  20 15:55 /usr/local/mysql -> mysql-5.7.23-linux-glibc2.12-x86_64/
//添加环境变量
[root@localhost ~]# vim /etc/profile.d/mysql.sh
[root@localhost ~]# source /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
//建立数据存放目录
[root@localhost ~]# mkdir /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data
[root@localhost ~]# ll /tmp/data -d
drwxr-xr-x. 2 mysql mysql 6 2月  20 16:01 /opt/data
//初始化数据库
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data
//配置mysql
2019-02-20T08:01:57.365613Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-02-20T08:02:02.649657Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-02-20T08:02:03.188376Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-02-20T08:02:03.261018Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: cec3e17c-34e5-11e9-9b0d-000c295aa226.
2019-02-20T08:02:03.264743Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-02-20T08:02:03.267878Z 1 [Note] A temporary password is generated for root@localhost: GSfIupL4jt?C
//请注意,这个命令的最后会生成一个临时密码,此处密码是GSfIupL4jt?C,一定要记住,登录数据库时会用到

//配置mysql
[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@localhost ~]# ldconfig
//生成配置文件
[root@localhost ~]# mv /etc/my.cnf /opt/
[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
//配置服务启动脚本
[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/opt/data		//在这两行的=后面添加内容,原本=后面没有内容
//启动mysql
[root@localhost ~]# service mysqld start
Starting MySQL. SUCCESS! 
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
LISTEN     0      80                                      :::3306                                                :::*                  
//修改密码
//使用临时密码登录
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
//设置新密码
mysql> set password=password('zml123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@localhost ~]# mysql -uroot -pzml123!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

//编译安装php
//安装yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# rm -rf *]
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# yum -y install epel-release
[root@localhost yum.repos.d]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//安装依赖包
[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  libpcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php72w-mysqlnd
//下载php
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
//编译安装php
[root@localhost src]# tar xf php-7.2.8.tar.xz
[root@localhost src]# cd php-7.2.8
[root@localhost php-7.2.8]# ./configure --prefix=/usr/local/php7  --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-openssl --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --enable-exif  --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-gettext --enable-json --enable-mbstring --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-readline --enable-shmop --enable-simplexml --enable-sockets --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-pcntl --enable-posix
[root@localhost php-7.2.8]# make
[root@localhost php-7.2.8]# make install
//安装后配置
[root@localhost ~]# vim /etc/profile.d/php7.sh
[root@localhost ~]# cat /etc/profile.d/php7.sh
export PATH=/usr/local/php7/bin:$PATH
[root@localhost ~]# source /etc/profile.d/php7.sh
[root@localhost ~]# echo $PATH
/usr/local/php7/bin:/usr/local/mysql/bin:/usr/local/mysql/bin:/usr/local/apache/bin:/usr/local/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost ~]# php -v
PHP 7.2.8 (cli) (built: Feb 20 2019 16:56:42) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
//配置php-fpm
[root@localhost ~]# cd /usr/src/
[root@localhost src]# cd php-7.2.8
[root@localhost php-7.2.8]# mv /etc/php.ini /opt/
[root@localhost php-7.2.8]# \cp php.ini-production /etc/php.ini
[root@localhost php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[root@localhost php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
//编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
/配置fpm的相关选项为你所需要的值:
[root@localhost ~]# vim /usr/local/php7/etc/php-fpm.conf
......
;  - the global prefix if it's been set (-p argument)
;  - /usr/local/php7 otherwise
include=/usr/local/php7/etc/php-fpm.d/*.conf
pm.max_children = 50    //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5    //启动时启动5个进程
pm.min_spare_servers = 2    //最小空闲进程数
pm.max_spare_servers = 8    //最大空闲进程数
//启动php-fpm
[root@localhost ~]# service php-fpm start
Starting php-fpm  done
//默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
[root@localhost ~]# ss -antl
State      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                              127.0.0.1:9000                                                 *:*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*                  
LISTEN     0      80                                      :::3306                                                :::*      


//修改php的www.conf文件,将监听在127.0.0.1的9000端口改成监听在192.168.233.129的90000端口
```[root@2 ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = nginx		//用户和组都改成nginx,在php服务器上创建的用户必须要和nginx服务器上的nginx的用户id一致
group = nginx

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 192.168.233.129:9000		//将127.0.0.1改成192.168.233.129,之所以要将端口改成本地的ip地址,是因为127只能本机才能访问,其他主机不可以,换成本机的IP地址后,其他主机也可以访问本机的php服务

; Set listen(2) backlog.
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
;listen.backlog = 511
[root@2 ~]# service php-fpm restart
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?
Starting php-fpm  done
[root@2 ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128      *:22                   *:*                  
LISTEN      0      128    192.168.233.129:9000                 *:*                  
LISTEN      0      128     :::22                  :::*                  
LISTEN      0      80      :::3306                :::*                  
[root@2 ~]#
//在php主机上创建虚拟主机目录并生成php测试页面
 [root@localhost ~]# mkdir /var/www
 [root@localhost ~]# vim /var/www/index.php
 [root@localhost ~]# cat /var/www/index.php
 <?php
    phpinfo();
?>
[root@localhost ~]# chown -R nginx.nginx /var/www		//两边的用户要一致
  • 测试
    在这里插入图片描述
  • 192.168.233.128
//nginx的安装
/创建系统用户nginx
[root@localhost ~]# groupadd -r nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g nginx nginx
//安装依赖环境
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
//安装开发工具
[root@localhost ~]# yum groups list
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
file:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
正在尝试其它镜像。
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   Cinnamon 桌面环境
   MATE 桌面环境
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
已安装的组:
   开发工具
可用组:
   Cinnamon
   Fedora Packager
   Haskell
   MATE
   Milkymist
   TurboGears 应用程序构架
   Xfce
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   控制台互联网工具
   教育软件
   智能卡支持
   电子实验室
   科学记数法支持
   系统管理
   系统管理工具
   通用桌面
完成
//创建日志存放目录
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
//解压nginx
[root@localhost ~]# cd /usr/src/
[root@localhost src]# tar -xf nginx-1.14.2.tar.gz
//编译安装
[root@localhost nginx-1.14.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-debug \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_image_filter_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module \
> --http-log-path=/var/log/nginx/access.log \
> --error-log-path=/var/log/nginx/error.log

[root@localhost nginx-1.14.2]# make
[root@localhost nginx-1.14.2]# make install

//配置环境变量
[root@localhost ~]# vim /etc/profile.d/nginx.sh
[root@localhost ~]# cat /etc/profile.d/nginx.sh 
export PATH=/usr/local/nginx/sbin:$PATH
[root@localhost ~]# . /etc/profile.d/nginx.sh
    
//启动nginx
[root@localhost ~]# ss -antl
[root@localhost ~]# ss -antl
State       Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
LISTEN      0      128                       *:111                                   *:*                  
LISTEN      0      128                       *:80                                    *:*                  
LISTEN      0      128                       *:51856                                 *:*                  
LISTEN      0      128                       *:22                                    *:*                  
LISTEN      0      128                      :::45995                                :::*                  
LISTEN      0      128                      :::111                                  :::*                  
LISTEN      0      128                      :::22                                   :::*      

//配置nginx访问页面
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
 #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            alias           /var/www;
            fastcgi_pass   192.168.233.129:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root

//重新加载配置文件
[root@localhost ~]# nginx -s reload          
  • 配置nfs
    在192.168.233.129上配置
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# vim /etc/exports
[root@localhost ~]# cat /etc/exports
/var/www 192.168.233.128(insecure,rw,no_root_squash)
[root@localhost ~]# systemctl start nfs-server
[root@localhost ~]# systemctl enable nfs-serve
[root@localhost ~]# cd /usr/src/zabbix-4.0.4
[root@localhost zabbix-4.0.4]# cp -a frontends/php/* /var/www/
cp:是否覆盖"/var/www/index.php"? y
[root@localhost zabbix-4.0.4]# chmod 777 /var/www/conf

在192.168.233.128上配置

[root@localhost ~]# yum -y install showmount
[root@localhost ~]# showmount -e 192.168.233.129
Export list for 192.168.233.129:
[root@localhost ~]# mount -t nfs 192.168.233.129:/var/www/ /usr/local/nginx/html
[root@localhost ~]# df -h
文件系统                  容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root      17G  5.1G   12G   30% /
devtmpfs                  478M     0  478M    0% /dev
tmpfs                     489M     0  489M    0% /dev/shm
tmpfs                     489M  6.9M  482M    2% /run
tmpfs                     489M     0  489M    0% /sys/fs/cgroup
/dev/sda1                1014M  125M  890M   13% /boot
tmpfs                      98M     0   98M    0% /run/user/0
192.168.233.129:/var/www   17G  5.7G   12G   34% /usr/local/nginx/html

root@localhost ~]# vim /etc/fstab 
[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Feb 18 21:02:08 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=6011a96d-9bf2-4131-9390-faf30b8d83ce /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
192.168.233.129:/var/www /usr/local/nginx/html nfs defaults,_netdev 0 0
  • 测试,Windows上访问192.168.233.128/zabbix.php
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值