CentOS7 LNMP安装

1. LNMP编译安装

1.1. 安装依赖包

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel e2fsprogs e2fsprogs-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers python-devel libicu-devel chrpath nspr-devel readline-devel ncurses-devel boost boost-devel pcre-devel js-devel git tcsh js js-devel libevent libevent-devel subversion git-core tcsh tcl net-snmp net-snmp-devel net-snmp-utils cmake postgresql-devel libxslt-devel

1.2. Nginx 1.11.13

1.2.1. 下载Nginx

wget http://nginx.org/download/nginx-1.11.13.tar.gz

1.2.2. 添加www用户组

/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www

1.2.3. 建立安装目录

mkdir -p /usr/local/webserver/nginx

1.2.4. 编译安装

./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre
make && make install

1.2.5. 修改Nginx配置文件

vi /usr/local/webserver/nginx/conf/fastcgi_params
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

vi /usr/local/webserver/nginx/conf/nginx.conf
worker_processes  4;
events {
    use epoll;
    worker_connections  8192;
}
gzip  on;

1.2.6. 添加service

vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/webserver/nginx/logs/nginx.pid
# config: /usr/local/webserver/nginx/conf/nginx.conf
nginxd=/usr/local/webserver/nginx/sbin/nginx
nginx_config=/usr/local/webserver/nginx/conf/nginx.conf
nginx_pid=/usr/local/webserver/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL
chmod a+x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx --level 2345 on

1.3. Mysql 5.7

1.3.1. 下载Mysql

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17.tar.gz

1.3.2. 创建mysql用户组

/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql

1.3.3. 创建目录

mkdir -p /usr/local/webserver/mysql

1.3.4. 编译安装

MYSQL5.7之后需要依赖Boost的C++扩展,而且只能是1.59.0版本,可以使用-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost自动下载Boost

或者wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz下载后解压到/usr/local/boost去掉-DDOWNLOAD_BOOST=1

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql -DMYSQL_UNIX_ADDR=/usr/local/webserver/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk,gb2312 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/webserver/mysql/data -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

make && make install

chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cp support-files/my-default.cnf /etc/my.cnf
chown mysql:mysql /etc/my.cnf
cp /usr/local/webserver/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld 
chkconfig --level 345 mysqld on

1.3.5. 修改my.conf

vi /etc/my.conf
innodb_buffer_pool_size = 128M
basedir=/usr/local/webserver/mysql
datadir=/usr/local/webserver/mysql/data
port = 3306
server_id = 1
socket = /usr/local/webserver/mysql/mysql.sock

1.3.6. 初始化库文件

MySQL5.7.6之后使用-initialize初始化bin/mysqld --initialize --user=mysql

MySQL5.7.6之前只用mysql_install_db初始化script/mysql_install_db --user=mysql

/usr/local/webserver/mysql/bin/mysqld --initialize --user=mysql

记下最后的密码

1.3.7. 启动mysql

service mysqld start

1.3.8. 修改密码

/usr/local/webserver/mysql/bin/mysql -uroot -p

输入初始化时的密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

1.4. PHP 5.6

1.4.1. 下载PHP5.6

wget http://cn.php.net/distributions/php-5.6.30.tar.gz

1.4.2. 安装依赖

1.4.2.1. libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install

若遇到gets undeclared则注释掉warning

vi srclib/stdio.in.h
//_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");

1.4.2.2. libmcrypt

wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz

tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install

1.4.2.3. mhash

wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install

1.4.2.4. 链接库文件

ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
ln -s /usr/local/webserver/mysql/lib/libmysqlclient.so.20 /usr/lib64/

echo /usr/local/webserver/mysql/lib >> /etc/ld.so.conf.d/mysql-x86_64.conf 
ldconfig -v

1.4.2.5. mcrypt

wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install

1.4.3. 创建目录

mkdir -p /usr/local/webserver/php 
mkdir -p /usr/local/webserver/php/etc

1.4.4. 编译安装

./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-iconv-dir=/usr/local/libiconv --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo-sqlite --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-xmlreader --enable-xmlwriter --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/mysql/bin/mysql_config --with-mysql-sock --enable-mysqlnd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --enable-ftp --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www

make && make install

1.4.5. 修改php.ini

cp php.ini-production /usr/local/webserver/php/etc/php.ini

vi /usr/local/webserver/php/etc/php.ini
date.timezone = "Asia/shanghai"
extension_dir = "/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20131226/"

1.4.6. 配置服务

cp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf
mkdir /usr/local/webserver/php/log
vi /usr/local/webserver/php/etc/php-fpm.conf
pid = run/php-fpm.pid
listen = /tmp/php-cgi.sock
pm = static
pm.max_children = 200
pm.max_requests = 2000
request_slowlog_timeout = 3
slowlog = log/$pool.log.slow
listen.owner = www
listen.group = www


cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 2345  php-fpm on

