设为首页 收藏本站
查看: 1390|回复: 0

LNMP配置文件及问题解决

[复制链接]

尚未签到

发表于 2015-11-16 08:25:58 | 显示全部楼层 |阅读模式
1.       安装mysql
mysql-5.0.41-linux-i686-glibc23.tar.gz 由于mysql是二进制包。所以还是比较方便的。
直接解压。然后移动。
mv mysql-5.0.41-linux-x86_64-glibc23 /usr/local/mysql
cd /usr/local/mysql
groupadd mysql
useradd -g mysql mysql
chown -R mysql .
chgrp -R mysql .
chown -R root .

./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/var/www/mysql/data
cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server  /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig –add mysqld
chkconfig --level 3 mysqld on
mv /usr/local/mysql/data /var/www/mysql
chown -R mysql:mysql /var/www/mysql


编辑/etc/my.cnf
[mysqld] 段增加
datadir = /var/www/mysql
skip-innodb
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000
[mysqld] 段修改
max_allowed_packet = 16M
thread_cache_size = CPU个数*2
log-bin 注释
service mysqld start
bin/mysqladmin -u root -p
  

如果启动 /opt/module/mysql/bin/mysqld_safe &


# 注:这里可能会出现错误。
[iyunv@localhost mysql]# Starting mysqld daemon with databases from /opt/module/mysql/data
STOPPING server from pid file /opt/module/mysql/data/localhost.localdomain.pid
101029 17:49:43  mysqld ended
这是因为basedirdatadir目录未设置的问题。那么在/etc/my.cnf  [mysqld]里和 /etc/rc.d/init.d/mysqld里面都上
添加basedir = /opt/module/mysql   datadir=/opt/data/mysql  (这都是我的目录,相应改成你的目录)

再次启动。就应该可以了。


2.       安装扩展库
安装pcre
tar -zxvf pcre-7.8.tar.gz
cd pcre-7.8
./configure
make && make install clean


安装 GD
安装 zlib
tar zxvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure --prefix=/usr

make && make install clean
cd ..
安装 libpng
tar zxvf libpng-1.2.44.tar.gz
cd libpng-1.2.44
./configure
make && make install clean
cd ..
  
安装 jpeg
tar zxvf jpegsrc.v8b.tar.gz
cd jpeg-8b
./configure -enable-shared -enable-static
make && make install clean
cd ..
安装 freetype
tar zxvf freetype-2.4.4.tar.gz
cd freetype-2.4.4
./configure
make && make install clean
cd ..
安装autoconf
tar zxvf autoconf-2.68.tar.gz
cd autoconf-2.68
./configure
make && make install clean
cd ..
安装 gd2.0.35
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd2 --with-zlib --with-freetype --with-jpeg --with-png
make && make install clean
cd ..
安装 libxml2
tar -zxvf libxml2-2.7.6.tar.gz
cd libxml2-2.7.6
./configure
make && make install clean
cd ..
安装libiconv
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make && make install clean
cd ..


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


安装mhash
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make && make install clean
cd ../
ln
命令在某个地方建立一个同步的链接
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config



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



3.       安装编译PHPFASTCGI
tar zxvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17/
./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 /
--with-iconv-dir=/usr/local /

--with-freetype-dir /
--with-jpeg-dir /
--with-png-dir /
--with-zlib /
--with-libxml-dir=/usr /
--enable-xml /
--disable-rpath /
--enable-discard-path /
--enable-safe-mode /
--enable-bcmath /
--enable-shmop /
--enable-sysvsem /
--enable-inline-optimization /
--with-curl /
--with-curlwrappers /
--enable-mbregex /
--enable-fastcgi /
--enable-fpm /
--enable-force-cgi-redirect /
--enable-mbstring /
--with-mcrypt /
--with-gd=/usr/local/gd2/ /
--enable-gd-native-ttf /
--with-openssl /
--with-mhash /
--enable-pcntl /
--enable-sockets /
--with-ldap /
--with-ldap-sasl


