CentOS下 安裝LNMP+memcache

#通過yum安裝gcc 、gcc-c++、libevent、libevent-devel、openssl、openssl-devel、libjpeg-devel libpng-devel freetype-devel curl-devel


yum -y install gcc gcc-c++  libjpeg-devel  libpng-devel cmake libevent libevent-devel

yum -y install freetype-devel libxml2-devel zlib-devel glibc-devel  glib2-devel bison autoconf

yum -y install bzip2-devel  ncurses-devel curl-devel  e2fsprogs-devel krb5-devel

yum -y install libidn-devel  openssl-devel openld  openldap-devel openldap-clients openldap-servers


#檢查是否安裝過rpm包

rpm -qa | grep httpd

#查看進程運行情況

ps -le | grep mysql

#查看所有默認系統服務

ls /etc/rc.d/init.d

#停止服務

service httpd stop

#卸載系統已安裝的rpm包

yum remove httpd

#停用SELinux

vi /etc/sysconfig/selinux  SELINUX=disabled

setenforce 0

#停用iptables

iptables -F


#解壓所有tar包的shell

cd /lamp

ls *.tar.gz > ls.list

for TAR in `cat ls.list`

do

tar -zxf $TAR

done


#標準源代碼包安裝的步驟

1、.tar.gz  tar -zxf   //解壓解包  

2、./configure //配置 --prefix=/usr/local/libxml2/

3、make //編譯

4、make install > 日誌文件  //安裝、拷貝


#標準源代碼包卸載

rm -rf 安裝目錄  與 源代碼目錄  


#安裝libxml2 (可忽略)

#安裝zlib-1.2.3 (不指定安裝位置) (可忽略)

#安裝libpng-1.2.31 (可忽略)

#安裝jpeg-6b (jpegsrc.v6b) (可忽略)

mkdir /usr/local/jpeg6

mkdir /usr/local/jpeg6/bin

mkdir /usr/local/jpeg6/lib

mkdir /usr/local/jpeg6/include

mkdir -p /usr/local/jpeg6/man/man1

./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

#安裝freetype-2.3.5  (可忽略)

#安裝autoconf-2.61(不指定安裝位置)  (可忽略)

#安裝gd-2.0.35(可忽略)

./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/


yum install apr-util-devel apr  apr-devel apr-util

#安裝apache

./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd --with-include-apr --with-pcre --enable-maintainer-mode --enable-dav --enable-modes-shared=most --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support

make

make install

#把apache加載到系統服務中,並讓其開機啓動

cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd


#修改httpd在文件頭部加入如下內容:

vi /etc/rc.d/init.d/httpd


###

# Comments to support chkconfig on RedHat Linux

# chkconfig: 2345 90 90

# description:http server

###

chkconfig --add httpd   chkconfig --del httpd

chkconfig --list httpd

chkconfig --levels 245 httpd off

chkconfig --list httpd


#httpd.conf設置ServerName爲本機name

/usr/local/apache2/bin/htpasswd -c /opt/svndata/repos/conf/passwd user1

/usr/local/apache2/bin/htpasswd  /opt/svndata/repos/conf/passwd user2


<Location /svn>

   DAV svn

   SVNParentPath /opt/svndata

   AuthType Basic

   AuthName "Subversion"

   AuthUserFile /opt/svndata/repos/conf/passwd

   AuthzSVNAccessFile /opt/svndata/repos/conf/authz

   Require valid-user

</Location>


#安裝libmcrypt-2.5.8

tar -zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt/

make && make install

#安裝libmcrypt下的libltdl

cd libltdl

./configure --enable-ltdl-install

make && make install

#安裝ncurses-5.6 (可忽略)

./configure --with-shared --without-debug --without-ada --enable-overwrite


#安裝mysql

groupadd mysql

grep mysql /etc/group

useradd -g mysql mysql


#安裝老版本mysql

./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all

#安裝完成後拷貝配置文件

cp support-files/my-medium.cnf /etc/my.cnf

#創建數據庫授權表

/usr/local/mysql/bin/mysql_install_db --user=mysql

#改變mysql所屬用戶

chown -R mysql /usr/local/mysql

chown -R mysql /usr/local/mysql/var

chgrp -R mysql /usr/local/mysql

