CentOS环境配置(LNMP) Installation

Required Modules

yum update

yum -y install pcre-devel openssl openssl-devel

libunwind

wget http://ftp.yzu.edu.tw/nongnu/libunwind/libunwind-1.1.tar.gz

tar zxvf libunwind-1.1.tar.gz

cd libunwind-1.1

CFLAGS=-fPIC ./configure 

make CFLAGS=-fPIC

make CFLAGS=-fPIC install

google-perftools

wget https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.3.tar.gz

tar zxvf google-perftools-1.8.tar.gz  

cd google-perftools-1.8/

./configure  

make && make install

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf  

ldconfig 

Nginx

./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --with-http_concat_module --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-google_perftools_module

make

make install

##开机自动启动脚本

vi /etc/init.d/nginx

chkconfig --add nginx

chkconfig --level 2345 nginx  on

自动启动脚本: nginx

NGINX systemd service file: nginx.service

PHP

Install the EPEL repository

You install the EPEL repository by downloading the appropriate RPM package for your system and installing it. The following instructions use the 64-bit packages that work with Rackspace Cloud Servers instances.

CentOS Extras repository

The CentOS Extras repository includes a package to install EPEL, and is enabled by default. To install the EPEL package, run the following command:

sudo yum install epel-release

If that command doesn't work, perhaps because the CentOS Extras repository is disabled, the following sections provide manual installation instructions based on your distribution version.

CentOS and Red Hat Enterprise Linux 5.x

wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo rpm -Uvh epel-release-5*.rpm

Install the Remi repository (optional)

The Remi repository provides newer versions of the software in the core CentOS and Red Hat Enterprise Linux repositories. The Remi repository depends on the EPEL repository.

Package names in the Remi repository are the same as the package names used in the official repositories. This similarity can result in inadvertent package upgrades when you run an update with yum, so use the Remi repository with care.

Note: Because Remi uses package names that are the same as the package names in the official repositories, we do not recommend Remi for Rackspace customers with a managed level of support. Managed servers automatically update nightly by default, which can cause unplanned upgrades if the Remi repository is enabled. If you require the Remi repository or another repository with package name conflicts, contact Rackspace Support before applying any upgrades to ensure continued support for your server.

You install the Remi repository by downloading the appropriate RPM package for your system and installing it. The following instructions use the 64-bit packages that work with Cloud Servers instances.

CentOS and Red Hat Enterprise Linux 6.x

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm 
sudo rpm -Uvh remi-release-6*.rpm

Enable the Remi repository

The Remi repository is disabled by default.

To use the Remi repository only when you know you need it, use the --enablerepo=remi option when installing a package. For example:

sudo yum --enablerepo=remi install php-tcpdf

Install php

yum --enablerepo=remi install php54

yum --enablerepo=remi install php54-php-gd php54-php-mbstring php54-php-mcrypt php54-php-pdo php54-php-soap php54-php-mysqli php54-php-imap

yum --enablerepo=remi install php54-php-fpm

Java

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u40-b26/jdk-8u40-linux-x64.rpm" 

# Download the file.
# Uninstall any earlier installations of the JDK packages.

rpm -e package_name

# Install the package.

rpm -ivh jdk-8uversion-linux-x64.rpm

#To upgrade a package:

rpm -Uvh jdk-8uversion-linux-x64.rpm

# Delete the .rpm file if you want to save disk space.
# Exit the root shell. No need to reboot.

Starting with version 8u40, the JDK installation is integrated with alternatives framework and after installation, the alternatives framework is updated to reflect the binaries from the recently installed JDK. Java commands such as java, javac, javadoc, javap can be invoked from the command line.

Using the java -version command, users can confirm the default (recently installed) JDK version.

In addition, users can now check which specific rpm package provides the java files:

rpm -q --whatprovides java

Mysql

yum --enablerepo=remi install mysql  mysql-server

/etc/init.d/mysqld start

