lnmp
搭建lnmp,动态显示zabbix网站
环境说明
系统平台 | IP | 服务 |
---|---|---|
redhat7 | 192.168.233.129 | MySQL、PHP |
redhat7 | 192.168.233.128 | nginx |
- 192.168.233.129
//安装mysql
/安装依赖包
[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g 306 mysql
[[email protected] ~]# id mysql
uid=996(mysql) gid=306(mysql) 组=306(mysql)
//下载二进制格式的mysql软件包
[[email protected] ~]# cd /usr/src/
[[email protected] 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/
[[email protected] src]# tar -xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] 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的属主属组
[[email protected] src]# cd /usr/local/
[[email protected] 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
[[email protected] local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.23-linux-glibc2.12-x86_64/"
[[email protected] local]# chown -R mysql.mysql /usr/local/mysql
[[email protected] 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/
//添加环境变量
[[email protected]ocalhost ~]# vim /etc/profile.d/mysql.sh
[[email protected] ~]# source /etc/profile.d/mysql.sh
[[email protected] ~]# 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
//建立数据存放目录
[[email protected] ~]# mkdir /opt/data
[[email protected] ~]# chown -R mysql.mysql /opt/data
[[email protected] ~]# ll /tmp/data -d
drwxr-xr-x. 2 mysql mysql 6 2月 20 16:01 /opt/data
//初始化数据库
[[email protected] ~]# /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 [email protected]: GSfIupL4jt?C
//请注意,这个命令的最后会生成一个临时密码,此处密码是GSfIupL4jt?C,一定要记住,登录数据库时会用到
//配置mysql
[[email protected] ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
[[email protected] ~]# vim /etc/ld.so.conf.d/mysql.conf
[[email protected] ~]# cat /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[[email protected] ~]# ldconfig
//生成配置文件
[[email protected] ~]# mv /etc/my.cnf /opt/
[[email protected] ~]# vim /etc/my.cnf
[[email protected] ~]# 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
//配置服务启动脚本
[[email protected] ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/tmp/data //在这两行的=后面添加内容,原本=后面没有内容
//启动mysql
[[email protected] ~]# service mysqld start
Starting MySQL. SUCCESS!
[[email protected] ~]# 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 :::*
//修改密码
//使用临时密码登录
[[email protected] ~]# 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
[[email protected] ~]# 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源
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# rm -rf *]
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# yum -y install epel-release
[[email protected] yum.repos.d]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
//安装依赖包
[[email protected] ~]# 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
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
//编译安装php
[[email protected] src]# tar xf php-7.2.8.tar.xz
[[email protected] src]# cd php-7.2.8
[[email protected] 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
[[email protected] php-7.2.8]# make
[[email protected] php-7.2.8]# make install
//安装后配置
[[email protected] ~]# vim /etc/profile.d/php7.sh
[[email protected] ~]# cat /etc/profile.d/php7.sh
export PATH=/usr/local/php7/bin:$PATH
[[email protected] ~]# source /etc/profile.d/php7.sh
[[email protected] ~]# 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
[[email protected] ~]# 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
[[email protected] ~]# cd /usr/src/
[[email protected] src]# cd php-7.2.8
[[email protected] php-7.2.8]# mv /etc/php.ini /opt/
[[email protected] php-7.2.8]# \cp php.ini-production /etc/php.ini
[[email protected] php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[[email protected] 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的相关选项为你所需要的值:
[[email protected] ~]# 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
[[email protected] ~]# service php-fpm start
Starting php-fpm done
//默认情况下,fpm监听在127.0.0.1的9000端口,也可以使用如下命令验证其是否已经监听在相应的套接字
[[email protected] ~]# 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主机上创建虚拟主机目录并生成php测试页面
[[email protected] ~]# mkdir /var/www
[[email protected] ~]# vim /var/www/index.php
[[email protected] ~]# cat /var/www/index.php
<?php
phpinfo();
?>
[[email protected] ~]# chown -R nginx.nginx /var/www //两边的用户要一致
- 测试
- 192.168.233.128
//nginx的安装
/创建系统用户nginx
[[email protected] ~]# groupadd -r nginx
[[email protected] ~]# useradd -r -M -s /sbin/nologin -g nginx nginx
//安装依赖环境
[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
//安装开发工具
[[email protected] ~]# 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 兼容性
兼容性程序库
图形管理工具
安全性工具
控制台互联网工具
教育软件
智能卡支持
电子实验室
科学记数法支持
系统管理
系统管理工具
通用桌面
完成
//创建日志存放目录
[[email protected] ~]# mkdir -p /var/log/nginx
[[email protected] ~]# chown -R nginx.nginx /var/log/nginx
//解压nginx
[[email protected] ~]# cd /usr/src/
[[email protected] src]# tar -xf nginx-1.14.2.tar.gz
//编译安装
[[email protected] 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
[[email protected] nginx-1.14.2]# make
[[email protected] nginx-1.14.2]# make install
//配置环境变量
[[email protected] ~]# vim /etc/profile.d/nginx.sh
[[email protected] ~]# cat /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
[[email protected] ~]# . /etc/profile.d/nginx.sh
//启动nginx
[[email protected] ~]# ss -antl
[[email protected] ~]# 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访问页面
[[email protected] ~]# 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
//重新加载配置文件
[[email protected] ~]# nginx -s reload
- 配置nfs
在192.168.233.129上配置
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# vim /etc/exports
[[email protected] ~]# cat /etc/exports
/var/www 192.168.233.128(insecure,rw,no_root_squash)
[[email protected] ~]# systemctl start nfs-server
[[email protected] ~]# systemctl enable nfs-serve
[[email protected] ~]# cd /usr/src/zabbix-4.0.4
[[email protected] zabbix-4.0.4]# cp -a frontends/php/* /var/www/
cp:是否覆盖"/var/www/index.php"? y
[[email protected] zabbix-4.0.4]# chmod 777 /var/www/conf
在192.168.233.128上配置
[[email protected] ~]# yum -y install showmount
[[email protected] ~]# showmount -e 192.168.233.129
Export list for 192.168.233.129:
[[email protected] ~]# mount -t nfs 192.168.233.129:/var/www/ /usr/local/nginx/html
[[email protected] ~]# 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
[email protected] ~]# vim /etc/fstab
[[email protected] ~]# 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