资讯专栏INFORMATION COLUMN

centos下编译lnmp环境

tuomao / 494人阅读

摘要:部署架设环境网卡绑定多个内网和外网下其实这部不用操作默认就是原来的内网配置原配置中的地址原配置的内网地址原配置原配置原配置添加规则内网

uclund 部署架设环境

cp /etc/resolv.conf /etc/resolv.conf.bak

yum update -y
yum -y install gcc gcc-c++ autoconf cmake libjpeg libg libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-deves-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-idn-devel openssl openssl-devel openldap openldap-devel nss_ldclients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN ncurses-devel bison bison-devel bzip2-devel libxslt-devel zip unzip
reboot

//网卡绑定多个内网和外网 ucloud.cn下

cd /etc/sysconfig/network-scripts cp ifcfg-eth0 ifcfg-eth0:1 vim ifcfg-eth0
DEVICE=eth0
IPADDR=$Publick_IP
NETMASK=255.255.255.255
BOOTPROTO=none
PEERDNS=yes
USERCTL=no
NM_CONTROLLED=no
ONBOOT=yes
vim ifcfg-eth0:1 其实这部不用操作 默认就是原来的内网配置
DEVICE=eth0:1
HWADDR=原配置中的mac地址
IPADDR=原配置的内网ip地址
NETMASK=255.255.0.0
BOOTPROTO=none
PEERDNS=yes
USERCTL=no
NM_CONTROLLED=no
ONBOOT=yes
DNS1=原配置
DNS2=原配置
DNS3=原配置
vim route-eth0

10.0.0.0/8 via 10.9.0.1
default via 10.9.0.1 src $Public_IP

service network restart vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

添加iptables规则:

iptables -t nat -A PREROUTING ! -s 10.0.0.0/8 -d 内网ip/32 -j DNAT --to-destination $Publick_IP iptables -t nat -A POSTROUTING -s 外网ip/32 -j SNAT --to-source 内网ip

umount /dev/vdb
fdisk -l
fdisk /dev/vdb
n
p
1
[enter]
[enter]
w

去掉vdb1的自动加载

vim /etc/fstab
mkdir /web
mkfs.ext3 /dev/vdb1
vim /etc/fstab

/dev/vdb1    /web    ext3    defaults     0 0

mount -a

安装mysql-5.6.26

创建mysql用户和组
groupadd mysql
useradd -g mysql -s /usr/sbin/nologin mysql
mkdir -p /web/mysql/data
mkdir -p /web/mysql/logs
mkdir -p /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /web/mysql

编译安装mysql
tar zxvf mysql-5.6.26.tar.gz
cd mysql-5.6.26

cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/web/mysql/data
-DSYSCONFDIR=/etc
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock
-DMYSQL_TCP_PORT=3306
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_READLINE=1-DWITH_SSL=system
-DWITH_EMBEDDED_SERVER=1
-DENABLED_LOCAL_INFILE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_DEBUG=0

make && make install

============可能遇到的编译错误===========
出现函数gets错误的
解决办法:
rm -f CMakeCache.txt

yum -y install ncurses-devel

修改配置文件
cp ./support-files/my-medium.cnf /etc/my.cnf
vi /etc/my.cnf

 输入以下内容(可以先清空默认内容):

[mysqld]
datadir=/web/mysql/data
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/web/mysql/logs/mysqld.log
pid-file=/web/mysql/mysqld.pid
user=mysql
tmpdir=/tmp

or
cp /web/lanmp/my.cnf /etc/my.cnf

初始化数据库
/usr/local/mysql/scripts/mysql_install_db
--user=mysql
--basedir=/usr/local/mysql
--datadir=/web/mysql/data

配置开机自启动
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

添加MySQL的软链接以适应init脚本
ln -sv /usr/local/mysql/bin/mysql /usr/sbin/mysql
ln -sv /usr/local/mysql/bin/mysqladmin /usr/sbin/mysqladmin
ln -sv /usr/local/mysql/bin/mysqldump /usr/sbin/mysqldump

启动mysql
service mysqld start  # 或 /etc/init.d/mysqld start

