centos7下编译安装lnmp和nginx代理实验

1、先安装mysql

cd /usr/local/src
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql
useradd mysql
mkdir /data/
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-default.cnf  /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld

定义basedir和datadir

/etc/init.d/mysqld start

2、安装php

编译安装php-fpm

什么是PHP-FPM

PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,可以在 http://php-fpm.org/download下载得到.

PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

新版PHP已经集成php-fpm了,不再是第三方的包了,推荐使用。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM,其它参数都是配置php的,具体选项含义可以查看这里。

安装前准备
centos下执行

yum -y install gcc automake autoconf libtool make

yum -y install gcc gcc-c++ glibc

yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel

axel http://mirrors.sohu.com/php/php-7.2.1.tar.xz
tar Jxf php-7.2.1.tar.xz
 useradd -s /sbin/nologin php-fpm
 cd php-7.2.1

./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt
--enable-mbstring --disable-pdo --with-curl --disable-debug  --disable-rpath
--enable-inline-optimization --with-bz2  --with-zlib --enable-sockets
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex
--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli
--with-gd --with-jpeg-dir

make all install
cp php.ini-production /usr/local/php-fpm/etc/php.ini

vim /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
 chmod 755 /etc/init.d/php-fpm
 chkconfig --add php-fpm
 chkconfig php-fpm on
 service php-fpm start
 ps aux |grep php-fpm

报错 Cannot find OpenSSL‘s <evp.h>
执行 yum install openssl openssl-devel

报错 Please reinstall the libcurl distribution
执行 yum -y install curl-devel

错误 jpeglib.h not found
执行 yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
和执行 yum install libjpeg-devel

错误:checking for BZip2 in default path... not found configure: error: Please reinstall the BZip2 distribution 这是bzip2软件包没有安装
执行 yum install bzip2-devel.x86_64 -y

错误:configure: error: xpm.h not found.
执行yum install libXpm-devel

错误: Unable to locate gmp.h
执行 yum install gmp-devel

错误:Unable to detect ICU prefix or /usr//bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works
执行 yum install -y icu libicu libicu-devel

错误:mcrypt.h not found. Please reinstall libmcrypt.
执行 yum install php-mcrypt libmcrypt libmcrypt-devel

错误: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
执行 yum install postgresql-devel

错误: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
执行yum install libxslt-devel

3、安装nginx

axel https://nginx.org/download/nginx-1.12.2.tar.gz
Initializing download: https://nginx.org/download/nginx-1.12.2.tar.gz

tar zxf nginx-1.12.2.tar.gz
cd nginx-1.12.2/
useradd nginx -s /sbin/nologin 

Nginx编译参数
–user 指定启动程序所属用户
–group 指定组
–prefix 指定安装路径
–sbin-path 设置nginx二进制文件的路径名
–conf-path 指定配置文件路径
–error-log-path 错误日志文件路径
–http-log-path 指定访问日志文件路径
–http-client-body-temp-path 设置存储HTTP客户端请求主体的临时文件路径
–http-proxy-temp-path 设置存储HTTP代理临时文件的路径
–http-fastcgi-temp-path 设置存储HTTP fastcgi的临时文件的路径
–pid-path 设置nginx.pid文件路径
–lock-path 设置nginx.lock文件路径
–with-openssl 启用SSL
–with-pcre 启用正则表达式
–with-http_stub_status_module 安装可以监控nginx状态的模块
–with-http_ssl_module 启用SSL支持
–with-http_gzip_static_module 启用gzip压缩

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-http_sub_module
echo $?
make && make install

vim /etc/init.d/nginx

