转:lnmp 搭建手册-黑一路人

 

【LAMP环境搭建手册】 v1.4.1
Author: heiyeluren
Created: 2015/6/3
Lastmodify: 2016/4/1


一、软件列表

# 基础软件 #
Nginx : https://openresty.org/download/openresty-1.9.7.4.tar.gz #采用 OpenResty 版的Nginx
PHP : http://cn2.php.net/get/php-5.6.20.tar.gz/from/this/mirror
: http://mirrors.sohu.com/php/php-5.6.20.tar.gz
MySQL : http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/mysql-5.6.29.tar.gz
: http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29.tar.gz
: http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
: http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.11.tar.gz
Redis : http://download.redis.io/releases/redis-2.8.24.tar.gz
Memcache : http://www.memcached.org/files/memcached-1.4.25.tar.gz
Coreseek : http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
: http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz
Sphinx : http://sphinxsearch.com/files/sphinx-2.0.2-beta.tar.gz
: #http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz

# Lib库 #
libmcrypt : ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
mhash : http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
jpegsrc : http://www.ijg.org/files/jpegsrc.v9a.tar.gz
libjpeg : http://jaist.dl.sourceforge.net/project/libjpeg-turbo/1.4.2/libjpeg-turbo-1.4.2.tar.gz
libpng : http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.21/libpng-1.6.21.tar.gz
libwebp : http://pkgs.fedoraproject.org/repo/pkgs/libwebp/libwebp-0.5.0.tar.gz/ba81eb9bf23e3c69a2f5cc8dcdb5938f/libwebp-0.5.0.tar.gz
giflib : http://jaist.dl.sourceforge.net/project/giflib/giflib-5.1.3.tar.gz
ImageMagick : http://jaist.dl.sourceforge.net/project/imagemagick/6.9.3-sources/ImageMagick-6.9.3-7.tar.gz
GraphicsMagick : http://jaist.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.22/GraphicsMagick-1.3.22.tar.gz
libmemcached : http://download.openpkg.org/components/cache/memcached/libmemcached-1.0.18.tar.gz
libgearmandclient : https://github.com/ButoVideo/gearmand-latest/archive/master.zip
librdkafka : https://github.com/edenhill/librdkafka/archive/0.9.0.zip
sphinx0.9.x : http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz
sphinx1.x : http://sphinxsearch.com/files/sphinx-1.10-beta.tar.gz
sphinx2.0.x : http://sphinxsearch.com/files/sphinx-2.0.10-release.tar.gz
sphinx2.1.x : http://sphinxsearch.com/files/sphinx-2.1.9-release.tar.gz
sphinx2.2.x : http://sphinxsearch.com/files/sphinx-2.2.9-release.tar.gz

# PHP扩展 #
memcached : http://pecl.php.net/get/memcached-2.2.0.tgz
imagick : http://pecl.php.net/get/imagick-3.4.1.tgz
gmagick : http://pecl.php.net/get/gmagick-1.1.7RC3.tgz
redis : http://pecl.php.net/get/redis-2.2.7.tgz
mongo : http://pecl.php.net/get/mongo-1.6.13.tgz
kafka : https://github.com/EVODelavega/phpkafka/archive/master.zip
gearman : http://pecl.php.net/get/gearman-1.1.2.tgz
sphinx : http://pecl.php.net/get/sphinx-1.3.3.tgz
memcache : http://pecl.php.net/get/memcache-3.0.8.tgz
seaslog : http://pecl.php.net/get/SeasLog-1.5.0.tgz
phalcon : https://github.com/phalcon/cphalcon/archive/phalcon-v2.0.3.zip
yaf : http://pecl.php.net/get/yaf-2.3.5.tgz
msgpack : http://pecl.php.net/get/msgpack-0.5.7.tgz
protobuf : https://github.com/allegro/php-protobuf/archive/master.zip
swoole : http://pecl.php.net/get/swoole-1.8.3.tgz

# 基础工具库 #
autoconf 2.64: http://down1.chinaunix.net/distfiles/autoconf-2.64.tar.bz2


######## 下载软件指令 #########
if [ $USER != "work" ]; then su work; fi
cd && cd soft

# 基础软件
if [ ! -f openresty-1.9.7.4.tar.gz ]; then wget http://openresty.org/download/openresty-1.9.7.4.tar.gz ; fi
if [ ! -f php-5.6.20.tar.gz ]; then rm -f mirror; wget http://mirrors.sohu.com/php/php-5.6.20.tar.gz; fi
if [ ! -f mysql-5.6.29.tar.gz ]; then wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29.tar.gz; fi
if [ ! -f redis-2.8.24.tar.gz ]; then wget https://github.com/antirez/redis/archive/2.8.24.tar.gz && mv 2.8.24.tar.gz redis-2.8.24.tar.gz; fi
if [ ! -f memcached-1.4.25.tar.gz ]; then wget http://www.memcached.org/files/memcached-1.4.25.tar.gz ; fi
if [ ! -f coreseek-4.1-beta.tar.gz ]; then wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz; fi
if [ ! -f coreseek-3.2.14.tar.gz ]; then wget http://www.coreseek.cn/uploads/csft/3.2/coreseek-3.2.14.tar.gz; fi
if [ ! -f sphinx-2.0.2-beta.tar.gz ]; then wget http://sphinxsearch.com/files/sphinx-2.0.2-beta.tar.gz; fi
#if [ ! -f sphinx-0.9.9.tar.gz ]; then wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz; fi


#Lib库
if [ ! -f libmcrypt-2.5.7.tar.gz ]; then wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz; fi
if [ ! -f mhash-0.9.9.9.tar.gz ]; then wget http://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz; fi
if [ ! -f jpegsrc.v9a.tar.gz ]; then wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz; fi
if [ ! -f libjpeg-turbo-1.4.2.tar.gz ]; then wget http://jaist.dl.sourceforge.net/project/libjpeg-turbo/1.4.2/libjpeg-turbo-1.4.2.tar.gz; fi
if [ ! -f libpng-1.6.21.tar.gz ]; then wget http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.21/libpng-1.6.21.tar.gz; fi
if [ ! -f giflib-5.1.3.tar.gz ]; then wget http://jaist.dl.sourceforge.net/project/giflib/giflib-5.1.3.tar.gz; fi
if [ ! -f tiff-4.0.4.tar.gz ]; then wget ftp://ftp.remotesensing.org/pub/libtiff/tiff-4.0.4.tar.gz; fi
if [ ! -f libwebp-0.5.0.tar.gz ]; then wget http://pkgs.fedoraproject.org/repo/pkgs/libwebp/libwebp-0.5.0.tar.gz/ba81eb9bf23e3c69a2f5cc8dcdb5938f/libwebp-0.5.0.tar.gz; fi
if [ ! -f ImageMagick-6.9.3-7.tar.gz ]; then wget http://jaist.dl.sourceforge.net/project/imagemagick/6.9.3-sources/ImageMagick-6.9.3-7.tar.gz; fi
if [ ! -f GraphicsMagick-1.3.22.tar.gz ]; then wget http://jaist.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.22/GraphicsMagick-1.3.22.tar.gz; fi
if [ ! -f libmemcached-1.0.18-exhsieh.tar.gz ]; then wget http://download.openpkg.org/components/cache/memcached/libmemcached-1.0.18.tar.gz; fi
if [ ! -f gearmand-1.1.12.tar.gz ]; then wget https://github.com/ButoVideo/gearmand-latest/archive/master.zip && unzip master.zip && mv gearmand-latest-master/*.gz . && rm -rf gearmand-latest-master && rm -f master.zip ; fi
if [ ! -f librdkafka-0.9.0.zip ]; then wget https://github.com/edenhill/librdkafka/archive/0.9.0.zip && mv 0.9.0.zip librdkafka-0.9.0.zip; fi
if [ ! -f sphinx-2.0.10-release.tar.gz ]; then wget http://sphinxsearch.com/files/sphinx-2.0.10-release.tar.gz; fi