修改root密码:

mysqladmin -uroot password "新密码"

mysql -uroot -p
输入新密码
create user "duigou"@"%" identified by "密码"
create user "duigou"@"localhost" identified by "密码"
create database duigou default character set utf8mb4 collate utf8mb4_general_ci;
grant all privileges on duigou.* to "duigou"@"%" identified by "密码";
grant all privileges on duigou.* to "duigou"@"localhost" identified by "密码";

======================================================================================
或者重新配置一个超级管理员并删除root
GRANT ALL PRIVILEGES ON . TO "admin"@"localhost" IDENTIFIED BY "12345678";
GRANT ALL PRIVILEGES ON . TO "admin"@"127.0.0.1" IDENTIFIED BY "12345678";

DELETE FROM user WHERE user!="admin"; #删除原先默认的用户,仅保留新建的admin用户

第三步:安装nginx-1.8.0

添加www用户和组、创建网站虚拟目录
groupadd www
useradd -g www -s /usr/sbin/nologin www
mkdir -p /web/htdocs/www
chmod +w /web/htdocs/www
chown -R www:www /web/htdocs/www
mkdir -p /web/htdocs/logs
chmod +w /web/htdocs/logs
chown -R www:www /web/htdocs/logs

安装Nginx所需的pcre库
tar zxvf pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && make install
ln -s /usr/local/lib/libpcre.so.1 /usr/lib64/libpcre.so.1
cd ..

安装nginx-1.8.0
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure
--user=www
--group=www
--prefix=/usr/local/nginx
--with-http_stub_status_module
--with-http_ssl_module
--with-http_realip_module
--with-http_image_filter_module

make && make install

创建Nginx配置文件和创建fcgi.conf文件
cp -f /web/lanmp/nginx.conf.uclound /usr/local/nginx/conf/nginx.conf
cp -f /web/lanmp/fastcgi.conf /usr/local/nginx/conf/fastcgi.conf

启动nginx
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx 直接启动

配置开机自启动
cp /web/lanmp/initd/nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig nginx on
service nginx start|stop|restart|reload

第四步:安装php5.5.13

cd ..
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make && make install

=====================================================================
编译libiconv解决./stdio.h:1010:1: 错误: ‘gets’未声明(不在函数内)
cd srclib/
sed -i -e "/gets is a security/d" ./stdio.in.h
cd ../
make

make install

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

cd ..
cd ..
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install

对共享库做符号链接

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/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18

cd ..
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make && make install

=====================================================================
遇到问题:configure: error: * libmcrypt was not found
继续查找,还是变量的问题
解决方法如下:运行

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

安装php:
cd ..
tar zxvf php-5.6.11.tar.gz
cd php-5.6.11

./configure
--prefix=/usr/local/php
--with-config-file-path=/usr/local/php/etc
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-fpm
--enable-calendar
--enable-dba
--enable-wddx
--enable-opcache
--with-fpm-user=php-fpm
--with-fpm-group=php-fpm
--with-mysql=mysqlnd
--with-mysql-sock=/tmp/mysql.sock
--with-libxml-dir=/usr
--with-xsl
--with-gd
--with-bz2
--with-kerberos
--with-jpeg-dir
--with-png-dir
--with-zlib
--with-freetype-dir
--with-iconv-dir
--with-zlib-dir
--with-mcrypt
--enable-soap
--enable-gd-native-ttf
--enable-ftp
--enable-sockets
--enable-zip
--enable-posix
--enable-pcntl
--enable-mbstring
--enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf
--with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap
--enable-mbregex
--enable-sysvsem
--enable-sockets
--enable-shmop
--enable-bcmath
--enable-xml
--enable-exif
--disable-ipv6
--with-pear
--with-curl
--with-openssl
--with-pdo-mysql

--enable-magic-quotes
--disable-fileinfo

注:如果内存较大 可以去掉--disable-fileinfo

======================================================
configure: error: Please reinstall the BZip2 distribution
yum install bzip2-devel.x86_64 -y

error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum install libxslt-devel -y make ZEND_EXTRA_LIBS="-liconv"