/usr/local/mysql/bin/mysqld_safe --user=mysql &

ps -le | grep mysqld

netstat -an | grep 3306


/usr/local/mysql/bin/mysqladmin version//查看mysql版本

/usr/local/mysql/bin/mysqladmin variables //查看mysql運行參數

#爲mysql設置密碼

/usr/local/mysql/bin/mysql -u root

SET PASSWORD FOR 'root'@'localhost'=PASSWORD('123');

exit


#讓mysql開機啓動

方法1:echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local

方法2:cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld

chown root.root /etc/rc.d/init.d/mysqld

chmod 755 /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

chkconfig --list mysqld

chkconfig --levels 245 mysqld off

chkconfig --list mysqld


#安裝Mysql5.5版本

groupadd mysql

grep mysql /etc/group

useradd -g mysql mysql

tar -zxvf mysql-5.5.28.tar.gz

cd mysql-5.5.28

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \    //指定mysql安裝目錄

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \                          //指定服務器默認字符集,默認latin1

-DDEFAULT_COLLATION=utf8_general_ci \             //指定服務器默認的校對規則,默認latin1_general_ci

-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=/data/mysql   // 數據文件目錄


[root@ceshi6 mysql-5.5.27]# make && make install

[root@ceshi6 mysql-5.5.27]# chmod +w /usr/local/mysql/

[root@ceshi6 mysql-5.5.27]# chown -R mysql:mysql /usr/local/mysql/

[root@ceshi6 mysql-5.5.27]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so18

[root@ceshi6 mysql-5.5.27]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so18

[root@ceshi6 mysql-5.5.27]# mkdir -p /data/mysql/data/

[root@ceshi6 mysql-5.5.27]# mkdir -p /data/mysql/log/

[root@ceshi6 mysql-5.5.27]# chown -R mysql:mysql /data/mysql/

[root@ceshi6 mysql-5.5.27]# cd support-files

mysql配置文件

[root@ceshi6 support-files]# cp my-large.cnf /etc/my.cnf

cp:是否覆蓋"/etc/my.cnf"? y

[root@ceshi6 support-files]# cp mysql.server /etc/init.d/mysqld

cp:是否覆蓋"/etc/init.d/mysqld"? y


初始化mysql

[root@ceshi6 support-files]# /usr/local/mysql/scripts/mysql_install_db \

--defaults-file=/etc/my.cnf \

--basedir=/usr/local/mysql/ \

--datadir=/data/mysql/data/ \

--user=mysql


[root@ceshi6 support-files]# vi /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql/data

[root@ceshi6 support-files]# chmod +x /etc/init.d/mysqld

[root@ceshi6 support-files]# chkconfig mysqld on

service mysqld start

[root@ceshi6 mysql-5.5.27]# /usr/local/mysql/bin/mysql -u root -p


#允許mysql遠程登錄:

grant all on *.* to root@'%' IDENTIFIED BY '123' with grant option;

#修改root本地登錄密碼

update mysql.user set password=password("123") where user="root" and host="localhost";

#設置mysql字符集

vi /etc/my.cnf

[client]

default-character-set = utf8

[mysqld]

character_set_server = utf8


#修改默認表引擎

[mysqld] 後面增加default-storage-engine=INNODB


#安裝libiconv-1.14.tar.gz

tar -zxvf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure

make && make install


#增加庫文件識別

vi /etc/ld.so.conf

追加/usr/local/lib

ldconfig


#安裝php5.2.6

cp -frp /usr/lib64/libjpeg.* /usr/lib/

cp -frp /usr/lib64/libpng* /usr/lib/

去除openssl 與 mysqli

安裝 mhash-0.9.9.9.tar


#安裝php5.3.8

tar -zxvf php-5.3.8.tar.gz

./configure --prefix=/usr/local/php/ --with-iconv-dir=/usr/local   --with-curl  --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql  --enable-sockets --with-openssl --with-mhash  --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6 --with-freetype-dir=/usr/local/freetype/ --with-gd --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --without-pear  --with-zlib

./configure --prefix=/usr/local/php/ --with-iconv-dir=/usr/local   --with-curl  --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --enable-ftp --enable-sockets --with-openssl --with-mhash  --with-libxml-dir=/usr --with-jpeg-dir --with-freetype-dir --with-gd --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --with-zlib --without-pear --enable-fpm