#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"
NGINX_PID="/var/run/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
    echo -n $"Starting $prog: "
    mkdir -p /dev/shm/nginx_temp
    daemon $NGINX_SBIN -c $NGINX_CONF
    RETVAL=$?
    echo
    return $RETVAL
}
stop()
{
    echo -n $"Stopping $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -TERM
    rm -rf /dev/shm/nginx_temp
    RETVAL=$?
    echo
    return $RETVAL
}
reload()
{
    echo -n $"Reloading $prog: "
    killproc -p $NGINX_PID $NGINX_SBIN -HUP
    RETVAL=$?
    echo
    return $RETVAL
}
restart()
{
    stop
    start
}
configtest()
{
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit $RETVAL
chmod 755 !$
chkconfig --add nginx
service nginx start
ps aux | grep nginx
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload 

增加mysql和php的环境变量

vim /etc/profile.d/mysql.sh
PATH=$PATH:/usr/local/mysql/bin

vim /etc/profile.d/php.sh
PATH=$PATH:/usr/local/php-fpm/bin

非虚拟主机的配置

vim /etc/nginx/nginx.conf

user nginx nginx;
worker_processes 2;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 6000;
}
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]‘
    ‘ $host "$request_uri" $status‘
    ‘ "$http_referer" "$http_user_agent"‘;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /tmp/nginx/client_body;
    proxy_temp_path /tmp/nginx/proxy;
    fastcgi_temp_path /tmp/nginx/fastcgi;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm
    application/xml;
    server
    {
        listen 80;
        server_name localhost;
        index index.html index.htm index.php;
        root /usr/local/nginx/html;
        location ~ \.php$
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
        }
    }
}
Vim /data/www/1.php

<?php
    echo "test php scripts.";
?>

curl localhost/1.php

test php scripts.