make
如果直接make出错make: * [sapi/cli/php] Error 1

make ZEND_EXTRA_LIBS="-liconv"

make install

php.ini设置

cp /web/lanmp/php.ini /usr/local/php/etc/php.ini
cp /web/lanmp/php-fpm.conf /usr/local/php/etc/php-fpm.conf

fpm加入自启动
cp /web/lanmp/initd/php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
service php-fpm start|stop|restart|reload

vi /etc/rc.local

输入

ulimit -SHn 65535

以上简单部署 下面是增加部分的扩展和优化

编译PHP扩展模块memcache、pdo_mysql、imagick
tar zxvf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
出错出现configure: error: mysql_query missing!? 解决方法 ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make出错
make && make install
cd ../

tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
ln -s /usr/local/mysql/include/* /usr/local/include/
make
make install
cd ../

tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../

tar zxvf imagick-3.2.0RC1.tgz
cd imagick-3.2.0RC1
/usr/local/php/bin/phpize
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

修改php.ini配置文件
vi /usr/local/php/etc/php.ini

查找; extension_dir = "/" 将前面的;去掉并修改为

extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/"

并加入

extension=memcache.so
extension=pdo_mysql.so
extension=imagick.so

执行下面的命令使配置文件立即生效:
kill -USR2 cat /usr/local/php/var/run/php-fpm.pid

其他(可选):

优化linux内核参数

vi /etc/sysctl.conf

在末尾增加以下内容:

Add

net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768

net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_len = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800

net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 120

net.ipv4.ip_local_port_range = 1024 65535

使配置立即生效:
/sbin/sysctl -p

安装opcache(因为PHP 5.5已经集成Zend Opcache,可以替代eaccelerator)
tar zxvf zendopcache-7.0.3.tgz
cd zendopcache-7.0.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd ../

在php.ini中加入下面配置:

[opcache]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
?
1
2 # 使php.ini配置文件立即生效
kill -USR2 cat /usr/local/php/var/run/php-fpm.pid

常用命令:

修改完php.ini后执行:

kill -USR2 cat /usr/local/php/var/run/php-fpm.pid

修改完nginx.conf后执行

/usr/local/nginx/sbin/nginx -s reload

重启mysql服务执行:

service mysqld (start|stop|restart)

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39610.html

相关文章

  • CentOS7.0下编安装PHP 5.6.21

    摘要:写在前面的话本文章紧接上一篇下编译安装。来完成常用的开发集成环境的基本搭建,本篇来记录的安装,还是那些步骤。 写在前面的话 本文章紧接上一篇CentOS7.0下编译安装Nginx 1.10.0。来完成常用的web开发集成环境lnmp的基本搭建,本篇来记录php的安装,还是那些步骤。 安装编译工具、依赖包及下载源码包 解压编译 安装 启动 编译安装 下载源码 由于在上篇文章中编译工具...

    Me_Kun 评论0 收藏0
  • CentOS7.0下编安装PHP 5.6.21

    摘要:写在前面的话本文章紧接上一篇下编译安装。来完成常用的开发集成环境的基本搭建,本篇来记录的安装,还是那些步骤。 写在前面的话 本文章紧接上一篇CentOS7.0下编译安装Nginx 1.10.0。来完成常用的web开发集成环境lnmp的基本搭建,本篇来记录php的安装,还是那些步骤。 安装编译工具、依赖包及下载源码包 解压编译 安装 启动 编译安装 下载源码 由于在上篇文章中编译工具...

    FullStackDeveloper 评论0 收藏0
  • Debian9(Stretch) 下编安装LNMP环境

    摘要:下源码安装一前言之前,我的开发环境是。重新加载权限表将确保所有到目前为止所做的更改将立即生效。然后,和注意,如果是使用二进制包安装了及相应的开发库,不需要指定路径。五参考资料入门教程编译安装编译安装 Debian9下源码安装LNMP 一、前言 之前,我的开发环境是Windows-10+PHP-7.1+Nginx-1.10+MariaDB-10.1。 后面开发需要使用到memcached...

    ideaa 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<