扩大
缩小

LEMP平台全编译搭建

1.安装nginx1.13

1.1解决依赖关系

编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries"。同时,还需要专门安装pcre-devel包:

[root@localhost ~]# yum groupinstall "Development tools" "Compatibility libraries"  -y
[root@localhost ~]# yum  install pcre-devel -y

1.2 添加用户

[root@localhost ~]# groupadd -r nginx
[root@localhost ~]# useradd -r -g nginx nginx

1.3下载nginx源码包

[root@localhost src]# wget http://nginx.org/download/nginx-1.13.1.tar.gz
[root@localhost src]# tar xf nginx-1.13.1.tar.gz 

 1.4编译安装

[root@localhost src]# cd nginx-1.13.1
[root@localhost nginx-1.13.1]#./configure \
  --prefix=/usr \
  --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 \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/var/tmp/nginx/scgi \
  --with-pcre
[root@localhost nginx-1.13.1]# make && make install 

1.5提供sysV脚本

[root@localhost nginx-1.13.1]# vim /etc/rc.d/init.d/nginx
[root@localhost nginx-1.13.1]# cat /etc/rc.d/init.d/nginx 
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -n "$user" ]; then
      if [ -z "`grep $user /etc/passwd`" ]; then
         useradd -M -s /bin/nologin $user
      fi
      options=`$nginx -V 2>&1 | grep 'configure arguments:'`
      for opt in $options; do
          if [ `echo $opt | grep '.*-temp-path'` ]; then
              value=`echo $opt | cut -d "=" -f 2`
              if [ ! -d "$value" ]; then
                  # echo "creating" $value
                  mkdir -p $value && chown -R $user $value
              fi
          fi
       done
    fi
}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
View Code

1.6 开机自启

[root@localhost nginx-1.13.1]# chmod +x /etc/rc.d/init.d/nginx 
[root@localhost nginx-1.13.1]# chkconfig --add nginx
[root@localhost nginx-1.13.1]# chkconfig nginx on

1.7启动

[root@localhost nginx-1.13.1]# service nginx start             #注意:启动前需要查看80端口是不是被httpd占用
Starting nginx:                                            [  OK  ]

1.8测试nginx

2.安装mariadb

2.1创建lvm存放数据

[root@localhost src]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc78823e1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +2G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e  
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p  

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc78823e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost src]# pvcreate  /dev/sdb1
  Writing physical volume data to disk "/dev/sdb1"
  Physical volume "/dev/sdb1" successfully created
[root@localhost src]# vgcreate vg_mysql /dev/sdb1
  Volume group "vg_mysql" successfully created
[root@localhost src]# lvcreate -L 1G -n lv_mysql vg_mysql
  Logical volume "lv_mysql" created
[root@localhost src]# mke2fs -t ext3 /dev/vg
vga_arbiter  vg_mysql/    
[root@localhost src]# mke2fs -t ext3 /dev/vg
vga_arbiter  vg_mysql/    
[root@localhost src]# mke2fs -t ext3 /dev/vg_mysql/lv_mysql 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost src]# mkdir /mydata
[root@localhost src]# mount /dev/vg_mysql/lv_mysql /mydata/
[root@localhost src]# tail -n 1 /etc/mtab  >> /etc/fstab
[root@localhost src]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Mon Jan 23 14:39:48 2017
#
# 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/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=5c3d4278-fa8d-4626-9546-67c0c26831b5 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sr0 /mnt/cdrom iso9660 ro 0 0
/dev/mapper/vg_mysql-lv_mysql /mydata ext3 rw 0 0
[root@localhost src]# chown -R mysql.mysql /mydata/
View Code

2.2创建mysql用户

root@localhost src]# groupadd -r mysql
[root@localhost src]# useradd -r -g mysql mysql -s /sbin/nologin -M -d /mydata/data
[root@localhost src]# mkdir /mydata/data

2.3下载安装mariadb

[root@localhost src]#  wget https://downloads.mariadb.org/interstitial/mariadb-10.2.6/source/mariadb-10.2.6.tar.gz/from/http%3A//mirrors.neusoft.edu.cn/mariadb/
[root@localhost src]# tar xf mariadb-10.2.6
[root@localhost src]# cd mariadb-10.2.6
[root@localhost yum.repos.d]# yum update cmake
[root@localhost mariadb-10.2.6]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[root@localhost mariadb-10.2.6]# make && make install

2.4初始化数据库