# PHP扩展 #
if [ ! -f memcached-2.2.0.tgz ]; then wget http://pecl.php.net/get/memcached-2.2.0.tgz; fi
if [ ! -f imagick-3.4.1.tgz ]; then wget http://pecl.php.net/get/imagick-3.4.1.tgz; fi
if [ ! -f gmagick-1.1.7RC3.tgz ]; then wget http://pecl.php.net/get/gmagick-1.1.7RC3.tgz; fi
if [ ! -f redis-2.2.7.tgz ]; then wget http://pecl.php.net/get/redis-2.2.7.tgz; fi
if [ ! -f mongo-1.6.13.tgz ]; then wget http://pecl.php.net/get/mongo-1.6.13.tgz; fi
if [ ! -f gearman-1.1.2.tgz ]; then wget http://pecl.php.net/get/gearman-1.1.2.tgz; fi
if [ ! -f phpkafka-master.zip ]; then wget https://github.com/EVODelavega/phpkafka/archive/master.zip && mv master.zip phpkafka-master.zip; fi
if [ ! -f memcache-3.0.8.tgz ]; then wget http://pecl.php.net/get/memcache-3.0.8.tgz; fi
if [ ! -f sphinx-1.3.3.tgz ]; then wget http://pecl.php.net/get/sphinx-1.3.3.tgz; fi
if [ ! -f SeasLog-1.5.0.tgz ]; then wget http://pecl.php.net/get/SeasLog-1.5.0.tgz; fi
if [ ! -f phalcon-v2.0.3.zip ]; then wget https://github.com/phalcon/cphalcon/archive/phalcon-v2.0.3.zip; fi
if [ ! -f yaf-2.3.5.tgz ]; then wget http://pecl.php.net/get/yaf-2.3.5.tgz; fi
if [ ! -f msgpack-0.5.7.tgz ]; then wget http://pecl.php.net/get/msgpack-0.5.7.tgz; fi
if [ ! -f php-protobuf-master.zip ]; then wget https://github.com/allegro/php-protobuf/archive/master.zip && mv master.zip php-protobuf-master.zip; fi
if [ ! -f swoole-1.8.3.tgz ]; then wget http://pecl.php.net/get/swoole-1.8.3.tgz; fi

# 基础工具库
if [ ! -f autoconf-2.64.tar.bz2 ]; then wget http://down1.chinaunix.net/distfiles/autoconf-2.64.tar.bz2; fi

 

二、初始化环境

1. 安装基本的系统支持库

if [ $USER != "root" ]; then su root; fi
yum -y install gcc gcc-c++ gdb make cmake automake autoconf nasm libtool imake binutils flex bison gmp gmp-devel mpfr glibc libstdc++ libgomp libmudflap ncurses ncurses-libs ncurses-devel boost boost-devel libgsasl libgsasl-devel cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib jemalloc jemalloc-devel gperf gperftools-libs gperftools-devel systemtap-sdt-devel wget unzip openssl openssl-devel pcre pcre-devel zlib zlib-devel bzip2 bzip2-devel curl libcurl libcurl-devel libevent libevent-devel libgcrypt libgcrypt-devel libpng libpng-devel libjpeg-turbo libjpeg-turbo-devel openjpeg openjpeg-devel openjpeg-libs giflib giflib-devel giflib-utils gd gd-devel ImageMagick ImageMagick-devel ImageMagick-c++ ImageMagick-c++-devel GraphicsMagick GraphicsMagick-devel GraphicsMagick-c++ GraphicsMagick-c++-devel gettext gettext-devel freetype freetype-devel libtiff libtiff-devel libwebp libwebp-devel libwebp-tools libxml2 libxml2-devel libxslt libxslt-devel libuuid libmemcached libmemcached-devel libuuid-devel expat expat-devel expat21 expat21-devel

## 注意:如果是CentOS/RHEL 7.0+系统,需要使用如下指令:(否则会报错:Error: Protected multilib versions: xxxxx) ##
## 也可以执行:package-cleanup --cleandupes 把旧版本包卸载后再执行上面的yum 安装命令 ##
yum -y install gcc gcc-c++ gdb make cmake automake autoconf nasm libtool imake binutils flex bison gmp gmp-devel mpfr glibc libstdc++ libgomp libmudflap ncurses ncurses-libs ncurses-devel boost boost-devel libgsasl libgsasl-devel cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib jemalloc jemalloc-devel gperf gperftools-libs gperftools-devel systemtap-sdt-devel wget unzip openssl openssl-devel pcre pcre-devel zlib zlib-devel bzip2 bzip2-devel curl libcurl libcurl-devel libevent libevent-devel libgcrypt libgcrypt-devel libpng libpng-devel libjpeg-turbo libjpeg-turbo-devel openjpeg openjpeg-devel openjpeg-libs giflib giflib-devel giflib-utils gd gd-devel ImageMagick ImageMagick-devel ImageMagick-c++ ImageMagick-c++-devel GraphicsMagick GraphicsMagick-devel GraphicsMagick-c++ GraphicsMagick-c++-devel gettext gettext-devel freetype freetype-devel libtiff libtiff-devel libwebp libwebp-devel libwebp-tools libxml2 libxml2-devel libxslt libxslt-devel libuuid libmemcached libmemcached-devel libuuid-devel expat expat-devel expat21 expat21-devel --setopt=protected_multilib=false


2. 创建基本用户
if [ $USER != "root" ]; then su root; fi
useradd -d /home/work -p heiyeluren work