make ZEND_EXTRA_LIBS='-liconv'
make install clean


# 注:这里可能会出现错误。
Installing PEAR environment:      /usr/local/php/lib/php/
/usr/local/src/php-5.2.17/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory
make[1]: *** [install-pear-installer] Error 127
make: *** [install-pear] Error 2
说没找到libmysqlclient.so.15 那么解决方法。
cp /usr/local/mysql/lib/libmysqlclient.so.15 /usr/lib再次make install 搞定!

cp php.ini-dist /usr/local/php/etc/php.ini


mv -f /usr/local/src/conf/php-fpm.conf /usr/local/php/etc/php-fpm.conf
echo 'ulimit -SHn 65535' >> /etc/rc.local
echo '/usr/local/php/sbin/php-fpm start' >> /etc/rc.local
cd ../

4.         编译安装PHP5扩展模块
memcache
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install clean
cd ../


eaccelerator
tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install clean
cd ../


配置eAccelerator加速PHP
mkdir -p /usr/local/eaccelerator_cache
vi /usr/local/php/etc/php.ini

[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="120"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

  修改配置文件:
vi /etc/sysctl.conf
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
# kernel.shmmax = 4294967295
kernel.shmmax = 134217728

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456
  然后执行以下命令使配置生效:
/sbin/sysctl -p

PDO_MYSQL
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
make && make install clean
cd ../


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


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


  

Memcached
tar zxvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
./configure --prefix=/usr/lib
make && make install clean
cd ../
tar zxvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure --prefix=/usr/local --with-libevent=/usr/lib/lib
make && make install clean

/usr/local/bin/memcached -d -u www -m 128
-p <num>
监听的TCP端口(缺省: 11211)
-d
以守护进程方式运行 以守护进程方式运行 Memcached Memcached
-u <username>
运行运行 Memcached的账户 root用户
-m <num>
最大的内存使用单位是MB 缺省是64MB
-c <num>
软连接数量缺省是1024
-v
输出警告和错误信息
-vv
打印客户端的请求和返回信息
-h
打印帮助信息
-i
打印memcachedlibevent的版权信息

# 注:这里可能会出现错误。
error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory 这样的问题是在安装memcached的时候遇到的。
我按别人的攻略安装了libeventmemcached之后却发现在执行的时候出现了。 error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory 这个错误提示。
解决类似问题的步骤我相信我的做法可以通用。
1. 首先 find / -name libevent-1.4.so.2 找到缺少的链接文件到底在那儿。
2. LD_DEBUG=libs /usr/local/bin/memcached -v
3. Debug信息中就知道程序去哪里找链接库了。我这边程序去 trying file=/usr/lib/libevent-1.4.so.2 而我的链接库的实际存储位置是 /usr/local/lib/libevent-1.4.so.2
4. 做一个软连接ln -s /usr/lib/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2
5.         安装ZendOptimizer

tar zxvf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.9-linux-glibc23-i386
cp data/5_2_x_comp/ZendOptimizer.so /usr/local/php/include/

编辑php.ini
vi /usr/local/php/etc/php.ini
extension_dir = &quot;/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/&quot;
extension=pdo_mysql.so

extension=memcache.so
extension=imagick.so

[zend]
zend_optimizer.optimization_level=15
zend_extension=&quot;/usr/local/php/include/ZendOptimizer.so&quot;

再查找output_buffering = Off
修改为output_buffering = On

重启PHP FCGI
/usr/local/php/sbin/php-fpm restart

6.         安装nginx

groupadd www
useradd -g www www

tar zxvf nginx..gz
cd nginx
./configure --prefix=/usr/local/nginx /
--conf-path=/usr/local/nginx/conf/nginx.conf /
--with-http_realip_module /
--with-http_addition_module /
--with-http_gzip_static_module /
--with-http_random_index_module /
--with-http_stub_status_module /
--with-http_sub_module /
--with-http_dav_module


make && make install

Nginx 日志目录
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www:www /var/log/nginx

创建 Nginx 配置文件
、在/usr/local/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local//nginx/conf/nginx.conf
vim /usr/local/nginx/conf/nginx.conf


user  www www;

worker_processes 4;

error_log  /var/log/nginx/error.log;
pid       /var/log/nginx/nginx.pid;

worker_rlimit_nofile 65535;

events
{
  use epoll;
  worker_connections 65535;
}

http
{
  include       mime.types;
  default_type  application/octet-stream;

  #charset  gb2312;
  charset  utf-8;
      
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
      
  sendfile on;
  tcp_nopush     on;

  keepalive_timeout 60;

  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;

  gzip on;
  gzip_min_length  1k;
  gzip_buffers     4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types       text/plain application/x-javascript text/css application/xml;
  gzip_vary on;

  server
  {
listen       10.0.0.61:80;
server_name  10.0.0.61;
index index.html index.htm index.php;
root  /home/www/wwwroot;
                             
    location ~ .*/.php?$
    {      
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }
   
    location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }

    location ~ .*/.(js|css)?$
    {
      expires      1h;
}

location /NginxStatus
{
  stub_status    on;
  access_log    off;
}

    access_log  off;
   }
}