使用unix-sock或者listen-9000端口, sock更稳定

1.4.7. 安装扩展

1.4.7.1. imagick

yum install ImageMagick-devel -y
wget http://pecl.php.net/get/imagick-3.4.3.tgz

tar zxvf imagick-3.4.3.tgz
cd imagick-3.4.3/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make && make install

vi /usr/local/webserver/php/etc/php.ini
extension=imagick.so
service php-fpm restart

1.4.7.2. mongodb

wget http://pecl.php.net/get/mongodb-1.2.8.tgz

tar zxvf mongodb-1.2.8.tgz
cd mongodb-1.2.8
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make && make install

vi /usr/local/webserver/php/etc/php.ini
extension=mongodb.so
service php-fpm restart

1.4.7.3. redis

wget http://pecl.php.net/get/redis-3.1.2.tgz

tar zxvf redis-3.1.2.tgz
cd redis-3.1.2
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make && make install

vi /usr/local/webserver/php/etc/php.ini
extension=redis.so
service php-fpm restart

1.5. 整合Nginx+PHP

1.5.1. 修改nginx配置文件

vi /usr/local/webserver/nginx/conf/nginx.conf

include vhost/*.conf;

mkdir /usr/local/webserver/nginx/conf/vhost

vi /usr/local/webserver/nginx/conf/vhost/local.conf
server {
    listen       80 default_server;
    server_name  _;
    root   /home/www/local;
    index  index.html index.htm index.php;
    charset utf-8;
    error_page   500 502 503 504  /50x.html;
    
    location ~ \.php$ {
        fastcgi_pass unix:/tmp/php-cgi.sock;
        fastcgi_index  statistic.php;
        include        fastcgi_params;
    }
}

service nginx restart
mkdir -p /home/www/local
vi /home/www/local/phpinfo.php

<?php
phpinfo();
?>

访问http://your_ip/phpinfo.php

1.6. MongoDB安装

由于各种的问题,编译V8比较困难,所以直接下载二进制包

1.6.1. 下载MongoDB

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.2.tgz

1.6.2. 解压安装

tar zxvf mongodb-linux-x86_64-3.4.2.tgz
mv mongodb-linux-x86_64-3.4.2 /usr/local/webserver/mongodb

1.6.3. 添加配置文件

mkdir /usr/local/webserver/mongodb/etc
mkdir /usr/local/webserver/mongodb/data
vi /usr/local/webserver/mongodb/etc/mongo.conf
systemLog:
    destination: file
    path: "/usr/local/webserver/mongodb/mongodb.log"
    logAppend: true
storage:
    dbPath: "/usr/local/webserver/mongodb/data"
    repairPath: "/usr/local/webserver/mongodb/data/repair"
    engine: mmapv1
    journal: 
        enabled: true
    directoryPerDB: true
    mmapv1:
        nsSize: 16
        quota:
            enforced: true
            maxFilesPerDB: 1024
processManagement:
    fork: true
    pidFilePath: "/usr/local/webserver/mongodb/mongodb.pid"
net:
    bindIp: 127.0.0.1
    port: 27017
security:
    authorization: disabled
/usr/local/webserver/mongodb/bin/mongod -f /usr/local/webserver/mongodb/etc/mongo.conf

/usr/local/webserver/mongodb/bin/mongo
use admin
db.createUser(
{
    user: "admin",
    pwd: "hemengze",
    roles:
    [
      {
        role: "root",
        db: "admin"
      }
    ]
  }
)

1.6.4. 启用认证

/usr/local/webserver/mongodb/bin/mongod -shutdown -f /usr/local/webserver/mongodb/etc/mongo.conf

vi /usr/local/webserver/mongodb/etc/mongo.conf
authorization: enabled

/usr/local/webserver/mongodb/bin/mongod -f /usr/local/webserver/mongodb/etc/mongo.conf

1.6.5. 配置服务

vi /etc/init.d/mongo
#!/bin/bash
# mongo Startup script for the Mongodb Database Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Mongodb is a high-performance Database server.
# processname: mongo
# pidfile: /usr/local/webserver/mongodb/mongodb.pid
# config: /usr/local/webserver/mongodb/etc/mongo.conf
mongod=/usr/local/webserver/mongodb/bin/mongod
mongo_config=/usr/local/webserver/mongodb/etc/mongo.conf
mongo_pid=/usr/local/webserver/mongodb/mongodb.pid
RETVAL=0
prog="mongo"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $mongod ] || exit 0
# Start mongo daemons functions.
start() {
if [ -e $mongo_pid ];then
   echo "${prog} already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $mongod -f ${mongo_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/mongo
   return $RETVAL
}
# Stop mongo daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        $mongod -shutdown -f ${mongo_config}
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/mongo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|status|help}"
        exit 1
esac
exit $RETVAL
chmod +x /etc/init.d/mongo
chkconfig --add mongo
chkconfig --level 2345 mongo on
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342

推荐阅读更多精彩内容