groupadd www && useradd -g www -d /home/www -s /sbin/nologin www


3. 创建基本目录
if [ $USER != "work" ]; then su work; fi
mkdir -p /home/work/lib
mkdir -p /home/work/soft
mkdir -p /home/work/logs
mkdir -p /home/work/www

## 说明:其他目录按照自己开发机需要再创建 ##


4. 设置环境使用指定lib目录
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/work/lib

echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/work/lib" >> ~/.bash_profile
echo "export LD_LIBRARY_PATH" >> ~/.bash_profile
source ~/.bash_profile


5. 下载相应软件
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft

## 注意:以下步骤如果该服务器不可用,可以直接按照上面软件列表的指令一个个下载 ##
if [ ! -f lnmp_soft_201603.tgz ]; then wget http://117.121.26.58/file/lnmp_soft_201603.tgz && tar zxvf lnmp_soft_201603.tgz && mv soft/* . && rm -r soft ; fi

# 统计下总共软件总数
cd /home/work/soft && ls -l | wc -l

#说明:如果最终统计出来是30多个则是都下载完整了 #

 

三、软件安装


1. MySQL 安装

############################
# 安装方式1: 使用yum安装
############################
if [ $USER != "root" ]; then su root; fi

# 创建运行mysql用户 (必须使用mysql用户)
groupadd mysql && useradd -g mysql -d /home/mysql -s /sbin/nologin mysql

# 通过yum安装包 (说明:rhel6.5/rhel7版本安装的mysql-server是5.1.x版, 应该跟mysql被oracle收购后yum源不再有新版本有关,如果需要新版本可以考虑 PerconaServer/MariaDB/FacebookMySQL/WebScaleSQL 等变种分支)
yum -y install mysql-server mysql-devel

# 构建数据库文件存储目录
mkdir -p /home/work/data/mysqldata
mkdir -p /var/run/mysqld
chown -R mysql /home/work/data/mysqldata
chgrp -R mysql /home/work/data/mysqldata
chown -R mysql /var/run/mysqld
chgrp -R mysql /var/run/mysqld
chmod 755 /home/work/data/mysqldata

# 修改基础配置文件 (说明:配置文件如果需要显示运行,还需要优化,目前配置只是可以运行)
cat > /etc/my.cnf << EOF
[mysqld]
port=3306
datadir=/home/work/data/mysqldata
socket=/var/run/mysqld/mysql.sock
user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
character-set-server=utf8mb4

log-error=/home/work/data/mysqldata/mysqld-err.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
socket=/var/run/mysqld/mysql.sock
default-character-set=utf8mb4

EOF


# 初始化数据库,加入到自启服务
chkconfig mysqld on
chkconfig --list mysqld

#启动 mysqld (本步骤会启动mysqld,如果my.cnf里设定的数据库目录为空,则同时会初始化相关数据库表等)
service mysqld start

# 修改root账户密码
mysqladmin -S /home/work/data/mysqldata/mysql.sock -uroot password 'heiyeluren'

# 创建其他账户, 自行操作
mysql -uroot -pheiyeluren -S /home/work/data/mysqldata/mysql.sock
mysql> grant all on 库名.* to 用户名@"%" identified by "密码";
mysql> flush privileges;

# 安装完成 #


## MySQL安装问题追查 ##

# 无法启动数据库的情况,可以直接裸启动试试
/usr/libexec/mysqld --skip-grant

# 初始化数据库表
/usr/bin/mysql_install_db


## MySQL基本参考命令 ##

# 用service命令启动mysqld
service mysqld start

# 用mysqld_safe脚本启动mysqld ,注意,不建议使用本方式启动,会导致可能 mysql.sock 文件无法正常生产,建议使用 service 命令启动mysqld #
/usr/bin/mysqld_safe --datadir=/home/work/data/mysqldata --socket=/home/work/data/mysqldata/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql --defaults-extra-file=/etc/my.cnf

# 用service 关闭mysqld
service mysqld stop

# 用mysqladmin 安全关闭mysqld ,注意,不建议使用本方式启动,可能会导致异常情况,建议使用 service 命令关闭mysqld#
/usr/bin/mysqladmin --socket=/home/work/data/mysqldata/mysql.sock --user=root -pheiyeluren shutdown

# 连接访问Mysql #
/usr/bin/mysql -hlocalhost -uroot -pheiyeluren --socket=/home/work/data/mysqldata/mysql.sock --port=3306


# 需要修改配置可以直接修改 /etc/my.cnf 配置文件 #


############################
# 安装方式2: 使用源码安装
# (推荐安装方式)
############################

说明:mysql server会直接运行在work账户上,同时所有安装操作都不需要root用户。

# 编译安装
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf mysql-5.6.29.tar.gz && cd mysql-5.6.29
cmake . -DCMAKE_INSTALL_PREFIX=/home/work/mysql
make && make install

# 生成配置文件和数据目录 (更多详细配置请参考相关mysql技术文档,实际线上业务按照实际需要配置来自行修改)
if [ $USER != "work" ]; then su work; fi
mkdir -p /home/work/mysql/data/test
rm -f /home/work/mysql/my.cnf
rm -f /home/work/mysql/my-new.cnf

## 注意:本配置文件my.cnf仅供使用参考,在本数据库实例中不生效(本配置文件是针对Master机器的配置,参考配置:http://geek.csdn.net/news/detail/41002) ##

cat > /home/work/mysql/my.cnf << EOF
[client]
default-character-set=utf8mb4
socket=/home/work/mysql/data/mysql.sock

[mysqld]
#***********************************common parameters******************************
port=3306
default-storage-engine=InnoDB
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
user=work
socket=/home/work/mysql/data/mysql.sock
pid-file=/home/work/mysql/data/mysqld.pid
autocommit=1
datadir=/home/work/mysql/data/
tmpdir=/home/work/mysql/data/

skip-name-resolve
skip_external_locking

group_concat_max_len=1048576
flush=OFF

lower_case_table_names=1
max_connections=3000
max_user_connections=2800
max_connect_errors=10
max_allowed_packet=64M

max_heap_table_size=512M
tmp_table_size=512M
max_length_for_sort_data=16k

wait_timeout=172800
interactive_timeout=172800

net_buffer_length=8K
read_buffer_size=4M
read_rnd_buffer_size=1M
sort_buffer_size=256K
join_buffer_size=2M
table_open_cache=512
thread_cache_size=512
query_cache_type=1
query_cache_size=256M
explicit_defaults_for_timestamp
#******************************* Logs related settings ***************************
log-error=/home/work/mysql/data/mysqld-err.log
long_query_time=2
slow_query_log
slow_query_log_file=/home/work/mysql/data/mysqld-slow.log
#log_queries_not_using_indexes
log_warnings
relay-log=/home/mysqldata/relaylog/mysql-relay-bin.index
relay-log=/home/mysqldata/relaylog/mysql-relay-bin
log-bin=/home/mysqldata/binlog/mysql-bin.index
log-bin=/home/mysqldata/binlog/mysql-bin
binlog_cache_size=8M
max_binlog_size=512M
binlog-format=MIXED
sync_binlog=1
expire_logs_days=10
key_buffer_size=128M