./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache2/bin/apxs --with-iconv-dir=/usr/local  --with-curl  --with-config-file-path=/usr/local/php/etc/ --with-mysql=/usr/local/mysql  --enable-sockets --with-openssl --with-mhash  --with-libxml-dir=/usr --with-jpeg-dir --with-freetype-dir --with-gd --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap  --with-zlib --enable-mbstring=all --enable-zip --without-pear


--with-apxs2=/usr/local/apache2/bin/apxs  


-–with-iconv=/usr/local/libiconv


make ZEND_EXTRA_LIBS='-liconv'


make install


#安裝成功後

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


#php語法錯誤不報錯解決方案


1,php.ini裏的error_reporting  =  E_ALL & ~E_NOTICE並且把前面的註釋去掉;

2,php.ini裏把display_error改爲On


#安裝nginx必須庫文件pcre

tar zxvf pcre-8.32.tar.gz

cd pcre-8.32/

./configure

make && make install


#安裝Nginx

useradd nginx

tar zxvf nginx-1.2.6.tar.gz

cd nginx-1.2.6

./configure  --prefix=/usr/local/nginx  --with-pcre --with-http_stub_status_module --with-http_ssl_module --user=nginx  --group=nginx  --with-http_flv_module --with-http_gzip_static_module


/configure \

 --prefix=/usr/local/nginx \

 --sbin-path=/usr/sbin/nginx \

 --conf-path=/etc/nginx/nginx.conf \

 --error-log-path=/var/log/nginx/error.log \

 --http-log-path=/var/log/nginx/access.log \

 --pid-path=/var/run/nginx/nginx.pid  \

 --lock-path=/var/lock/nginx.lock \

 --user=nginx \

 --group=nginx \

 --with-http_ssl_module \

 --with-http_flv_module \

 --with-http_stub_status_module \

 --with-http_gzip_static_module \

 --http-client-body-temp-path=/var/tmp/nginx/client/ \

 --http-proxy-temp-path=/var/tmp/nginx/proxy/ \

 --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \

 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

 --http-scgi-temp-path=/var/tmp/nginx/scgi \

 --with-pcre


make && make install


#如果運行nginx命令出錯的時候

從錯誤看出是缺少lib文件導致,進一步查看下

ldd $(which /usr/local/nginx/sbin/nginx)

可以看出 libpcre.so.1 => not found 並沒有找到,進入/lib64目錄中手動鏈接下ln -s libpcre.so.0.0.1 libpcre.so.1


#修改Nginx配置文件讓其支持php解析

#解注並修改以下項

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

user  nobody;

worker_processes  8;

error_log  logs/error.log;

pid       /usr/local/nginx/nginx.pid;

解注21,22,23行

events {

  worker_connections  65535;

}


location ~ \.php$ {

           root           /var/www/html;  

           fastcgi_pass   127.0.0.1:9000;  

           fastcgi_index  index.php;  

           fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;  

           include        fastcgi_params;  

}

#實現URL重寫

location / {

           root   /web/domain1;

           index  index.html index.htm;

           if (!-e $request_filename) {

                rewrite "^/([\w]+).html$" /$1.php last;

           }

}

#配置虛擬主機

include /usr/local/nginx/conf/vhosts/www.domain1.com.conf;(在80行左右添加)


#www.domain1.com.conf文件

server {

    listen       80;

    server_name  www.domain1.com;

    access_log   logs/domain1.access.log main;

    location / {

           root   /web/domain1;

           index  index.html index.htm;

           if (!-e $request_filename) {

                rewrite "^/([\w]+).html$" /$1.php last;

           }

    }

    location ~ \.php$ {

           root           /web/domain1;

           fastcgi_pass   127.0.0.1:9000;

           fastcgi_index  index.php;

           fastcgi_param  SCRIPT_FILENAME  /web/domain1$fastcgi_script_name;

           include        fastcgi_params;

    }

}


#允許查看nginx狀態

location /NginxStatus {

        stub_status on;

        access_log off;

allow 192.168.0.0/24;

deny all;

}



#檢查配置文件是否有錯

/usr/local/nginx/sbin/nginx -t


