前言:
当前我们对“centos732位库”大概比较注重,你们都需要分析一些“centos732位库”的相关内容。那么小编在网络上汇集了一些对于“centos732位库””的相关内容,希望你们能喜欢,小伙伴们快快来了解一下吧!版本选择 :php 5.3.14 mysql 5.5.25 nginx 1.2.1
试用阿里云主机512m,配置环境测试
参考:
一、挂载数据盘
可以先测试是否挂载
fdisk -l|grep Disk
df -lh
没有挂载的话,如下做
1. 切换到root;
2. 运行命令 "fdisk /dev/xvdb";
3. 根据提示,依次输入 "n", "p", "1";
4. 然后 ,按两次回车;
5. 输入 "w", 当提示Syncing disks.时,表示已成功完成分区;
6. 输入 "mkfs.ext3 /dev/xvdb1" 格式化分区;这里要耐心等待
7. 输入 "mkdir /data0"建立挂载目录
8. 使用"mount /dev/xvdb1 /data0 "命令挂载分区后即可使用。
9. vi /etc/fstab
按 i
最后一行写入
/dev/xvdb1 /data0 ext3 defaults 0 0
按esc
输入:wq ,回车
操作完毕
二、安装gcc
打开 /etc/yum.conf 然后找到这行:
exclude=kernel*
修改为:
exclude=
安装升级所需程序库
sudo -s
LANG=C
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 ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
三、下载所需程序
mkdir -p /data0/soft
cd /data0/soft
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
wget
四、安装PHP 5.3.14
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure --prefix=/usr/local
make
make install
cd ../
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
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
编译安装MySQL 5.5.25a
tar zxvf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
make
make install
cd ../
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
tar zxvf mysql-5.5.25a.tar.gz
cd mysql-5.5.25a
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql \
-DEXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
make
make intall
chmod +w /usr/local/webserver/mysql
chown -R mysql:mysql /usr/local/webserver/mysql
cd ../
附:以下为附加步骤,如果你想在这台服务器上运行MySQL数据库,则执行以下几步。如果你只是希望让PHP支持MySQL扩展库,能够连接其他服务器上的MySQL数据库,那么,以下两步无需执行。
①、创建MySQL数据库存放目录
mkdir -p /data0/mysql/3306/data/
mkdir -p /data0/mysql/3306/binlog/
mkdir -p /data0/mysql/3306/relaylog/
chown -R mysql:mysql /data0/mysql/
cd /usr/local/webserver/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf
vi /etc/my.cnf #编辑配置文件,在 [mysqld] 部分增加
datadir = /data0/mysql/3306/data #添加MySQL数据库路径
./scripts/mysql_install_db --user=mysql #生成mysql系统数据库
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
chmod 755 /etc/init.d/mysqld #增加执行权限
chkconfig mysqld on #加入开机启动
vi /etc/rc.d/init.d/mysqld #编辑
basedir = /usr/local/webserver/mysql #MySQL程序安装路径
datadir = /data0/mysql/3306/data #MySQl数据库存放目录
service mysqld start #启动
vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/webserver/mysql/bin
下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql
的库文件地址。
ln -s /usr/local/webserver/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/webserver/mysql/include/mysql /usr/include/mysql
重启系统,等待系统重新启动之后继续在终端命令行下面操作
mysql_secure_installation #设置Mysql密码
根据提示按Y 回车输入2次密码
或者直接修改密码/usr/local/webserver/mysql/bin/mysqladmin -u root -p password "123456" #修改
密码
service mysqld restart #重启
到此,mysql安装完成!
通过命令行登录管理MySQL服务器(提示输入密码时直接回车,上处修改密码了的话这里要输入的):
/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock
输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
(可选)停止MySQL:
service mysqld stop
//安装到此截止了,php请看下一章
附:常用mysql命令:
查看用户信息
select user,host,password from mysql.user;
(3)创建数据库
/usr/local/webserver/mysql/bin/mysql -u admin -p -S /tmp/mysql.sock
(注意密码是 12345678)
MySQL>create database blog;
MySQL>flush privileges;
查询用户下的数据库
SHOW DATABASES;
3、编译安装PHP(FastCGI模式)
tar zxvf php-5.3.14.tar.gz
cd php-5.3.14/
ln -s /usr/local/webserver/mysql/lib/libmysqlclient.so /usr/lib/
ln -s /usr/local/webserver/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
./configure --prefix=/usr/local/webserver/php --with-config-file-path=/usr/local/webserver/php/etc --with-mysql=/usr/local/webserver/mysql --with-mysqli=/usr/local/webserver/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 --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/webserver/php/etc/php.ini
cd ../
4、编译安装PHP5扩展模块
tar zxvf memcache-3.0.6.tgz
cd memcache-3.0.6/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1/
/usr/local/webserver/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
tar zxvf PDO_MYSQL-1.0.2.tgz
cd PDO_MYSQL-1.0.2/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-pdo-mysql=/usr/local/webserver/mysql
make
make install
cd ../
tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../
tar zxvf imagick-2.3.0.tgz
cd imagick-2.3.0/
/usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config
make
make install
cd ../
5、修改php.ini
手工修改:查找/usr/local/webserver/php/etc/php.ini中的找到
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = OFF #禁止显示php版本的信息
找到:display_errors = On
修改为:display_errors = OFF #关闭错误提示
6、配置eAccelerator加速PHP:
mkdir -p /usr/local/webserver/eaccelerator_cache
chmod 777 /usr/local/webserver/eaccelerator_cache
vi /usr/local/webserver/php/etc/php.ini
按shift+g键跳到配置文件的最末尾,加上以下配置信息:
引用
[eaccelerator]
zend_extension="/usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/usr/local/webserver/eaccelerator_cache"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
7、创建www用户和组,以及供两个虚拟主机使用的目录:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /data0/htdocs/blog
chmod +w /data0/htdocs/blog
chown -R www:www /data0/htdocs/blog
mkdir -p /data0/htdocs/www
chmod +w /data0/htdocs/www
chown -R www:www /data0/htdocs/www
创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgi)
cp /usr/local/webserver/php/etc/php-fpm.conf.default/usr/local/webserver/php/etc/php-fpm.conf
修改 vi /usr/local/webserver/php/etc/php-fpm.conf
php_flag[display_errors] = off;不显示错误信息
pm.max_children = 32 ;静态方式下开启的php-fpm进程数量,内存小于3g不要超过64
pm.start_servers = 5;动态方式下的起始php-fpm进程数量。
pm.min_spare_servers = 5;动态方式下的最小php-fpm进程数量
pm.max_spare_servers = 30;动态方式下的最大php-fpm进程数量
pm.max_requests = 512
user = www
group = www
pm = dynamic;进程数动态模式不清楚的不要修改
;pm = static;进程数静态模式不清楚的不要修改
pid = run/php-fpm.pid ;取消前面的分号
#检查语法是否正确
/usr/local/webserver/php/sbin/php-fpm -t
#出现NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful 测试成功
启动fpm
/usr/local/php/sbin/php-fpm &
相关命令
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
示例:
php-fpm 关闭:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
查看php-fpm进程数:
ps aux | grep -c php-fpm
三、安装Nginx 0.8.46
1、安装Nginx所需的pcre库:
tar zxvf pcre-8.30.tar.gz
cd pcre-8.30/
./configure
make && make install
cd ../
2、安装Nginx
tar zxvf nginx-1.2.1.tar.gz
cd nginx-1.2.1/
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/data0/soft/pcre-8.30
make && make install
cd ../
3、创建Nginx日志目录
mkdir -p /data0/logs
chmod +w /data0/logs
chown -R www:www /data0/logs
4、创建Nginx配置文件
①、在/usr/local/webserver/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/webserver/nginx/conf/nginx.conf
vi /usr/local/webserver/nginx/conf/nginx.conf
输入以下内容:
引用user www www;
worker_processes 8;
error_log /data0/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
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;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name 42.121.83.101;
index index.html index.htm index.php;
root /data0/htdocs/blog;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
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;
}
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data0/logs/access.log access;
server
{
listen 80;
server_name ;
index index.html index.htm index.php;
root /data0/htdocs/www;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
}
log_format wwwlogs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data0/logs/wwwlogs.log wwwlogs;
server
{
listen 80;
server_name status.blog.s135.com;
location / {
stub_status on;
access_log off;
}
}
}
②、在/usr/local/webserver/nginx/conf/目录中创建fcgi.conf文件:
vi /usr/local/webserver/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;
5、启动Nginx
ulimit -SHn 65535
/usr/local/webserver/nginx/sbin/nginx
#检测配置文件
/usr/local/webserver/nginx/sbin/nginx -t
#提示表示成功
#nginx: the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
#nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test is successful
#开启Nginx
/usr/local/webserver/nginx/sbin/nginx &
#平滑重启Nginx
/usr/local/webserver/nginx/sbin/nginx -s reload
四、配置开机自动启动Nginx + PHP
vi /etc/rc.local
在末尾增加以下内容:
引用
ulimit -SHn 65535
/usr/local/webserver/php/sbin/php-fpm &
/usr/local/webserver/nginx/sbin/nginx
五、优化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
六、在不停止Nginx服务的情况下平滑变更Nginx配置
1、修改/usr/local/webserver/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t
如果屏幕显示以下两行信息,说明配置文件正确:
the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/webserver/nginx/conf/nginx.conf was tested successfully
2、平滑重启:
①、对于Nginx 0.8.x版本,现在平滑重启Nginx配置非常简单,执行以下命令即可:
/usr/local/webserver/nginx/sbin/nginx -s reload
②、对于Nginx 0.8.x之前的版本,平滑重启稍微麻烦一些,按照以下步骤进行即可。输入以下命令
查看Nginx主进程号:
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302
或者无需这么麻烦,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/webserver/nginx/nginx.pid`
七、编写每天定时切割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="/usr/local/webserver/nginx/logs/"mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/webserver/nginx/nginx.pid`
2、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e
输入以下内容:
引用00 00 * * * /bin/bash /usr/local/webserver/nginx/sbin/cut_nginx_log.sh
crontab -l 查看你的定时任务是否加进去了。
标签: #centos732位库