#******************************Replication Specific options **********************
server-id=9527
slave-skip-errors=1022,1032,1062
log_slave_updates=1
log_bin_trust_function_creators=1
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
replicate-ignore-db=mysql
replicate-ignore-db=information_schema
replicate-ignore-db=information_schema
auto_increment_increment=1
auto_increment_offset=1
skip-slave-start
#semi sync replication
#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000 # 1 second

#***************************** INNODB Specific options ****************************
innodb_file_per_table
innodb_open_files=7168
innodb_use_sys_malloc=1
innodb_additional_mem_pool_size=64M
innodb_buffer_pool_instances=4
innodb_buffer_pool_size=20G
innodb_data_home_dir=/home/work/mysql/data
innodb_data_file_path=ibdata1:1024M:autoextend
innodb_autoextend_increment=128
innodb_thread_concurrency=0
innodb_flush_log_at_trx_commit=1
innodb_fast_shutdown=1
innodb_force_recovery=0
innodb_log_buffer_size=16M
innodb_log_file_size=128M
innodb_log_files_in_group=4
innodb_log_group_home_dir=/home/work/mysql/data
innodb_max_dirty_pages_pct=60
innodb_purge_threads=0
innodb_lock_wait_timeout=50
innodb_rollback_on_timeout=1
innodb_commit_concurrency=0
innodb_concurrency_tickets=1024
innodb_autoinc_lock_mode=2
innodb_change_buffering=all

# innodb plugin
innodb_io_capacity=1000
innodb_read_io_threads=16
innodb_write_io_threads=8
innodb_file_format=Barracuda
innodb_file_format_check=1
#innodb_strict_mode=1
innodb_stats_on_metadata=0
#sql_mode
#sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_AUTO_VALUE_ON_ZERO

[mysqldump]
quick
max_allowed_packet=2G
default-character-set=utf8mb4

[mysql]
no-auto-rehash
prompt="\\u@\\h : \\d \\r:\\m:\\s> "
default-character-set=utf8mb4
show-warnings

[myisamchk]
key_buffer_size = 256K
sort_buffer_size = 256K
read_buffer = 256K
write_buffer = 256K

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
user=work
open-files-limit=8192
pid-file=/home/work/mysql/data/mysqld.pid

EOF

 

# 初始化数据库结构和权限
/home/work/mysql/scripts/mysql_install_db --datadir=/home/work/mysql/data --tmpdir=/home/work/mysql/data --user=work --basedir=/home/work/mysql --port=3306 --socket=/home/work/mysql/data/mysql.sock --pid-file=/home/work/mysql/data/mysqld.pid --log-error=/home/work/mysql/data/mysqld-err.log --server-id=9527 --skip-grant --innodb_data_home_dir=/home/work/mysql/data --innodb_data_file_path=ibdata1:1024M:autoextend --innodb_log_file_size=128M --innodb_log_files_in_group=4 --innodb_log_group_home_dir=/home/work/mysql/data --innodb_file_per_table=1

# 启动数据库 (直接给mysqld传递参数,不使用任何配置文件,mysql_start_dev.sh 脚本参考下面的生成程序)
sh /home/work/mysql/mysql_start_dev.sh

# 验证数据库是否正常启动
/home/work/mysql/bin/mysql -h127.0.0.1 -P3306 -uroot -pheiyeluren -e "select version();show databases;use mysql;show tables;desc db;"

# mysqladmin 修改root账户密码 #
/home/work/mysql/bin/mysql -h127.0.0.1 -P3306 -uroot -pheiyeluren -e "select Host,User,Password,plugin,authentication_string,password_expired from mysql.user;"
/home/work/mysql/bin/mysqladmin -u root -h 127.0.0.1 password 'heiyeluren'
/home/work/mysql/bin/mysql -uroot -pheiyeluren -h127.0.0.1 -P3306 -e "select Host,User,Password,plugin,authentication_string,password_expired from mysql.user;"

# sql修改所有root密码
/home/work/mysql/bin/mysql -uroot -pheiyeluren -h127.0.0.1 -P3306 -e "UPDATE mysql.user SET password=PASSWORD('heiyeluren') WHERE user='root'; flush privileges;"

 

## MySQL基本参考命令 ##

# 安全启动数据库 (默认会使用 /home/work/mysql/my.cnf 配置文件)
/home/work/mysql/bin/mysqld_safe --no-defaults --malloc-lib=/usr/lib64/libjemalloc.so --datadir=/home/work/mysql/data --tmpdir=/home/work/mysql/data --basedir=/home/work/mysql --log-error=/home/work/mysql/data/mysqld-err.log --socket=/home/work/mysql/data/mysql.sock --pid-file=/home/work/mysql/data/mysqld.pid --port=3306 --user=work --server-id=9527 &
ps auxx |grep mysqld

# 安全的关闭mysql #
/home/work/mysql/bin/mysqladmin -uroot -h127.0.0.1 -P3306 -p'heiyeluren' shutdown && sleep 3 && ps auxx |grep mysqld

# 创建业务使用的mysql账户(测试:创建一个针对test库所有表可以select/insert/update/delete/crate/drop权限的work账户,密码是heiyeluren)
/home/work/mysql/bin/mysql -uroot -pheiyeluren -h127.0.0.1 -P3306 -e " grant select,insert,update,delete,create,drop on test.* to work@'%' identified by 'heiyeluren'; flush privileges;"
# 查看创建结果
/home/work/mysql/bin/mysql -uroot -pheiyeluren -h127.0.0.1 -P3306 -e "select Host,User,Password,plugin,authentication_string,password_expired from mysql.user;"
/home/work/mysql/bin/mysql -uroot -pheiyeluren -h127.0.0.1 -P3306 -e "select Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv from mysql.db;"


### 生成启动mysql脚本 ###