配置默认虚拟主机:
mkdir /etc/nginx/vhost
修改nginx.conf,
增加

 include vhost/*.conf
user nginx nginx;
worker_processes 2;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 6000;
}
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]‘
    ‘ $host "$request_uri" $status‘
    ‘ "$http_referer" "$http_user_agent"‘;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /tmp/nginx/client_body;
    proxy_temp_path /tmp/nginx/proxy;
    fastcgi_temp_path /tmp/nginx/fastcgi;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm
    application/xml;
    include vhost/*.conf;
}
Vim /etc/nginx/vhost/default.conf

server
{
listen 80;
server_name oceanwing.com;
index index.html index.htm index.php;
root /data/www/default;
location ~ \.php$
    {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/default$fastcgi_script_name;
    }
}

nginx -t
nginx -s reload

mkdir -p /data/www/default/

mv /data/www/*.php /data/www/default
 curl -x 127.0.0.1:80 oceanwing.com

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"&gt;
<html>
<head>
<title>LNMP</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="Gavin Zhao">
<meta name="keywords" content="Centos7服务器">
<meta name="description" content="">
<link rel="shortcut icon" href="favicon.ico" type="image/ico">
<style type="text/css">

恭喜,lnmp 已安装成功!

查看服务器WEB环境:探针信息 phpinfo信息

为安全起见,本页可删除或重命名

添加虚拟主机代理:
1、confluence代理
80端口代理confluence的8090
vim /etc/ng``inx/vhost/itks.oceanwing.com.conf
server {
server_name itks.oceanwing.com
listen 80;
location / {
proxy_pass http://172.16.20.247:8090/;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
2、Jenkins代理
```
vim /etc/nginx/vhost/jenkins.oceanwing.com.conf
server {
server_name jenkins.oceanwing.com
listen 80;
location / {
proxy_pass http://172.16.22.245:8080;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
3、jira的代理
```
vim /etc/nginx/vhost/jira.oceanwing.com.conf
server {
server_name jira.oceanwing.com
listen 80;
location / {
proxy_pass http://172.16.20.247:8080/;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
![](http://i2.51cto.com/images/blog/201802/08/f6d353a850cef04d710df548c9141875.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

原文地址:http://blog.51cto.com/m51cto/2070200

时间: 2024-10-13 14:58:18

centos7下编译安装lnmp和nginx代理实验的相关文章

centos下编译安装LNMP环境

自PHP-5.3.3起,PHP-FPM加入到了PHP核心,编译时加上--enable-fpm即可提供支持. PHP-FPM以守护进程在后台运行,Nginx响应请求后,自行处理静态请求,PHP请求则经过fastcgi_pass交由PHP-FPM处理,处理完毕后返回. Nginx和PHP-FPM的组合,是一种稳定.高效的PHP运行方式,效率要比传统的Apache和mod_php高出不少. 二.依赖环境 yum -y install gcc gcc-c++ make cmake automake au

centos6.7下编译安装lnmp

很多步骤不说明了,请参照本人的centos6.7下编译安装lamp,这次的架构是nginx+php-fpm一台服务器,mysql一台服务器 (1)首先编译安装nginx: 操作命令: yum -y groupinstall "Development Tools" "Server Platform Development" yum -y install pcre-devel  useradd -r nginx  mkdir /var/tmp/nginx   事先得创建

centos7下编译安装nginx并实现日志轮替

centos7编译安装nginx: 首先确保系统上存在编译安装使用的必要工具运行:  # yum groupinstall "development tools" "server platform development" 1 下载PCRE version 4.4 - 8.40 (ngx_http_rewrite_module模块需要)    # wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/p

CentOS7.2编译安装LNMP

一.前言 1.环境说明 基础环境Linux+Nginx+MySQL+PHP linux:7.2 nginx:1.10.2 mysql:5.6.17 php:5.5.12 2.部署说明 php安装目录:/usr/local/php php.ini配置文件路径:/usr/local/php/etc/php.ini Nginx安装目录:/usr/local/nginx Nginx配置文件路径:/etc/nginx/nginx.conf Nginx网站根目录:/usr/local/nginx/html

Linux下编译安装Lnmp

1.安装nginx 下载链接http://nginx.org/en/download.html (1)下载,解压 wget http://nginx.org/download/nginx-1.15.8.tar.gz tar zxf nginx-1.15.8.tar.gz cd nginx-1.15.8 (2)在编译安装之前先安装需要的依赖库和编译软件安装 yum install gcc gcc-c++ glibc -y yum install pcre-devel -y yum install

在centos下编译安装配置高性能Nginx

安装nginx的依赖包:pcre, pcre-devel 编译nginx事实上需要的依赖包是pcre-devel,可以执行yum install pcre-devel 安装它.不过这个包的编译安装很简单,正好我们拿它练练手,熟悉熟悉linux编译安装软件的一般过程. [tips] linux下从源码编译安装软件一般是三步:配置.编译.安装.具体一点说就依次是执行三条命令:configure, make, make install. 不多讲理论,实际操作一下就明白了. 在build目录下创建子目录

CentOS 6.6 环境下 编译安装LNMP

环境:      OS:     CentOS 6.6     IP: 172.16.66.100    Nginx:  nginx-1.6.2    PHP:     php-5.4.40    Xcache: xcache-3.2.0    Mysql:  mariadb-5.5.43 一.前期环境准备: 1.根据官方ISO 创建本地yum源[[email protected] ~]# mkdir /mnt/cd [[email protected] ~]# mount /dev/cdrom

CentOS7下编译安装Python3.7.x【亲测有效】

所有操作都在root用户下操作 下载安装包 编译安装 建立软链接 验证 安装: 更新yum: yum update 安装Python依赖: yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel zlib-devel ncurses-devel tk-devel libffi-devel gcc make 下载python安装包: 这是安装的是Python3.7.4 由于可能

CentOS7.1编译安装LNMP

系统CentOS7.1链接 http://mirrors.sohu.com/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso   md5值: d07ab3e615c66a8b2e9a50f4852e6a77  CentOS-7-x86_64-Minimal-1503-01.iso 系统为最小化安装,版本号: nginx:1.6.3 mysql:5.5.37 php:5.3.28 下面shell,没有多的版本判断设置,可