一个80后
程序员的笔记

[Centos]安装LNMP服务器

1、安装支持扩展(根据自己需求决定安装哪些扩展)

1.1、安装Autoconf

#下载地址:http://mirrors.kernel.org/gnu/autoconf/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf autoconf-2.69.tar.gz
cd autoconf-2.69/
./configure --prefix=/usr/local/autoconf-2.69
#如果遇见报错*** [autoconf.in] Error
#是因为perl的问题,yum groupinstall perl*
make && make install
ln -s /usr/local/autoconf-2.69/ /usr/local/autoconf
rm -rf autoconf-2.69/

1.2、安装libiconv(PHP必须)

#下载地址:http://www.gnu.org/software/libiconv/#downloading
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf libiconv-1.15.tar.gz
cd libiconv-1.15
./configure --prefix=/usr/local/libiconv-1.15 --enable-static
make && make install
ln -sf /usr/local/libiconv-1.15/ /usr/local/libiconv
ln -sf /usr/local/libiconv/lib/libiconv.so.2 /usr/lib/libiconv.so.2
ln -sf /usr/local/libiconv/lib/libiconv.so /usr/lib/libiconv.so
ldconfig
rm -rf libiconv-1.15

1.3、安装libmcrypt

#下载地址:https://sourceforge.net/projects/mcrypt/files/Libmcrypt/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
New  ./configure --prefix=/usr/local/libmcrypt-2.5.8
#如果遇见报错:configure: error: C++ compiler cannot create executables
#是因为gcc-c++,yum install gcc-c++
make && make install
ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
New  ln -sf /usr/local/libmcrypt-2.5.8 /usr/local/libmcrypt
New  ln -sf /usr/local/libmcrypt/bin/libmcrypt-config /usr/bin/.
New  ln -sf /usr/local/libmcrypt/lib/libmcrypt* /usr/lib/.

ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ldconfig
rm -rf libmcrypt-2.5.8

1.4、安装mhash