#== 开发环境启动脚本
cat > /home/work/mysql/mysql_start_dev.sh << EOF
/home/work/mysql/bin/mysqld_safe --basedir=/home/work/mysql --datadir=/home/work/mysql/data --plugin-dir=/home/work/mysql/lib/plugin --default-storage-engine=InnoDB --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --autocommit=1 --tmpdir=/home/work/mysql/data --skip-name-resolve --skip-external-locking --group-concat-max-len=1048576 --flush=OFF --lower-case-table-names=1 --max-connections=3000 --max-user-connections=2800 --max-connect-errors=10 --max-allowed-packet=64M --max-heap-table-size=16M --tmp-table-size=16M --max-length-for-sort-data=16k --wait-timeout=172800 --interactive-timeout=172800 --net-buffer-length=8K --read-buffer-size=4M --read-rnd-buffer-size=1M --sort-buffer-size=256K --join-buffer-size=2M --table-open-cache=512 --thread-cache-size=512 --query-cache-type=1 --query-cache-size=8M --explicit-defaults-for-timestamp --long-query-time=2 --slow-query-log=1 --slow-query-log-file=/home/work/mysql/data/mysqld-slow.log --log-warnings=1 --relay-log=/home/work/mysql/data/mysql-relay-bin.index --relay-log=/home/work/mysql/data/mysql-relay-bin --log-bin=/home/work/mysql/data/mysql-bin.index --log-bin=/home/work/mysql/data/mysql-bin --binlog-cache-size=8M --max-binlog-size=512M --binlog-format=MIXED --sync-binlog=1 --expire-logs-days=10 --key-buffer-size=4M --server-id=9527 --slave-skip-errors=1022,1032,1062 --log-slave-updates=1 --log-bin-trust-function-creators=1 --binlog-ignore-db=mysql --binlog-ignore-db=information_schema --binlog-ignore-db=performance_schema --replicate-ignore-db=mysql --replicate-ignore-db=information_schema --replicate-ignore-db=information_schema --auto-increment-increment=1 --auto-increment-offset=1 --skip-slave-start --innodb-file-per-table=1 --innodb-open-files=7168 --innodb-use-sys-malloc=1 --innodb-additional-mem-pool-size=2M --innodb-buffer-pool-instances=4 --innodb-buffer-pool-size=640M --innodb-data-home-dir=/home/work/mysql/data --innodb-data-file-path=ibdata1:1024M:autoextend --innodb-autoextend-increment=128 --innodb-thread-concurrency=0 --innodb-flush-log-at-trx-commit=1 --innodb-fast-shutdown=1 --innodb-force-recovery=0 --innodb-log-buffer-size=16M --innodb-log-file-size=128M --innodb-log-files-in-group=4 --innodb-log-group-home-dir=/home/work/mysql/data --innodb-max-dirty-pages-pct=60 --innodb-purge-threads=0 --innodb-lock-wait-timeout=50 --innodb-rollback-on-timeout=1 --innodb-commit-concurrency=0 --innodb-concurrency-tickets=1024 --innodb-autoinc-lock-mode=2 --innodb-change-buffering=all --innodb-io-capacity=1000 --innodb-read-io-threads=16 --innodb-write-io-threads=8 --innodb-file-format=Barracuda --innodb-file-format-check=1 --innodb-stats-on-metadata=0 --log-error=/home/work/mysql/data/mysqld-err.log --pid-file=/home/work/mysql/data/mysqld.pid --socket=/home/work/mysql/data/mysql.sock --port=3306 &

EOF
chmod +x /home/work/mysql/mysql_start_dev.sh

#== 线上环境配置
cat > /home/work/mysql/mysql_start_online.sh << EOF
/home/work/mysql/bin/mysqld_safe --basedir=/home/work/mysql --datadir=/home/work/mysql/data --plugin-dir=/home/work/mysql/lib/plugin --default-storage-engine=InnoDB --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --autocommit=1 --tmpdir=/home/work/mysql/data --skip-name-resolve --skip-external-locking --group-concat-max-len=1048576 --flush=OFF --lower-case-table-names=1 --max-connections=3000 --max-user-connections=2800 --max-connect-errors=10 --max-allowed-packet=64M --max-heap-table-size=512M --tmp-table-size=512M --max-length-for-sort-data=16k --wait-timeout=172800 --interactive-timeout=172800 --net-buffer-length=8K --read-buffer-size=4M --read-rnd-buffer-size=1M --sort-buffer-size=256K --join-buffer-size=2M --table-open-cache=512 --thread-cache-size=512 --query-cache-type=1 --query-cache-size=256M --explicit-defaults-for-timestamp --long-query-time=2 --slow-query-log=1 --slow-query-log-file=/home/work/mysql/data/mysqld-slow.log --log-warnings=1 --relay-log=/home/work/mysql/data/mysql-relay-bin.index --relay-log=/home/work/mysql/data/mysql-relay-bin --log-bin=/home/work/mysql/data/mysql-bin.index --log-bin=/home/work/mysql/data/mysql-bin --binlog-cache-size=8M --max-binlog-size=512M --binlog-format=MIXED --sync-binlog=1 --expire-logs-days=10 --key-buffer-size=128M --server-id=9527 --slave-skip-errors=1022,1032,1062 --log-slave-updates=1 --log-bin-trust-function-creators=1 --binlog-ignore-db=mysql --binlog-ignore-db=information_schema --binlog-ignore-db=performance_schema --replicate-ignore-db=mysql --replicate-ignore-db=information_schema --replicate-ignore-db=information_schema --auto-increment-increment=1 --auto-increment-offset=1 --skip-slave-start --innodb-file-per-table=1 --innodb-open-files=7168 --innodb-use-sys-malloc=1 --innodb-additional-mem-pool-size=64M --innodb-buffer-pool-instances=4 --innodb-buffer-pool-size=20G --innodb-data-home-dir=/home/work/mysql/data --innodb-data-file-path=ibdata1:1024M:autoextend --innodb-autoextend-increment=128 --innodb-thread-concurrency=0 --innodb-flush-log-at-trx-commit=1 --innodb-fast-shutdown=1 --innodb-force-recovery=0 --innodb-log-buffer-size=16M --innodb-log-file-size=128M --innodb-log-files-in-group=4 --innodb-log-group-home-dir=/home/work/mysql/data --innodb-max-dirty-pages-pct=60 --innodb-purge-threads=0 --innodb-lock-wait-timeout=50 --innodb-rollback-on-timeout=1 --innodb-commit-concurrency=0 --innodb-concurrency-tickets=1024 --innodb-autoinc-lock-mode=2 --innodb-change-buffering=all --innodb-io-capacity=1000 --innodb-read-io-threads=16 --innodb-write-io-threads=8 --innodb-file-format=Barracuda --innodb-file-format-check=1 --innodb-stats-on-metadata=0 --log-error=/home/work/mysql/data/mysqld-err.log --pid-file=/home/work/mysql/data/mysqld.pid --socket=/home/work/mysql/data/mysql.sock --port=3306 &

EOF
chmod +x /home/work/mysql/mysql_start_online.sh

#== 关闭数据库脚本
cat > /home/work/mysql/mysql_stop.sh << EOF
/home/work/mysql/bin/mysqladmin -uroot -h127.0.0.1 -P3306 -p'heiyeluren' shutdown && sleep 3 && ps auxx |grep mysqld

