Centos7下源码编译安装Nginx1.16.1+Php7.2.21+Mysql5.7.22

安装nginx1.16.1

这台服务器的环境是刚刚安装完系统的新环境,没有安装任何软件.

准备nginx用户:
useradd -M -s /sbin/nologin nginx

[root@iZhp37dmahkdx7kgn3gss6Z nginx]# id nginx
uid=1004(nginx) gid=1005(nginx) groups=1005(nginx)

准备依赖包:
yum -y install zlib-devel pcre-devel openssl-devel

[yangshuqiu@iZhp37dmahkdx7kgn3gss6Z ~]$ sudo yum -y install zlib-devel pcre-devel openssl-devel
[sudo] password for yangshuqiu:
base | 3.6 kB 00:00:00
epel | 5.3 kB 00:00:00
extras | 2.9 kB 00:00:00
updates

下载Ngnix:

$ sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz

password for yangshuqiu:
–2019-12-23 11:47:57– http://nginx.org/download/nginx-1.16.1.tar.gz
Resolving nginx.org (nginx.org)… 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|95.211.80.227|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1032630 (1008K) [application/octet-stream]
Saving to: ‘nginx-1.16.1.tar.gz’

[yangshuqiu@iZhp37dmahkdx7kgn3gss6Z src]$ sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz
[sudo] password for yangshuqiu:
--2019-12-23 11:47:57-- http://nginx.org/download/nginx-1.16.1.tar.gz
Resolving nginx.org (nginx.org)… 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|95.211.80.227|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 1032630 (1008K) [application/octet-stream]
Saving to: ‘nginx-1.16.1.tar.gz’
./configure: error: C compiler cc is not found

You need to be root to perform this command. 解决办法

$ sudo yum -y install gcc gcc-c++ autoconf automake make
Package gcc-4.8.5-39.el7.x86_64 already installed and latest version
Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version
Package autoconf-2.69-11.el7.noarch already installed and latest version
Package automake-1.13.4-3.el7.noarch already installed and latest version
Package 1:make-3.82-24.el7.x86_64 already installed and latest version
Nothing to do

配置安装路径

[yangshuqiu@iZhp37dmahkdx7kgn3gss6Z nginx-1.16.1]$ sudo ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_random_index_module --with-http_sub_module
checking for OS
Linux 3.10.0-1062.4.1.el7.x86_64 x86_64
checking for C compiler … found
using GNU C compiler
gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
checking for gcc -pipe switch … found
checking for -Wl,-E switch … found
checking for gcc builtin atomic operations … found
checking for C99 variadic macros … found
checking for gcc variadic macros … found
checking for gcc builtin 64 bit byteswap … found
checking for unistd.h … found
checking for inttypes.h … found
checking for limits.h … found
checking for sys/filio.h … not found
checking for sys/param.h … found
checking for sys/mount.h … found
checking for sys/statvfs.h … found
checking for crypt.h … found
checking for Linux specific features
checking for epoll … found
checking for EPOLLRDHUP … found
checking for EPOLLEXCLUSIVE … not found
checking for O_PATH … found
checking for sendfile() … found
checking for sendfile64() … found
checking for sys/prctl.h … found
checking for prctl(PR_SET_DUMPABLE) … found
checking for prctl(PR_SET_KEEPCAPS) … found
checking for capabilities … found
checking for crypt_r() … found
checking for sys/vfs.h … found
checking for nobody group … found
checking for poll() … found
checking for /dev/poll … not found
checking for kqueue … not found
checking for crypt() … not found
checking for crypt() in libcrypt … found
checking for F_READAHEAD … not found
checking for posix_fadvise() … found
checking for O_DIRECT … found
checking for F_NOCACHE … not found
checking for directio() … not found
checking for statfs() … found
checking for statvfs() … found
checking for dlopen() … not found
checking for dlopen() in libdl … found
checking for sched_yield() … found
checking for sched_setaffinity() … found
checking for SO_SETFIB … not found
checking for SO_REUSEPORT … found
checking for SO_ACCEPTFILTER … not found
checking for SO_BINDANY … not found
checking for IP_TRANSPARENT … found
checking for IP_BINDANY … not found
checking for IP_BIND_ADDRESS_NO_PORT … not found
checking for IP_RECVDSTADDR … not found
checking for IP_SENDSRCADDR … not found
checking for IP_PKTINFO … found
checking for IPV6_RECVPKTINFO … found
checking for TCP_DEFER_ACCEPT … found
checking for TCP_KEEPIDLE … found
checking for TCP_FASTOPEN … found
checking for TCP_INFO … found
checking for accept4() … found
checking for eventfd() … found
checking for int size … 4 bytes
checking for long size … 8 bytes
checking for long long size … 8 bytes
checking for void * size … 8 bytes
checking for uint32_t … found
checking for uint64_t … found
checking for sig_atomic_t … found
checking for sig_atomic_t size … 4 bytes
checking for socklen_t … found
checking for in_addr_t … found
checking for in_port_t … found
checking for rlim_t … found
checking for uintptr_t … uintptr_t found
checking for system byte ordering … little endian
checking for size_t size … 8 bytes
checking for off_t size … 8 bytes
checking for time_t size … 8 bytes
checking for AF_INET6 … found
checking for setproctitle() … not found
checking for pread() … found
checking for pwrite() … found
checking for pwritev() … found
checking for sys_nerr … found
checking for localtime_r() … found
checking for clock_gettime(CLOCK_MONOTONIC) … found
checking for posix_memalign() … found
checking for memalign() … found
checking for mmap(MAP_ANON|MAP_SHARED) … found
checking for mmap("/dev/zero", MAP_SHARED) … found
checking for System V shared memory … found
checking for POSIX semaphores … not found
checking for POSIX semaphores in libpthread … found
checking for struct msghdr.msg_control … found
checking for ioctl(FIONBIO) … found
checking for struct tm.tm_gmtoff … found
checking for struct dirent.d_namlen … not found
checking for struct dirent.d_type … found
checking for sysconf(_SC_NPROCESSORS_ONLN) … found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) … found
checking for openat(), fstatat() … found
checking for getaddrinfo() … found
checking for PCRE library … found
checking for PCRE JIT support … found
checking for OpenSSL library … found
checking for zlib library … found
creating objs/Makefile
Configuration summary
using system PCRE library
using system OpenSSL library
using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