#下载地址:http://mhash.sf.net/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf mhash-0.8.15.tar.gz
cd mhash-0.8.15/
./configure
New  ./configure --prefix=/usr/local/mhash-0.9.9.9
make && make install
New  ln -sf /usr/local/mhash-0.9.9.9 /usr/local/mhash
New  ln -sf /usr/local/mhash/lib/* /usr/lib/.

ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ldconfig
rm -rf mhash-0.8.15

1.5、安装mcrypt

#下载地址:https://sourceforge.net/projects/mcrypt/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure --prefix=/usr/local/mcrypt-2.6.8
make && make install
ln -sf /usr/local/mcrypt-2.6.8/ /usr/local/mcrypt
rm -rf mcrypt-2.6.8 

1.6、安装freetype

#下载地址:https://download.savannah.gnu.org/releases/freetype/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf freetype-2.9.1.tar.gz
cd freetype-2.9.1/
./configure --prefix=/usr/local/freetype-2.9.1
make && make install
ln -sf /usr/local/freetype-2.9.1/ /usr/local/freetype
#cp /usr/local/freetype/lib/pkgconfig/freetype2.pc /usr/lib/pkgconfig/ 这句未执行
cat > /etc/ld.so.conf.d/freetype.conf<<EOF
/usr/local/freetype/lib
EOF
ldconfig
ln -sf /usr/local/freetype/include/freetype2/* /usr/include/

1.7、安装pcre

#下载地址:https://www.pcre.org/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf pcre-8.42.tar.gz
cd pcre-8.42/
./configure --prefix=/usr/local/pcre-8.42/
make && make install
ln -sf /usr/local/pcre-8.42/ /usr/local/pcre
rm -rf pcre-8.42

1.8、内存管理优化工具(可以不装,也可以二选一)

1.8.1、安装Jemalloc

#下载地址:https://github.com/jemalloc/jemalloc/releases
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar jxvf jemalloc-5.1.0.tar.bz2
cd jemalloc-5.1.0/
./configure
make && make install
ldconfig
ln -sf /usr/local/lib/libjemalloc* /usr/lib/
rm -rf jemalloc-5.1.0

1.8.2、安装TCMalloc(TCMalloc是gperftools的一个插件,所以直接安装gperftools即可)

因为gperftools需要libunwind,我们先来安装libunwind。

1.8.2.1、安装libunwind

#下载地址:http://download.savannah.gnu.org/releases/libunwind/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf libunwind-1.2.tar.gz
cd libunwind-1.2/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
rm -rf libunwind-1.2

1.8.2.2、安装gperftools

#下载地址:https://github.com/gperftools/gperftools.git
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
#使用Git库安装
git clone https://github.com/gperftools/gperftools.git
#或用工具包内文件安装
tar zxvf gperftools-2.7.tar.gz
cd gperftools-2.7/
#判断系统是32还是64位
getconf LONG_BIT
./autogen.sh
#如果64位执行
./configure
#如果是32位执行
./configure --enable-frame-pointers
make
make install
ldconfig
ln -sf /usr/local/lib/libtcmalloc* /usr/lib/

=================Nginx配置====================
mkdir /tmp/tcmalloc
chown -R www:www /tmp/tcmalloc
sed -i '/nginx.pid/a\
google_perftools_profiles /tmp/tcmalloc;' /usr/local/nginx/conf/nginx.conf

1.9、安装openssl

#下载地址:https://www.openssl.org/source/snapshot/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf openssl-1.1.0-stable-SNAP-20180901.tar.gz
./config -fPIC --prefix=/usr/local/openssl-1.1.0 --openssldir=/usr/local/openssl-1.1.0
perl configdata.pm --dump
make depend && make && make install
ln -sf /usr/local/openssl-1.1.0/ /usr/local/openssl
ln -sf /usr/local/openssl/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1
ln -sf /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -sf /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1
ln -sf /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
rm -rf openssl-1.1.0-stable-SNAP-20180901

1.10、安装Crul

#下载地址:https://curl.haxx.se/download.html
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf curl-7.61.0.tar.gz
cd curl-7.61.0/
./configure --prefix=/usr/local/curl-7.61.0 --enable-ares --without-nss --with-ssl=/usr/local/openssl
New ./configure --prefix=/usr/local/curl-7.71.1 --enable-ares=/usr/local/c-ares --without-nss --with-nghttp2 --with-ngtcp2 --enable-sspi --with-ssl=/usr/local/openssl

make && make install
ln -sf /usr/local/curl-7.65.1/ /usr/local/curl
ln -sf /usr/local/curl/bin/* /usr/bin/
cat > /etc/ld.so.conf.d/freetype.conf<<EOF
/usr/local/freetype/lib
EOF
ldconfig
rm -rf curl-7.61.0

备注:安装Crul的时候有可能提示:configure: error: c-ares library defective or too old

这里升级安装c-ares

#下载地址:https://c-ares.haxx.se/download/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar zxvf c-ares-1.14.0.tar.gz
cd c-ares-1.14.0/
ll
./configure --prefix=/usr/local/c-ares-1.14.0
make
make install
ln -sf /usr/local/c-ares-1.14.0/ /usr/local/c-ares
rm -rf c-ares-1.14.0
#安装的时候需要    --enable-ares=/usr/local/c-ares/

1.11、安装Nghttp2

#下载地址:https://github.com/nghttp2/nghttp2/releases
#工具包 https://gitee.com/bbhsky/Centos7-setup.git
tar Jxvf nghttp2-1.33.0.tar.xz
cd nghttp2-1.33.0/
./configure --prefix=/usr/local/nghttp2-1.33.0
make && make install
ln -sf /usr/local/nghttp2-1.33.0/ /usr/local/nghttp2
rm -rf nghttp2-1.33.0

1.12、安装boots(安装MySQL5.7和MySQL8.0需要)

#下载地址:https://www.boost.org/users/download/
#工具包 https://gitee.com/bbhsky/Centos7-setup.git

#解压即可
tar zxvf boost_1_68_0.tar.gz
#MySQL5.7如果报错请测试低版本,比如1.59
tar zxvf boost_1_59_0.tar.gz

2、系统环境设置

2.1、设置虚拟内存

#其他建议设置成无限制(unlimited)的一些重要设置是: 
#数据段长度:ulimit -d unlimited 
#最大内存大小:ulimit -m unlimited 
#堆栈大小:ulimit -s unlimited 
#CPU 时间:ulimit -t unlimited 
虚拟内存:ulimit -v unlimited #建议设置

2.2、设置libpng和libjpeg

#64位
ln -sf /usr/lib64/libpng.* /usr/lib/
ln -sf /usr/lib64/libjpeg.* /usr/lib/

2.3、加载新的lib库

echo "/lib" >> /etc/ld.so.conf
echo "/usr/lib" >> /etc/ld.so.conf
echo "/usr/lib64" >> /etc/ld.so.conf
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

2.4、配置limits.conf

cat >>/etc/security/limits.conf<<eof
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
eof

2.5、配置sysctl.conf

#参数表示进程可以同时打开的最大句柄数,这个参数直接限制最大并发连接数。
echo "fs.file-max=65535" >> /etc/sysctl.conf

3、mysql安装

3.1、Docker安装(推荐)

3.2、编译安装5.7

4、编译安装php

4.1、安装编译7.2

4.2、安装编译7.3

5、编译安装Nginx

6、设置自启动

systemctl enable mysql.service
systemctl enable php-fpm.service
systemctl enable nginx.service

7、安装phpmyadmin

#下载地址:https://www.phpmyadmin.net
#工具包 https://gitee.com/bbhsky/PHP-Setup.git
unzip phpMyAdmin-4.8.3-all-languages.zip
mv phpMyAdmin-4.8.3-all-languages /home/wwwroot/default/phpmyadmin
cp conf/config.inc.php /home/wwwroot/default/phpmyadmin/config.inc.php
sed -i 's/LNMPORG/FoolTiger/g' /home/wwwroot/default/phpmyadmin/config.inc.php
mkdir /home/wwwroot/default/phpmyadmin/upload
mkdir /home/wwwroot/default/phpmyadmin/save
chmod 755 -R /home/wwwroot/default/phpmyadmin/
chown www:www -R /home/wwwroot/default/phpmyadmin/

8、安装Memcached

赞(0) 打赏
未经允许不得转载:FoolTiger笔记本 » [Centos]安装LNMP服务器
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