码迷,mamicode.com
首页 > 其他好文 > 详细

LEMP平台全编译搭建

时间:2017-06-10 14:07:07      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:nim   decide   host   reverse   image   安装   inf   sql   tps   

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

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 wont be recoverable.

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

WARNING: DOS-compatible mode is deprecated. Its 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初始化数据库

 

LEMP平台全编译搭建

标签:nim   decide   host   reverse   image   安装   inf   sql   tps   

原文地址:http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_26_lemp.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!