#配置php-fpm

php5.3.8默認包含php-fpm

cd /usr/local/php/etc

cp php-fpm.conf.default php-fpm.conf


php-fpm在/usr/local/php/sbin/下

#/usr/local/php/sbin/php-fpm ========啓動php-fpm


#編輯php-fpm配置文件

vi php-fpm.conf

找到pm.min_spare_servers 去除;號,注意非註釋內容pm.min_spare_servers

找到pm.max_spare_servers 去除;號,同樣非註釋內容pm.max_spare_servers

找到pm.start_servers 去除;號,同樣非註釋內容pm.start_servers

ERROR: bind() for address '127.0.0.1:9000' failed: Address already in use (98)

netstat -an | grep 9000查看進程,已開啓

killall php-fpm 結束所有php-fpm進程

再啓動php-fpm

#/usr/local/php/sbin/php-fpm

成功


#修改php.ini文件後重啓的步驟

pkill php-fpm

/usr/local/php/sbin/php-fpm

pkill -HUP nginx  //平滑重啓


#安裝mamcache的php擴展

[root@Linux ~]#tar -zxvf  memcache-2.2.7.tgz

編譯安裝:

[root@Linux ~]#cd memcache-2.2.7

[root@Linux ~]#/usr/local/php/bin/phpize

[root@Linux ~]#./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir

[root@Linux ~]#make && make install


#在php.ini文件中添加memcache擴展

[root@Linux ~]#vi /usr/local/php/etc/php.ini

添加以下內容

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

extension=memcache.so


#安裝memcache服務器端

tar zxvf memcached-1.4.15.tar.gz

cd memcached-1.4.15  

./configure --prefix=/usr/local/memcache  --with-libevent

make && make install  

#啓動memcache

cd  /usr/local/memcache/bin/

./memcached -d -m 1024 -u root -l 192.168.1.10 -p 11211 -c 128 -P /usr/local/memcache/memcached.pid  

#查看memcache  

ps  -ef  |  grep  memcached

#停止memcache進程

pkill memcached


#把Session交給Memcache管理保存

vi php.ini

#1450行左右

[Session]

; Handler used to store/retrieve data.

session.save_handler = memcache

session.save_path = tcp://192.168.1.161:11211


---------------------------

//附錄

#添加用戶級環境變量

vi ~/.bash_profile

#添加系統級環境變量

vi /etc/profile

PATH=$PATH:/usr/local/nginx/sbin

source .bash_profile

echo $PATH


#在Apache配置文件中支持php

vi /etc/httpd/httpd.conf

Addtype application/x-httpd-php .php .phtml

/usr/lcoal/apache2/bin/apachectl restart


#利用ssh登錄到局域網其他服務器

ssh -l root ip

#修改iptables

/etc/sysconfig/iptables

#修改網卡

/etc/sysconfig/network-scripts/ifcfg-eth0

#修改DNS地址

vi /etc/resolv.conf

#修改主機名與網關

vi /etc/sysconfig/network


#禁止使用ipv6:

/etc/modprobe.conf – 內核模塊配置文件

vi /etc/modprobe.d/disable-ipv6.conf (CentOS6版本後)

/etc/sysconfig/network – 網絡配置文件

1. # vim /etc/modprobe.conf

在其中加入下面這一行,

install ipv6 /bin/true

保存並退出。

2. # vim /etc/sysconfig/network

在其中加入下面配置項:

NETWORKING_IPV6=no

IPV6INIT=no

保存並退出文件,重啓網絡與服務器:

# service network restart

# rmmod ipv6

# reboot

如果想檢查當前IPv6是否已禁用,可以使用下列命令:

# lsmod | grep ipv6

# ifconfig -a


#查看目錄所佔磁盤大小

du -sh

#umount 報 device is busy 的處理方法

fuser -km /datatmp


#停掉SELinux

setenforce 0

getenforce


vi /etc/selinux/config

SELINUX=enfoceing

把其修改爲:

SELINUX=disabled


#網卡漂移

vi /etc/udev/rules.d/70-persistent-net.rules


#生成大文件

dd if=/dev/zero of=file1 bs=1M count=1000


#數據同步

rsync -ae ssh 目錄名/ 192.168.10.2:/usr/local/xx



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章