LNMP(源码编译)

实验环境:

系统 角色 IP 部署事物
Redhat 7.4 server1 192.168.230.16 mysql
php
Redhat 7.4 server2 192.168.230.15 nginx

注意:做之前记得关闭防火墙和selinux

安装php

//配置yum源
[[email protected] ~]# cd /etc/yum.repos.d/
[[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 groups mark install 'Development Tools'
[[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]# ls
apr-1.6.3          apr-util-1.6.1.tar.bz2  httpd-2.4.34.tar.bz2                        php-7.2.8.tar.xz
apr-1.6.3.tar.bz2  debug                   kernels
apr-util-1.6.1     httpd-2.4.34            mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
//编译安装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 -j $(cat /proc/cpuinfo |grep processor|wc -l)
[[email protected] php-7.2.8]# make install
//安装后配置
[[email protected] ~]# echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
[[email protected] ~]# source /etc/profile.d/php7.sh
//配置php-fpm
[[email protected] ~]# cp php.ini-production /etc/php.ini
[[email protected] ~]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] ~]# chmod +x /etc/rc.d/init.d/php-fpm
[[email protected] ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[[email protected] ~]# 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
pm.max_children = 50    //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5    //启动时启动5个进程
pm.min_spare_servers = 2    //最小空闲进程数
pm.max_spare_servers = 8    //最大空闲进程数

[[email protected] ~]# service php-fpm start
[[email protected] ~]# ss -antl

安装mysql

//安装依赖包,可本地源
[[email protected] ~]# yum groups mark install 'Development Tools'
[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
//下载二进制格式的mysql软件包
[[email protected] ~]# cd /usr/src/
[[email protected] src]# ls
apr-1.6.3          apr-util-1.6.1.tar.bz2  httpd-2.4.34.tar.bz2
apr-1.6.3.tar.bz2  debug                   kernels
apr-util-1.6.1     httpd-2.4.34            mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
//解压软件至/usr/local/
[[email protected] src]# tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] src]# cd /usr/local/
[[email protected] local]# ls
apache  apr-util  etc    include  lib64    mysql-5.7.23-linux-glibc2.12-x86_64  share
apr     bin       games  lib      libexec  sbin                                 src
[[email protected] local]# ln -sv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
//修改目录/usr/local/mysql的属主属组
[[email protected] ~]# chown -R mysql.mysql /usr/local/mysql
//添加环境变量
[[email protected] ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh
//建立数据存放目录
[[email protected] mysql]# mkdir /opt/data
[[email protected] mysql]# chown -R mysql.mysql /opt/data/
//初始化数据库
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2019-02-20T15:57:51.078089Z 1 [Note] A temporary password is generatedfor [email protected]: fjHG>8Fgflo!
//请注意,这个命令的最后会生成一个临时密码,此处密码是fjHG>8Fgflo!

//配置mysql
[[email protected] ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
[[email protected] ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[[email protected] ~]# ldconfig -v 

//生成配置文件
[[email protected] ~] cat > /etc/my.cnf <<EOF
[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
EOF

//配置服务启动脚本
[[email protected] ~] cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~] sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[[email protected] ~] sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld

//启动mysql
[[email protected] ~]# service mysqld start
[[email protected] ~]# ss -antl
//使用临时密码登录
[[email protected] ~]# mysql -uroot -p
Enter password: 
//设置新密码
mysql> set password = password('CS123.com');
mysql> quit

安装nginx

[[email protected] ~]# useradd -r -M -s /sbin/nologin nginx
[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[[email protected] ~]# mkdir -p /var/log/nginx
[[email protected] ~]# chown -R nginx.nginx /var/log/nginx
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
[[email protected] src]# tar xf nginx-1.14.2.tar.gz
[[email protected] src]# cd nginx-1.14.2
[[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 -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
[[email protected] nginx-1.14.2]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[[email protected] nginx-1.14.2]# . /etc/profile.d/nginx.sh
[[email protected] ~]# cd /usr/local/nginx/conf/
[[email protected] conf]# vim nginx.conf

user  nginx;
error_log  logs/error.log;
location / {
	root   /soft/code;
		index  index.php index.html index.htm;
}
location ~ \.php$ {
	root           /soft/code;
		fastcgi_pass   192.168.230.16:9000;
		fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  /soft/code$fastcgi_script_name;
		include        fastcgi_params;
}

php服务器修改配置文件并创建对应目录

[[email protected] ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 192.168.230.16:9000
listen.allowed_clients = 192.168.230.15
[[email protected] ~]# service php-fpm start
[[email protected] ~]# ss -antl

[[email protected] ~]# mkdir -p /soft/code/
//phpinfo界面
[[email protected] ~]# vim /soft/code/index.php
<?php
   phpinfo();
?>
//zabbix安装界面
[[email protected] ~]# cp -r /usr/local/apache/htdocs/zabbix/ /soft/code/

检测语法并启动nginx

[[email protected] conf]# nginx -t
[[email protected] conf]# nginx -s reload

浏览器检测
LNMP(源码编译)

LNMP(源码编译)