mysql_secure_installation

Redis

$ yum install tcl
$ wget http://download.redis.io/releases/redis-2.8.19.tar.gz
$ tar xzf redis-2.8.19.tar.gz
$ cd redis-2.8.19
$ make
$ cp redis.conf /etc/  
$ make test
$ make install
$ mkdir /etc/redis
$ cp redis/utils/redis_init_script /etc/init.d/redis_p6379
$ mv /etc/redis.conf /etc/redis
$ cp redis.conf  p6379.conf
$ vi p6379.conf
# 端口号
port 6379
# 是否作为守护进程运行
daemonize yes
# 如果作为后台进程运行需要配置pid
pidfile /var/run/redis/redis_6379.pid
# 日志记录等级,有4个可选值,debug,verbose(默认值),notice,warning
loglevel notice
# 日志文件保存地址及命名
logfile /var/log/redis_6379.log
# 本地数据库存放路径,默认值为 ./
dir /data/redis/p6379
# 本地数据库文件名,默认值为dump.rdb
dbfilename  dump6379.rdb
# 最大内存使用设置(单位bytes),设置为可用内存的一半。
# 1GB
maxmemory 1073741824
# 设置为其他Redis数据库的slave
# slaveof 127.0.0.1 6379
$ mkdir -p /var/run/redis/
$ mkdir -p /data/redis/p6379
$ vi /etc/init.d/redis_p6379

# add the following at the top:

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#
# chkconfig:   - 85 15
# description:  Redis is a persistent key-value database
# processname: redis_p6379
#
# and change pid location to 
# PIDFILE=/var/run/redis/redis_${REDISPORT}.pid

$ chkconfig --add redis_p6379
$ chkconfig --level 2345 redis_p6379 on

Supervisor

# install supervisor
$ yum install python-setuptools
$ easy_install supervisor
$ mkdir -p /etc/supervisor/conf.d
$ echo_supervisord_conf > /etc/supervisor/supervisord.conf
#
# vi supervisord.conf, and change the following lines to
# [supervisord]
# logfile=/var/log/supervisord/supervisord.log ;
#
# [include]
# files = /etc/supervisor/conf.d/*.conf
#
#
## create conf file for laravel queue
#
$ vi /etc/supervisor/conf.d/haoli58_laravel_queue.conf
 [program:haoli58LaravelQueue]
 command                 = /usr/bin/php54 /home/techract/web/artisan queue:work --daemon --env=production
 directory               = /home/techract/web/
 process_name            = %(program_name)s_%(process_num)s
numprocs                = 1
autostart               = true
autorestart             = true
stdout_logfile          = /home/techract/web/app/storage/logs/supervisor_haoli58LaravelQueue.log
stdout_logfile_maxbytes = 10MB
stderr_logfile          = /home/techract/web/app/storage/logs/supervisor_haoli58LaravelQueue.log
stderr_logfile_maxbytes = 10MB
#  下载你系统的*nux服务脚本: https://github.com/Supervisor/initscripts 到 /etc/init.d/supervisor
#  centos 可选 redhat-init-mingalevme
# 
$ supervisorctl  -c /etc/supervisor/supervisord.conf
> reread                # Get available jobs
> add haoli58LaravelQueue
> start haoli58LaravelQueue

脚本: supervisor

Memcached

install

yum install memcached

cat /etc/sysconfig/memcached

# OPTIONS="-l 127.0.0.1" 

/etc/init.d/memcached start

chkconfig --levels 235 memcached on

Installing the Memcached PHP Extension

yum --enablerepo=remi install php54-php-pecl-memcached

Inspecting Running Configuration

echo "stats settings" | nc localhost 11211

start

/etc/init.d/memcached start|stop

php-fpm 配置session handler

php_value[session.save_handler] = memcached

php_value[session.save_path]    = localhost:11211:1,localhost:11311:1

# restart nginx php-fpm