[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# scripts/mysql_install_db  --user=mysql --datadir=/mydata/data

2.5设置配置文件

[root@localhost mysql]# vim /etc/my.cnf
[root@localhost mysql]# cat /etc/my.cnf
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4
datadir=/mydata/data   

2.6设置启动脚本

[root@localhost mysql]# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld 
[root@localhost mysql]# chkconfig mysqld on 

2.7启动服务

[root@localhost mysql]# service mysqld start
Starting MySQL.170528 21:50:46 mysqld_safe Logging to '/mydata/data/localhost.localdomain.err'.
170528 21:50:46 mysqld_safe Starting mysqld daemon with databases from /mydata/data
                                                           [  OK  ]
[root@localhost mysql]# netstat -tunlp |grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      30899/mysqld    

2.8导出环境变量

[root@localhost mysql]# vim /etc/profile.d/mysql.sh
[root@localhost mysql]# cat /etc/profile.d/mysql.sh 
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# source /etc/profile.d/mysql.sh

2.9导出头文件

[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
`/usr/local/include/mysql' -> `/usr/local/mysql/include/'

2.10导出库文件

[root@localhost mysql]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf.d/mysql.conf
[root@localhost mysql]# ldconfig -v

2.11导出帮助文档

[root@localhost mysql]# echo "/usr/local/mysql/man" >> /etc/man.config 

2.12设置数据库用户密码

[root@localhost mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.6-MariaDB Source distribution

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> grant all privileges on *.* to root@'localhost' identified by 'zhaojiedi';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all privileges on *.* to root@'127.0.0.1' identified by 'zhaojiedi';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select host,user,password from user;
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> select host,user,password from mysql.user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *2F9ACBF8883BE76FAA7C042FDA59A7CC0841B40F |
| localhost.localdomain | root |                                           |
| 127.0.0.1             | root | *2F9ACBF8883BE76FAA7C042FDA59A7CC0841B40F |
| ::1                   | root |                                           |
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+
6 rows in set (0.00 sec)

 3.编译安装php

 3.1安装php依赖包

[root@localhost src]# yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

 

3.2下载并编译安装php

[root@localhost src]# wget http://cn2.php.net/get/php-7.1.6.tar.bz2/from/this/mirror
[root@localhost src]# tar xf php-7.1.6.tar.bz2 
[root@localhost src]# cd php-7.1.6
[root@localhost php-7.1.6]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx  --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared  --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir  --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets  --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
[root@localhost php-7.1.6]# make && make install

 

 3.7提供php配置文件

[root@localhost php-7.1.6]# cp php.ini-production /etc/php.ini
[root@localhost php-7.1.6]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@localhost php-7.1.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-7.1.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@localhost php-7.1.6]# chmod +x /etc/rc.d/init.d/php-fpm

 

3.8自动启动

[root@localhost php-7.1.6]# chkconfig --add php-fpm
[root@localhost php-7.1.6]# chkconfig php-fpm on

3.3导出环境变量

[root@localhost mysql]# vim /etc/profile.d/php.sh
[root@localhost mysql]# cat /etc/profile.d/php.sh 
export PATH=/usr/local/php/bin:$PATH
[root@localhost mysql]# source /etc/profile.d/php.sh

3.4导出头文件

[root@localhost mysql]# ln -sv /usr/local/php/include/ /usr/local/include/php
`/usr/local/include/php' -> `/usr/local/php/include/'

3.5导出库文件

[root@localhost mysql]# echo "/usr/local/php/lib" >> /etc/ld.so.conf.d/php.conf
[root@localhost mysql]# ldconfig -v

3.6导出帮助文档

[root@localhost mysql]# echo "/usr/local/php/man" >> /etc/man.config 

3.7启动php并查看

[root@localhost php-7.1.6]# service php-fpm start
Starting php-fpm  done
[root@localhost php-7.1.6]# ps aux |grep php-fpm
root     11337  0.0  0.1  28696  3128 ?        Ss   23:08   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)                                                                    
nginx    11338  0.0  0.1  28696  2572 ?        S    23:08   0:00 php-fpm: pool www                                                                                                            
nginx    11339  0.0  0.1  28696  2572 ?        S    23:08   0:00 php-fpm: pool www                                                                                                            
root     11342  0.0  0.0   4336   744 pts/6    S+   23:09   0:00 grep php-fpm

 

4.整合nginx和php7

4.1 nginx配置php页面

[root@localhost php-7.1.6]# vim /etc/nginx/nginx.conf
启用如下几行
 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
下面的位置加入index.php默认主页
   location / {
            root   html;
            index   index.php index.html index.htm;
        }

4.2添加fatcgi_params文件

[root@localhost php-7.1.6]# mv /etc/nginx/fastcgi_params /etc/nginx/fastcgi_params.bak
[root@localhost php-7.1.6]# vim /etc/nginx/fastcgi_params
[root@localhost php-7.1.6]# cat /etc/nginx/fastcgi_params
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

4.3添加测试主页

[root@localhost php-7.1.6]# cd /usr/html/
50x.html    index.html  
[root@localhost php-7.1.6]# vim /usr/html/index.php
[root@localhost php-7.1.6]# cat /usr/html/index.php 
<?php
phpinfo();
?>

4.4测试

[root@localhost php-7.1.6]# service nginx reload
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Reloading nginx:                                           [  OK  ]

5.安装具体的应用

5.1配置discuz应用

5.1.1下载并解压discuz

[root@localhost src]#wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
[root@localhost src]#unzip Discuz_X3.3_SC_UTF8.zip -d /usr/html/discuz

5.1.2 访问 http://192.168.5.68/discuz/upload/home.php

5.1.3 创建需要的目录

#这里我就简单的设置了777权限了
[root@localhost upload]# chmod 777 -R ./data/
[root@localhost upload]# chmod 777 -R ./config/
[root@localhost upload]# chmod 777 -R ./uc_client/
[root@localhost upload]# chmod 777 -R ./uc_server/

5.1.4访问主页

posted on 2017-06-10 11:21  LinuxPanda  阅读(381)  评论(0编辑  收藏  举报

导航