文章主要是根据https://my.oschina.net/ruiorz/blog/604232来写的,基本是抄的,但是也是一步一步操作完成
前提准备
源码均下载到自己的家目录,我自己试验的是下载到 /root 目录
先安装一些基本的扩展,采用yum安装
yum -y install gcc gcc-c++ autoconf cmake 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 gd gd2 gd-devel gd2-devel perl-CPAN bosin
安装mysql
创建用户和用户组
groupadd mysql
useradd -g mysql -s /usr/sbin/nologin mysql
mkdir -p /usr/local/mysql
mkdir -p /data0/mysql/data
mkdir /data0/mysql/logs
chown -R mysql:mysql /data0/mysql/
解释说明
groupadd mysql 新建mysql用户组,便于管理mysql
useradd -g mysql -s /usr/sbin/nologin mysql 创建mysql用户,并设置不能用该用户登录服务器
mkdir -p /usr/local/mysql 创建mysql的安装目录
mkdir -p /data0/mysql/data 创建mysql数据存储目录
mkdir /data0/mysql/logs 创建mysql的日志目录
chown -R mysql:mysql /data0/mysql/ 修改mysql目录的所有者为mysql用户
下载mysql源码并进行编译安装
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz
可以选择其它的版本,自行选择,其它版本镜像地址为 http://mirrors.sohu.com/mysql/
下载完成后
tar zxvf mysql-5.6.35.tar.gz
cd mysql-5.6.35/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data0/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
参数说明如下
tar zxvf mysql-5.6.35.tar.gz 对mysql源码解压
cd mysql-5.6.35/ 跳转到mysql文件中
cmake \ 对其进行cmake编译
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ 参数:mysql的安装位置
-DMYSQL_DATADIR=/data0/mysql/data \ 参数:mysql数据库的安装位置
-DSYSCONFDIR=/etc \ 参数:mysql的配置文件位置
-DWITH_MYISAM_STORAGE_ENGINE=1 \ 参数:开启myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ 参数:开启innodb存储引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 \ 参数:开启memory存储引擎
-DWITH_READLINE=1 \ 参数:
-DMYSQL_TCP_PORT=3306 \ 参数:端口号
-DENABLED_LOCAL_INFILE=1 \ 参数:
-DWITH_PARTITION_STORAGE_ENGINE=1 \ 参数:
-DEXTRA_CHARSETS=all \ 参数:
-DDEFAULT_CHARSET=utf8 \ 参数:默认字符集
-DDEFAULT_COLLATION=utf8_general_ci 参数:默认字段字符
make && make install
详细的参数说明可以查看这篇博客 http://blog.51cto.com/laowafang/1294964#a4
编译完成后若有warning Bison ,则 yum install bison
再进行重新 编译
想删除以前的编译 , 删除 源码目录中的CMakeCache.txt 即可
配置mysql开机自启动
cp ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
cp ./support-files/mysql.server /etc/init.d/mysqld 复制mysql服务端的启动文件到init.d中
chmod +x /etc/init.d/mysqld 给与改文件的可执行权限
chkconfig --add mysqld 添加mysql服务
chkconfig mysqld on 开启mysql服务
增加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
ln -sv /usr/local/mysql/bin/mysql /usr/sbin/mysql 把mysql服务程序加入到sbin中
ln -sv /usr/local/mysql/bin/mysqladmin /usr/sbin/mysqladmin 把mysqladmin服务加入到sbin中
ln -sv /usr/local/mysql/bin/mysqldump /usr/sbin/mysqldump 把mysqldump加入到sbin中
修改mysql配置文件
注意:此时我们现在在mysql目录中
cp ./support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
# 输入以下内容(可以先清空默认内容):
[mysqld]
datadir=/data0/mysql/data
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/data0/mysql/logs/mysqld.log
pid-file=/data0/mysql/mysqld.pid
user=mysql
tmpdir=/tmp
cp ./support-files/my-default.cnf /etc/my.cnf 复制mysq的配置文件到/etc/目录中
vi /etc/my.cnf 对/etc/my.cnf进行编辑
# 输入以下内容(可以先清空默认内容)
[mysqld]
datadir=/data0/mysql/data 设置mysql的数据库路径
socket=/tmp/mysql.sock 设置mysql的sock路径
user=mysql 设置用户
symbolic-links=0
[mysqld_safe]
log-error=/data0/mysql/logs/mysqld.log 设置错误日志
pid-file=/data0/mysql/mysqld.pid
user=mysql 设置用户
tmpdir=/tmp 设置临时目录
初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data0/mysql/data
启动mysql
service mysqld start
若出现错误
Starting MySQL.180203 01:23:50 mysqld_safe error: log-error set to '/data0/mysql/logs/mysqld.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/data0/mysql/data/bogon.pid).
说明mysql用户没有写权限 , 我感觉这个问题应该从权限方面去考虑,但是手动在/data0/mysql/logs/ 创建一个mysqld.log也行,要加上mysql用户/组的权限.这个问题的根源没找到
chown -R mysql:mysql /data0/mysql/logs
vim /data0/mysql/logs/mysqld.log
进入mysql
mysql 回车即可
创建新的mysql用户
输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY '12345678'; #这句可以创建一个允许远程访问的账户
DELETE FROM user WHERE User!='admin'; #删除原先默认的用户,仅保留新建的admin用户(这招狠吧,连root用户都删了)
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY '12345678'; mysql授权给admin,带密码
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY '12345678';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY '12345678'; #这句可以创建一个允许远程访问的账户
DELETE FROM user WHERE User!='admin'; #删除原先默认的用户,仅保留新建的admin用户(这招狠吧,连root用户都删了) 删除其它用户,不建议,但是要给root用户设置密码
好了,mysql成功安装完成 ^_^
安装nginx
添加用户和组,创建网站目录
groupadd www
useradd -g www -s /usr/sbin/nologin www
mkdir -p /data0/htdocs/www
chmod +w /data0/htdocs/www
chown -R www:www /data0/htdocs/
groupadd www 新增www组
useradd -g www -s /usr/sbin/nologin www 新增www用户,这只不能用该用户登录系统
mkdir -p /data0/htdocs/www 新建www目录作为站点目录
chmod +w /data0/htdocs/www 新增www目录权限
chown -R www:www /data0/htdocs/ 修改www目录所属组和所有者
下载tengine 并编译安装
下载nginx所需要的库
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
tar zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install
ln -s /usr/local/lib/libpcre.so.1 /usr/lib64/libpcre.so.1
cd ..
tar zxvf pcre-8.33.tar.gz 解压安装包
cd pcre-8.33 跳转到文件中
./configure 编译
make && make install 安装
ln -s /usr/local/lib/libpcre.so.1 /usr/lib64/libpcre.so.1 创建软连接成公共库,若已存在就不用创建了
cd ..
还回到家目录中,下载tnginx源码包
刚开始看着片文章的时候装的是nginx,后来了解到tengine也不错,所以这次装tengine,编译参数有一个区别
wget http://tengine.taobao.org/download/tengine-2.2.2.tar.gz
若是安装nginx直接下载nginx wget http://mirrors.sohu.com/nginx/nginx-1.9.9.tar.gz
tar zxvf tengine-2.2.2.tar.gz
cd tengine-2.2.2
./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 --with-http_concat_module
make && make install
cd ..
tar zxvf tengine-2.1.2.tar.gz 解压tengine文件
cd tengine-2.1.2
./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 --with-http_concat_module
make && make install 若是nginx 不需要这个参数 --with-http_concat_module
)
cd ..
创建nginx日志记录
mkdir -p /data0/logs
chmod +w /data0/logs
chown -R www:www /data0/logs
mkdir -p /data0/logs 创建nginx日志文件
chmod +w /data0/logs 给改文件读的权限
chown -R www:www /data0/logs 修改logs目录的组和用户
创建nginx的配置文件,在/usr/local/nginx/conf/目录中创建nginx.conf文件:
rm -f /usr/local/nginx/conf/nginx.conf
vim /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 /data0/logs/nginx_error.log crit;
#pid /usr/local/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;
include /usr/local/nginx/conf/sites-enabled/*;
}
user www www; 用户和组
worker_processes 4; 子进程数
error_log /data0/logs/nginx_error.log crit; 错误日志目录
#pid /usr/local/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 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;
include /usr/local/nginx/conf/sites-enabled/*; 包含虚拟机配置
}
新建sites-available目录专门存放虚拟网站配置,创建sites-enabled目录专门存放正在使用的网站配置
mkdir /usr/local/nginx/conf/sites-available
mkdir /usr/local/nginx/conf/sites-enabled
mkdir /usr/local/nginx/conf/sites-available 新建站点配置文件目录
mkdir /usr/local/nginx/conf/sites-enabled 同上
新建www网站配置文件,vi /usr/local/nginx/conf/sites-available/www ,输入以下内容:
server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /data0/htdocs/www;
access_log /data0/logs/www_access.log;
#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 /usr/local/nginx/conf/fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
server
{
listen 80; 监听端口
server_name localhost; server名称
index index.html index.htm index.php; 默认页面类型
root /data0/htdocs/www; 站点根目录
access_log /data0/logs/www_access.log; 权限
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$ rewrite规则
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
vim /usr/local/nginx/conf/fcgi.conf,并输入下面内容:(配置fcgi信息)
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;
fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi的一些参数配置,具体我也不太懂
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;
发布sites-available里的www网站:
ln -s /usr/local/nginx/conf/sites-available/www /usr/local/nginx/conf/sites-enabled/www
ln -s /usr/local/nginx/conf/sites-available/www /usr/local/nginx/conf/sites-enabled/www 建立软链到sites-enabled中
启动nginx
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx
ulimit -SHn 65535 修改最大的连接数,临时修改,重启后会失效
/usr/local/nginx/sbin/nginx 启动nginx
修改最大的连接数 优化nginx
https://www.cnblogs.com/yuanzai12345/p/5951860.html
centos中如下设置
在/etc/security/limits.conf 最后增加:
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
安装php
安装php所需要的依赖包
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.9.2.tar.gz
wget https://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget https://jaist.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget https://jaist.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
编译安装依赖包
tar zxvf libiconv-1.9.2.tar.gz
cd libiconv-1.9.2
./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 ../
# 对共享库做符号链接
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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
安装php
下载php
wget http://am1.php.net/distributions/php-5.6.31.tar.gz
可以选择其它版本
进行安装
tar zxvf php-5.6.31.tar.gz
cd php-5.6.31
./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 --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr \
--enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
--with-curl --enable-mbregex --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-opcache --without-pear --disable-fileinfo
#注:如果内存较大 可以去掉--disable-fileinfo
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
cd ../
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
tar zxvf php-5.5.31.tar.gz
cd php-5.5.31
./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 --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr \
--enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \
--with-curl --enable-mbregex --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-opcache --without-pear --disable-fileinfo
#注:如果内存较大 可以去掉--disable-fileinfo
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini 复制php的配置文件
cd ../
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 复制php-fpm配置文件
vi /usr/local/php/etc/php-fpm.conf 编辑php-fpm文件
修改 /usr/local/php/etc/php-fpm.conf
修改
user = nobody
group = nobody
为
user = www
group = www
# 将;pid = run/php-fpm.pid前的;去掉并修改为
pid = /usr/local/php/var/run/php-fpm.pid
启动php-fpm
/usr/local/php/sbin/php-fpm
将nginx和php-fpm加入自启动
vi /etc/rc.local
# 输入
ulimit -SHn 65535
/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx
编译安装php扩展模块memcache,redis,pdo_mysql,imagick
以前装扩展感觉好难,看了这篇教程后感觉真是简单啊,整体来说就是下载扩展,phpize一下,然后编译安装就好了,特简单
wget http://pecl.php.net/get/memcache-3.0.8.tgz
wget http://download.redis.io/releases/redis-3.2.9.tar.gz redis源码
http://pecl.php.net/package/redis
wget http://pecl.php.net/get/redis-3.1.6.tgz php-redis扩展
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
http://www.imagemagick.org/download/
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-3.4.3.tgz
以后再装扩展可以直接在pecl.php.net直接搜,下载,按照下面的安装方法就好了
好的,先下载所需要的包
开始安装
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
make
make install
cd ../
tar zxvf redis-3.1.6.tgz
cd redis-3.1.6
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
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-7.0.7-26/
./configure
make
make install
cd ../
tar zxvf imagick-3.4.3.tgz
cd imagick-3.4.3
/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配置文件php.ini
vi /usr/local/php/etc/php.ini
#在最后一行加入以下
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"
extension=memcache.so
extension=redis.so
extension=pdo_mysql.so
extension=imagick.so
zend_extension=opcache.so
[opcache]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1
vi /usr/local/php/etc/php.ini 编辑php的配置文件
#在最后一行加入以下
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/" 这个地址一定要根据自己的实际扩展目录来写,可能会不一样
extension=memcache.so 增加memcache扩展
extension=redis.so 增加redis扩展
extension=pdo_mysql.so 增加pdo扩展
extension=imagick.so
zend_extension=opcache.so
[opcache]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1
执行下面的命令使其立即生效
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
好了,这个时候基本安装完成
在/data0/htdocs/www/下新建一个index.php,里面输出phpinfo(),访问ip观察扩展信息
或者直接在服务器 输入下面命令 curl 127.0.0.1
但是我在启动的时候碰到一个问题,就是nginx成功启动了,但是确无法访问项目,127.0.0.1拒绝连接,这个原因可能是端口号被限制的问题
我是一通乱搞,不知怎么的又好了,我就修改了防火墙
首先我准备在/etc/sysconfig/iptables 添加一条防火墙规则,但是很悲催的发现我的centos7并没有这个文件
所以我根据下面这个教程修改了下
http://blog.csdn.net/csdn_lqr/article/details/53885808
再重新启动就好了,中间我又看了看nginx的配置问题,我想应该不是nginx的问题吧
安装redis
正在高兴的感觉安装好所有的扩展的时候,突然想到怎么启动redis啊,好吧,原来我只是安装了php的相应扩展,但是还没有安装redis服务呢
首先回到/root/目录
下载redis http://download.redis.io/releases/
选一个版本 wget http://download.redis.io/releases/redis-3.2.0.tar.gz
tar zxvf redis-3.2.0.tar.gz
cd redis-3.2.0
make && make install
安装完成后没有什么问题
会在/usr/local/bin目录下生成下面几个可执行文件,它们的作用分别是:
redis-server:Redis服务器端启动程序
redis-cli:Redis客户端操作工具。也可以用telnet根据其纯文本协议来操作
redis-benchmark:Redis性能测试工具
redis-check-aof:数据修复工具
redis-check-dump:检查导出工具
下面进行配置redis
复制配置文件 redis.conf 目录到/etc/目录中
cp redis.conf /etc/
vim /etc/redis.conf
对配置文件进行编辑(使redis能够在后台运行)
daemonize yes配置成系统服务
把redis配置成系统服务
cp /root/redis-3.2.0/utils/redis_init_script /etc/init.d/redis
注意修改配置文件路径和pid路径
这一步我没有成功,连接失败....纠结
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Redis stopped
不过可以把命令写入开机自启配置
echo "/usr/local/bin/redis-server /etc/redis.conf" >>/etc/rc.local
其它优化
配置php环境变量
先找到自己的php的bin目录
vim /etc/profile
在末尾添加
PATH=$PATH:/usr/local/php/bin/
export PATH
保存退出 :wq
source /etc/profile
优化linux内核参数
vi /etc/sysctl.conf
在文件末尾添加下面的内容
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
修改php.ini的时区
vi /usr/local/php/etc/php.ini
#找到;date.timezone =
去掉前面的分号并改为date.timezone = Asia/Chongqing
常用命令
#修改完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)
#启动redis命令
/usr/local/bin/redis-server /etc/redis.conf