EOF
chmod +x /home/work/mysql/mysql_stop.sh

#== 连接mysql脚本
cat > /home/work/mysql/mysql_conn.sh << EOF
/home/work/mysql/bin/mysql -uroot -h127.0.0.1 -P3306 -p'heiyeluren'

EOF
chmod +x /home/work/mysql/mysql_conn.sh

 

## MySQL安装问题追查 ##

# 无法启动数据库的情况,可以直接裸启动试试
/home/work/mysql/bin/mysqld_safe --no-defaults --datadir=/home/work/mysql/data --port=3306 --socket=mysql.sock --server-id=1 --tmpdir=/home/work/mysql/data --user=mysql --basedir=/home/work/mysql --skip-grant

 

2. Memcached 安装

if [ $USER != "work" ]; then su work; fi

#创建基本目录
mkdir -p /home/work/memcached/var

# 安装memcached
cd /home/work/soft
tar zxvf memcached-1.4.25.tar.gz
cd memcached-1.4.25
./configure --prefix=/home/work/memcached --with-libevent=/usr --enable-64bit --enable-dtrace
make && make install

# 启动memcached (在11211端口,占用64M内存,允许102400个最大连接等)
/home/work/memcached/bin/memcached -p 11211 -m 64M -c 102400 -b 10240 -P /home/work/memcached/var/memcached.pid -f 1.25 -d

# 查看测试启动效果
ps auxx |grep memcached
telnet 127.0.0.1 11211
# 在memcached终端下面输入:stats,输出结果说明正常


3. Redis 安装

if [ $USER != "work" ]; then su work; fi

# 编译redis
cd /home/work/soft
tar zxvf redis-2.8.24.tar.gz
cd redis-2.8.24
make

# 安装redis
mkdir -p /home/work/redis/conf && mkdir -p /home/work/redis/bin && mkdir -p /home/work/redis/data && mkdir -p /home/work/redis/log && mkdir -p /home/work/redis/var
cd /home/work/soft/redis-2.8.24
cp redis.conf /home/work/redis/conf
cd /home/work/soft/redis-2.8.24/src
cp mkreleasehdr.sh /home/work/redis/bin/ && cp redis-benchmark /home/work/redis/bin/ && cp redis-check-aof /home/work/redis/bin/
cp redis-check-dump /home/work/redis/bin/ && cp redis-cli /home/work/redis/bin/ && cp redis-sentinel /home/work/redis/bin/ && cp redis-server /home/work/redis/bin/

# 启动Redis服务
/home/work/redis/bin/redis-server /home/work/redis/conf/redis.conf &
ps auxx |grep redis

# 检查启动情况
/home/work/redis/bin/redis-cli -h 127.0.0.1 -p 6379
# 在终端下面输入:
127.0.0.1:6379> set name heiyeluren
127.0.0.1:6379> get name
127.0.0.1:6379> quit

# 关闭redis
/home/work/redis/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown && sleep 1 && ps auxx |grep redis

 

4. Coreseek/Sphinx 安装

# 安装基础支持工具 autoconf 2.64 版
if [ $USER != "root" ]; then su root; fi
cd /home/work/soft
tar xf autoconf-2.64.tar.bz2
cd autoconf-2.64
./configure
make && make install

# 安装libmysqlclient支持
## 注意yum中的libmysqlient 是 mysql5.1版本的,为了稳妥起见,可能5.1版本会无法访问高版本mysql的情况。(不确定,知悉本问题)
if [ $USER != "root" ]; then su root; fi
yum -y install mysql++ mysql++-devel mysql-libs mysql-devel

# 安装libmmseg
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf coreseek-4.1-beta.tar.gz
cd coreseek-4.1-beta/mmseg-3.2.14

##说明:初始化操作,解决 "config.status: error: cannot find input file: src/Makefile.in" 的问题
aclocal && libtoolize --force && automake --add-missing && autoconf && autoheader && make clean
./configure --prefix=/home/work/lib/mmseg
make && make install

# 安装csft
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft/coreseek-4.1-beta/csft-4.1
sh buildconf.sh
./configure --prefix=/home/work/coreseek --without-unixodbc --with-mmseg --with-mmseg-includes=/home/work/lib/mmseg/include/mmseg --with-mmseg-libs=/home/work/lib/mmseg/lib --with-mysql
make && make install

# 测试mmseg安装结果
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft/coreseek-4.1-beta/testpack
cat var/test/test.xml
/home/work/lib/bin/mmseg -d /home/work/lib/etc/ var/test/test.xml

# 测试sphinx安装结果
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft/coreseek-4.1-beta/testpack
/home/work/coreseek/bin/indexer -c etc/csft.conf --all
/home/work/coreseek/bin/search -c etc/csft.conf

 

#====== Coreseek/Sphinx 基本操作命令 =======

# 搜索增量索引
#/alidata/server/coreseek/bin/indexer -c /alidata/server/coreseek/etc/csft.conf delta_subject delta_subject_floor --rotate;
/alidata/server/coreseek/bin/indexer delta_subject delta_subject_floor --rotate --config /alidata/server/coreseek/etc/csft.conf;

# 合并增量索引
/alidata/server/coreseek/bin/indexer -c /alidata/server/coreseek/etc/csft.conf --merge subject delta_subject --rotate --merge-dst-range deleted 0 0;
/alidata/server/coreseek/bin/indexer -c /alidata/server/coreseek/etc/csft.conf --merge subject_floor delta_subject_floor --rotate --merge-dst-range deleted 0 0;

 

 

5. Nginx 安装

#创建相应目录
if [ $USER != "work" ]; then su work; fi
mkdir -p /home/work/nginx/sbin && mkdir -p /home/work/nginx/conf && mkdir -p /home/work/nginx/var && mkdir -p /home/work/nginx/logs

# 解压OpenResty
cd /home/work/soft
tar zxvf openresty-1.9.7.4.tar.gz

# 配置编译安装
cd openresty-1.9.7.4
./configure --prefix=/home/work/nginx --sbin-path=/home/work/nginx/sbin/nginx --conf-path=/home/work/nginx/conf/nginx.conf --pid-path=/home/work/nginx/var/nginx.pid --lock-path=/home/work/nginx/var/nginx.lock --error-log-path=/home/work/nginx/logs/error.log --http-log-path=/home/work/nginx/logs/access.log
make && make install
cd /home/work/nginx && mv *.default conf/ && mv fastcgi* conf/ && mv koi* conf/ && mv mime* conf/ && mv scgi_params* conf/ && mv uwsgi_params* conf/ && mv win* conf/