使用root用户去安装编译:

[root@iZhp37dmahkdx7kgn3gss6Z nginx-1.16.1]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/usr/local/src/nginx-1.16.1'
......

make[1]: Leaving directory `/usr/local/src/nginx-1.16.1'
[root@iZhp37dmahkdx7kgn3gss6Z nginx-1.16.1]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src

复制nginx.conf改名为nginx.conf.back 修改nginx.conf的配置文件,修改user:为nginx

测试修改后的nginx.conf是否有问题 : ./sbin/nginx -t

[root@iZhp37dmahkdx7kgn3gss6Z nginx]# ./sbin/nginx  -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动nginx

[root@iZhp37dmahkdx7kgn3gss6Z nginx]# ./sbin/nginx 

查看nginx

[root@iZhp37dmahkdx7kgn3gss6Z nginx]# pstree |grep nginx
|-nginx---nginx

查看nginx 端口占用情况

[root@iZhp37dmahkdx7kgn3gss6Z nginx]# netstat -tunpl |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19583/nginx: master

总结:

服务管理:
1.检测配置语法
/usr/local/nginx/sbin/nginx -t

2.启动服务
/usr/local/nginx/sbin/nginx

3.重载服务
/usr/local/nginx/sbin/nginx -s reload
pkill -HUP nginx

4.关闭服务
/usr/local/nginx/sbin/nginx -s stop
pkill nginx

5.开机启动
vi /etc/rc.local
/usr/local/nginx/sbin/nginx

进程管理:
pstree |grep nginx
ps -ef |grep nginx
ps aux |grep nginx

端口管理:
netstat -tunpl |grep nginx

安装mysql5.7.22

CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL5.7之前为了避免发生冲突首先删除MariaDB。
# rpm -qa | grep maria

# yum remove mariadb-libs -y

安装依赖工具

yum install -y cmake ncurses-devel libtirpc*

下载mysql5.7.22.tar.gz

[root@iZhp37dmahkdx7kgn3gss6Z src]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.22.tar.gz

 mysql5.7.22编译需要依赖boost包 ,boost1.5.9 .

下载之后解压:

tar xzf boost_1_70_0.tar.gz
mv boost_1_70_0 /usr/local/boost

解压mysql5.7.22.tar.gz

安装mysql5.7.22

tar xzf mysql5.7.22.tar.gz
cd mysql-5.7.22/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_BOOST=/usr/local/boost -DFORCE_INSOURCE_BUILD=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make install

注意mysql编译的时间比较长,长达3-4个小时。

安装php7.2.21

1.下载 php7.2.21 : https://www.php.net/distributions/php-7.2.21.tar.gz

安装依赖包

yum -y install autoconf freetype gd libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-clients freetype-devel gmp-devel libzip libzip-devel

2.编译安装
tar xzf php-7.2.21.tar.gz
cd php-7.2.21/

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-curl --with-gd --with-gmp --with-zlib --with-xmlrpc --with-openssl --without-pear --with-snmp --with-gettext --with-mhash --with-libxml-dir=/usr --with-fpm-user=nginx --with-fpm-group=nginx --enable-xml --enable-fpm  --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-sockets --enable-inline-optimization --enable-maintainer-zts --enable-mbregex --enable-mbstring --enable-pcntl --disable-fileinfo --disable-rpath --enable-libxml --enable-opcache --enable-mysqlnd
make && make install

3.配置文件
cp /usr/local/src/php-7.2.21/php.ini-development /usr/local/php/etc/php.ini

4.配置文件语法检测
/usr/local/php/sbin/php-fpm -t

出现下面问题:

解决办法:将php-fpm.conf.default 修改为 php-fpm.conf , www.conf.default 修改为www.conf

[root@iZhp37dmahkdx7kgn3gss6Z etc]# ls
php-fpm.conf.default php-fpm.d php.ini
[root@iZhp37dmahkdx7kgn3gss6Z etc]# mv php-fpm.conf.default php-fpm.conf
[root@iZhp37dmahkdx7kgn3gss6Z etc]# ls
php-fpm.conf php-fpm.d php.ini
[root@iZhp37dmahkdx7kgn3gss6Z etc]# cd php-fpm.d/
[root@iZhp37dmahkdx7kgn3gss6Z php-fpm.d]# ls
www.conf.default
[root@iZhp37dmahkdx7kgn3gss6Z php-fpm.d]# mv www.conf.default www.conf
[root@iZhp37dmahkdx7kgn3gss6Z php-fpm.d]# ls
www.conf

再次测试启动php

[root@iZhp37dmahkdx7kgn3gss6Z sbin]# ./php-fpm -t
[24-Dec-2019 19:53:20] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@iZhp37dmahkdx7kgn3gss6Z sbin]# pstree |grep php-fpm
|-php-fpm---20[php-fpm] [root@iZhp37dmahkdx7kgn3gss6Z sbin]# netstat -tunpl |grep php-fpm tcp 0 0 127.0.0.1:9000 0.0.0.0: LISTEN 28142/php-fpm: mast
[root@iZhp37dmahkdx7kgn3gss6Z sbin]#

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注