、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/nginx/conf/fcgi.conf

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;


建立nginx启动脚本
vi /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# 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/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/log/nginx/nginx.pid

RETVAL=0
prog=&quot;nginx&quot;

# Source function library.
. /etc/rc.d/init.d/functions
&quot;/etc/init.d/nginx&quot; [dos] 101L, 1996C
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# 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/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/log/nginx/nginx.pid

RETVAL=0
prog=&quot;nginx&quot;

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = &quot;no&quot; ] && exit 0

[ -x $nginxd ] || exit 0


# Start nginx daemons functions.
start() {

if [ -e $nginx_pid ];then
   echo &quot;nginx already running....&quot;
   exit 1
fi

   echo -n $&quot;Starting $prog: &quot;
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL

}


# Stop nginx daemons functions.
stop() {
        echo -n $&quot;Stopping $prog: &quot;
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}


# reload nginx service functions.
reload() {

    echo -n $&quot;Reloading $prog: &quot;
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo

}

# See how we were called.
case &quot;$1&quot; in
start)
        start
        ;;

stop)
        stop
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $&quot;Usage: $prog {start|stop|restart|reload|status|help}&quot;
        exit 1
esac

exit $RETVAL

chmod 755 /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

7.       启动NginxPHP

ulimit -SHn 65535
/usr/local/php/sbin/php-fpm start
service nginx start


8.         优化Linux内核参数
vi /etc/sysctl.conf

在末尾增加以下内容:
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_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 65536

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_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.ip_local_port_range = 1024  65535
使配置立即生效:
/sbin/sysctl -p

9.         ddos攻击
Sysctl 修改
vi /etc/rc.local
加入如下文本
sysctl kern.ipc.maxsockets=100000  ##增加并发的socket,对于ddos很有用
sysctl kern.ipc.somaxconn=65535  ##打开文件数
sysctl net.inet.tcp.msl=2500   ##timeout时间



10.     编写每天定时切割Nginx日志的脚本
1、创建脚本/usr/local/webserver/nginx/sbin/cut_nginx_log.sh
vi /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
  输入以下内容:
#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path=&quot;/usr/local/webserver/nginx/logs/&quot;

mkdir -p ${logs_path}$(date -d &quot;yesterday&quot; +&quot;%Y&quot;)/$(date -d &quot;yesterday&quot; +&quot;%m&quot;)/
mv ${logs_path}access.log ${logs_path}$(date -d &quot;yesterday&quot; +&quot;%Y&quot;)/$(date -d &quot;yesterday&quot; +&quot;%m&quot;)/access_$(date -d &quot;yesterday&quot; +&quot;%Y%m%d&quot;).log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`



  2、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e
  输入以下内容:
00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh

             版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-139666-1-1.html 上篇帖子: centos6.6配置LNMP(linux+nginx+mysql+php) 下篇帖子: lnmp基础
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表