# 测试启动 (必须root账户启动)
if [ $USER != "root" ]; then su root; fi
/home/work/nginx/sbin/nginx && sleep 1 && ps auxx | grep nginx

## 说明:完成,记得修改 /home/work/nginx/conf/nginx.conf 配置文件,按照自己需要来部署虚拟机等,线上环境可以采用最后我们指定的配置 ##

 

6. PHP 安装

(1) 初始化环境
if [ $USER != "root" ]; then su root; fi
## 如果没有执行上面的初始化环境的yum install基础软件操作,在这里务必记得操作一下 ##

(2) 编译必须的基础库,除了上面已初始化好的lib
if [ $USER != "work" ]; then su work; fi

#
# 安装 libmysqlclient.so 支持
#
cd /home/work/soft
tar zxvf mysql-5.6.29.tar.gz && cd mysql-5.6.29
cmake . -DCMAKE_INSTALL_PREFIX=/home/work/lib/mysql
# 或者使用cmake的方式 : cmake . && ./configure --prefix=/home/work/lib/mysql
make && make install

#
# 安装 libmcrypt 和 mhash 库
#
cd /home/work/soft
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

#
# 安装jpeg/gif/png/webp/ImageMagick/GraphicsMagick等图片处理支持
#
cd /home/work/soft
tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf libjpeg-turbo-1.4.2.tar.gz
cd libjpeg-turbo-1.4.2
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf libpng-1.6.21.tar.gz
cd libpng-1.6.21
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf giflib-5.1.3.tar.gz
cd giflib-5.1.3
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf libwebp-0.5.0.tar.gz
cd libwebp-0.5.0
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf ImageMagick-6.9.3-7.tar.gz
cd ImageMagick-6.9.3-7
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

cd /home/work/soft
tar zxvf GraphicsMagick-1.3.22.tar.gz
cd GraphicsMagick-1.3.22
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install


#
# 安装libmemcached支持
#
cd /home/work/soft
tar zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure --prefix=/home/work/lib/ --enable-shared --enable-static
make && make install

#
# 安装libgearmanclient支持
#
cd /home/work/soft
tar zxvf gearmand-1.1.12.tar.gz
cd gearmand-1.1.12
./configure --prefix=/home/work/lib/gearman --enable-jobserver=no --enable-shared --enable-static
make && make install


#
# 安装librdkafka支持
#
## 注意:因为扩展依赖原因,本软件需要使用root权限,并且库不会安装在 /home/work/lib 下,只会安装在 /usr/local 下 ##
if [ $USER != "root" ]; then su root; fi
cd /home/work/soft
unzip -o librdkafka-0.9.0.zip
cd librdkafka-0.9.0
./configure --prefix=/usr --libdir=/usr/lib64
make && make install

#
# 安装libsphinxclient支持
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf sphinx-2.0.2-beta.tar.gz
cd sphinx-2.0.2-beta/api/libsphinxclient
sed -i 's/void sock_close ( int sock );/static void sock_close ( int sock );/g' sphinxclient.c
./configure --prefix=/home/work/lib/sphinxclient --enable-static --enable-shared
make && make install


(3) 安装PHP

#
# 编译PHP引擎
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft

tar zxvf php-5.6.20.tar.gz
cd php-5.6.20
./configure --prefix=/home/work/php --with-config-file-path=/home/work/php/etc/ --with-libxml-dir=/home/work/lib --with-mysql=/home/work/lib/mysql --with-mysqli=/home/work/lib/mysql/bin/mysql_config --with-pdo-mysql=/home/work/lib/mysql --with-jpeg-dir=/home/work/lib --with-png-dir=/usr/lib64 --with-freetype-dir --with-mhash=/home/work/lib --with-mcrypt=/home/work/lib --with-openssl --with-gd --enable-gd-native-ttf --with-gettext --with-zlib --with-pcre-regex --with-xmlrpc --with-xsl --with-iconv --with-zlib --with-bz2 --with-gmp --with-curl --enable-mbstring --enable-mbregex --enable-exif --enable-shmop --enable-soap --enable-sockets --enable-wddx --enable-zip --enable-calendar --enable-ftp --enable-xml --enable-mysqlnd --enable-bcmath --enable-sysvsem --enable-sysvmsg --enable-sysvshm --enable-pcntl --enable-inline-optimization --enable-fpm --with-fpm-user=work --with-fpm-group=work --enable-opcache --enable-session --enable-shared --enable-static
make && make install

#
# 配置&测试是否可以运行
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
cd php-5.6.20
cp php.ini-production /home/work/php/etc/php.ini
cd /home/work/php/etc && mv php-fpm.conf.default php-fpm.conf
echo " " >> /home/work/php/etc/php.ini
chown -R work /home/work/php/etc/php.ini
chown -R work /home/work/php/etc/php-fpm.conf
chown -R work /home/work/php/etc/pear.conf

if [ $USER != "root" ]; then su root; fi
/home/work/php/sbin/php-fpm && sleep 1 && ps auxx |grep php-fpm

 


#
# 安装Redis扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf redis-2.2.7.tgz
cd redis-2.2.7
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo "[redis]" >> /home/work/php/etc/php.ini
echo "extension=redis.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装ImageMagick扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf imagick-3.4.1.tgz
cd imagick-3.4.1
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[imagick]" >> /home/work/php/etc/php.ini
echo ";extension=imagick.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装GraphicsMagick扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf gmagick-1.1.7RC3.tgz
cd gmagick-1.1.7RC3
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[gmagick]" >> /home/work/php/etc/php.ini
echo ";extension=gmagick.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装Memcached扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf memcached-2.2.0.tgz
cd memcached-2.2.0
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config --with-libmemcached-dir=/home/work/lib
make && make install

echo ";[memcached]" >> /home/work/php/etc/php.ini
echo ";extension=memcached.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini

#
# 安装memcache扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo "[memcache]" >> /home/work/php/etc/php.ini
echo "extension=memcache.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装MongoDB扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf mongo-1.6.13.tgz
cd mongo-1.6.13
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo "[mongo]" >> /home/work/php/etc/php.ini
echo "extension=mongo.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini

 

#
# 安装Shpinx扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf sphinx-1.3.3.tgz
cd sphinx-1.3.3
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config --with-sphinx=/home/work/lib/sphinxclient
make && make install

echo "[sphinx]" >> /home/work/php/etc/php.ini
echo "extension=sphinx.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini

#
# 安装Gearman扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf gearman-1.1.2.tgz
cd gearman-1.1.2
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config --with-gearman=/home/work/lib/gearman/
make && make install

echo ";[gearman]" >> /home/work/php/etc/php.ini
echo ";extension=gearman.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装Kafka扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
unzip -o phpkafka-master.zip
cd phpkafka-master
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[kafka]" >> /home/work/php/etc/php.ini
echo ";extension=kafka.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装SeasLog扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf SeasLog-1.5.0.tgz
cd SeasLog-1.5.0
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[seaslog]" >> /home/work/php/etc/php.ini
echo ";extension=seaslog.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini

#
# 安装MsgPack扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf msgpack-0.5.7.tgz
cd msgpack-0.5.7
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[msgpack]" >> /home/work/php/etc/php.ini
echo ";extension=msgpack.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装Protobuf扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
unzip -o php-protobuf-master.zip
cd php-protobuf-master
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[protobuf]" >> /home/work/php/etc/php.ini
echo ";extension=protobuf.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装Phalcon扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
unzip -o phalcon-v2.0.3.zip
cd cphalcon-phalcon-v2.0.3/build/64bits/
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config --enable-phalcon
make && make install

echo ";[phalcon]" >> /home/work/php/etc/php.ini
echo ";extension=phalcon.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装Swoole扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf swoole-1.8.3.tgz
cd swoole-1.8.3
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo ";[swoole]" >> /home/work/php/etc/php.ini
echo ";extension=swoole.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


#
# 安装Yaf扩展
#
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
tar zxvf yaf-2.3.5.tgz
cd yaf-2.3.5
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo "[yaf]" >> /home/work/php/etc/php.ini
echo "extension=yaf.so" >> /home/work/php/etc/php.ini
echo "yaf.environ=develop" >> /home/work/php/etc/php.ini
echo "yaf.use_namespace=1" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini

 


四、覆盖成为正式配置

# 下载正式配置
if [ $USER != "work" ]; then su work; fi
cd /home/work/soft
rm -f php-fpm.conf && wget http://117.121.26.58/file/php-fpm.conf.xh.v1.0 && mv php-fpm.conf.xh.v1.0 php-fpm.conf
rm -f php.ini.v1.2 && rm -f php.ini && wget http://117.121.26.58/file/php.ini.v1.3 && mv php.ini.v1.3 php.ini
rm -f nginx.conf && wget http://117.121.26.58/file/nginx.conf.xh.v1.0 && mv nginx.conf.xh.v1.0 nginx.conf
rm -rf redis.conf && wget http://117.121.26.58/file/redis.conf.xh.v1.0 && mv redis.conf.xh.v1.0 redis.conf

## 如果配置文件是老路径,使用以下命令替换下,如果是新的忽略 ##
# sed -i 's/\/usr\/local\/openresty\//\/home\/work\//g' nginx.conf
# sed -i 's/\/home\/openresty\/1.7.4.1\/web\//\/home\/work\/nginx\//g' nginx.conf
# sed -i 's/\/home\/web\//\/home\/work\/www\//g' nginx.conf
# sed -i 's/\/home\/web\/run_logs\//home\/work\/php\/var\/log\//g' php-fpm.conf

 

# 覆盖配置
mkdir -p /home/work/logs
cd /home/work/soft
cp php-fpm.conf /home/work/php/etc/php-fpm.conf.new
cp php.ini /home/work/php/etc/php.ini.new
cp nginx.conf /home/work/nginx/conf/nginx.conf.new
cp redis.conf /home/work/redis/conf/redis.conf.new
cd /home/work/php/etc/; cp php-fpm.conf php-fpm.conf.old; mv php-fpm.conf.new php-fpm.conf
cd /home/work/php/etc/; cp php.ini php.ini.old; mv php.ini.new php.ini
cd /home/work/nginx/conf; cp nginx.conf nginx.conf.old; mv nginx.conf.new nginx.conf
cd /home/work/redis/conf; cp redis.conf redis.conf.old; mv redis.conf.new redis.conf

## 配置覆盖后,请自行重新启动服务 ##

## 注意: 到了本步骤,建议重新review检查修改自己想要的配置选项,为了规范,关于路径等配置不建议修改 ##

# 启动LNP服务
if [ $USER != "root" ]; then su root; fi
pkill nginx && pkill php-fpm && sleep 1 && ps auxx |grep php-fpm && ps auxx |grep nginx
/home/work/php/sbin/php-fpm && sleep 1 && ps auxx |grep php-fpm
/home/work/nginx/sbin/nginx && sleep 1 && ps auxx |grep nginx

# 启动Redis服务
if [ $USER != "work" ]; then su work; fi
/home/work/redis/bin/redis-cli shutdown ; ps auxx | grep redis && /home/work/redis/bin/redis-server /home/work/redis/conf/redis.conf &
ps aux |grep redis

# 启动MySQL服务
## 参考上面的启动脚本 ##


五、部署PHP代码

代码目录:
线上环境:/home/work/www

线下开发测试环境:/home/用户名字/www/

代码部署完成后,在nginx设置好主机指向:
Nginx配置文件:/home/work/nginx/conf/nginx.conf

修改类似酱紫配置:

#------------------------------------------------------------

server {
server_name xiehualiang.api.xiangha.com;
listen 80;
listen 81;
root /home/xiehualiang/www/api.xiangha.com;

if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
access_log /home/xiehualiang/log/xiehualiang_access.log access;

location / {
index index.php index.html index.htm;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /home/work/nginx/conf/fastcgi_params;

}
location ~* .(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ {
expires 1d;
}
location ~* .(js|css)$ {
expires 1h;
}
location ~ /\.ht {
deny all;
}
location /log/ {
deny all;
}
error_page 400 401 402 403 404 /40x.html;
error_page 500 502 503 504 /50x.html;

}
#------------------------------------------------------------

修改完成后保存,重启nginx:
if [ $USER != "root" ]; then su root; fi
/home/work/nginx/sbin/nginx -s reload

 

六、其他

(一)如何安装一个单独扩展给PHP

假设是安装MongoDB扩展为例子:

1. 下载编译安装扩展
#
# 安装MongoDB扩展
#
cd ~
rm -f mongo-1.6.13.tgz && wget http://pecl.php.net/get/mongo-1.6.13.tgz
tar zxvf mongo-1.6.13.tgz
cd mongo-1.6.13
/home/work/php/bin/phpize
./configure --with-php-config=/home/work/php/bin/php-config
make && make install

echo "[mongo]" >> /home/work/php/etc/php.ini
echo "extension=mongo.so" >> /home/work/php/etc/php.ini
echo " " >> /home/work/php/etc/php.ini


2. 重启 php-fpm
sudo pkill php-fpm && sudo /home/work/php/sbin/php-fpm


3. 检查是否安装成功
/home/work/php/bin/php -m | grep mongo
/home/work/php/bin/php -i | grep mongo

 

转载于:https://www.cnblogs.com/dasn/articles/5836837.html

你可能感兴趣的:(转:lnmp 搭建手册-黑一路人)