Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.0 + Mariadb 10.1.9 + Nginx 1.9.9 + PHP 7.0.2) 环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1503-01.iso
1.1 主机名设置 当前主机名查看 [root@centos ~]# hostname 主机名设置 [root@centos ~]# hostnamectl --static set-hostname tCentos [root@centos ~]# service network restart [root@centos ~]# hostname tCentos
1.2 设置静态IP、DNS地址(网络设备名称有可能不一样,这里是eno16780032,如使用DHCP获取动态IP,可忽略) [root@centos ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16780032 找到BOOTPROTO,并且修改(设为静态网址) BOOTPROTO="static" 在最后添加三行内容(添加IP,子网掩码,网关)
IPADDR="192.168.1.117" :wq 保存退出
添加以下几个DNS地址
nameserver 114.114.114.114 :wq 保存退出
[root@centos ~]# ip addr|grep inet
inet 127.0.0.1/8 scope host lo
1.4 安装基本软件包 [root@centos ~]# yum install vim wget lsof gcc gcc-c++ bzip2 -y [root@centos ~]# yum install net-tools bind-utils -y [root@centos ~]# yum install firewalld -y
[root@centos ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup [root@centos ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@centos ~]# yum makecache [root@centos ~]# yum update -y 更新完成后重启,查看内核版本 [root@centos ~]# shutdown -r now [root@centos ~]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) [root@centos ~]# uname -a Linux centos 3.10.0-229.20.1.el7.x86_64 #1 SMP Tue Nov 3 19:10:07 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
1.6 关闭selinux (如不关闭,有时会添加不了用户,或者重启后没法开机) [root@centos ~]# vim /etc/selinux/config 屏蔽以下两行 #SELINUX=enforcing #SELINUXTYPE=targeted 添加以下一行 SELINUXTYPE=disabled 保存,退出
[root@centos ~]# shutdown -r now [root@centos ~]# getenforce Disabled
1.7.1 在客户机生成对称密钥 ssh-keygen -t rsa
创建目录 [root@centos ~]# mkdir -p /root/.ssh 使用软件远程复制id_rsa.pub到服务器/root/.ssh中。
[root@centos ~]# ll /root/.ssh 导入密钥到authorized_keys [root@centos ~]# cat id_rsa.pub >> authorized_keys
[root@centos ~]# ll /root/.ssh 导入后,删除公钥文件 [root@centos ~]# rm id_rsa.pub
[root@centos ~]# vim /etc/ssh/sshd_config 找到GSSAPICleanupCredentials,并且修改为以下内容 GSSAPICleanupCredentials yes :wq 保存退出
[root@centos ~]# systemctl restart sshd
打开软件 PuTTYgen 点击load 选择之前客户机生成私钥文件id_rsa, 点击save private key 生成 pKey.ppk文件 打开软件 PuTTY 点击Session,在HostName(or IP address)输入服务器地址 点击Connection下的DATA,在Auto-login username中输入登录账号(当前账号为root) 点击Connection下的SSH下的Auth,点击Browse 选择之前生成 pKeyppk文件 点击Session,在Saved Sessions中,输入需要保存的Session名称,点击保存
打开软件 PuTTY 点击Session,在"Default Settings"下,找到之前已经保存的Session,双击打开连接 如果显示 Authenticating with public key "xxxxx-xxxx"时,即表未成功
[root@centos ~]# cd /usr/local/src [root@centos ~]# wget https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz [root@centos ~]# wget http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz [root@centos ~]# wget https://github.com/jemalloc/jemalloc/releases/download/4.0.4/jemalloc-4.0.4.tar.bz2 [root@centos ~]# wget https://downloads.mariadb.org/f/mariadb-10.1.9/source/mariadb-10.1.9.tar.gz [root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz [root@centos ~]# wget https://www.openssl.org/source/openssl-1.0.2e.tar.gz [root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@centos ~]# wget http://nginx.org/download/nginx-1.9.9.tar.gz [root@centos ~]# wget http://am1.php.net/get/php-7.0.2.tar.gz [root@centos ~]# wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz [root@centos ~]# wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz [root@centos ~]# wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz [root@centos ~]# wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz [root@centos ~]# wget http://pecl.php.net/get/zendopcache-7.0.5.tgz [root@centos ~]# wget http://xdebug.org/files/xdebug-2.4.0rc3.tgz [root@centos ~]# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz [root@centos ~]# wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz 查看是否已经需要的包是否下载完成(如下载地址失效,需另外下载并上传到服务器) [root@centos ~]# ll /usr/local/src
2.1 安装依赖 [root@centos ~]# yum install ncurses-devel openssl* bzip2 m4 -y
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget https://cmake.org/files/v3.4/cmake-3.4.1.tar.gz [root@centos ~]# tar zvxf cmake-3.4.1.tar.gz [root@centos ~]# cd cmake-3.4.1 [root@centos ~]# ./bootstrap && make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz [root@centos ~]# tar zvxf bison-3.0.4.tar.gz [root@centos ~]# cd bison-3.0.4 [root@centos ~]# ./configure && make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget https://github.com/jemalloc/jemalloc/releases/download/4.0.4/jemalloc-4.0.4.tar.bz2 [root@centos ~]# tar xjf jemalloc-4.0.4.tar.bz2 [root@centos ~]# cd jemalloc-4.0.4 [root@centos ~]# ./configure && make && make install [root@centos ~]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf [root@centos ~]# ldconfig
2.5 安装libevent [root@centos ~]# cd /usr/local/src [root@centos ~]# wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz [root@centos ~]# tar zvxf libevent-2.0.22-stable.tar.gz [root@centos ~]# cd libevent-2.0.22-stable [root@centos ~]# ./configure --prefix=/usr [root@centos ~]# make && make install
如果libevent的lib目录不在LD_LIBRARY_PATH里,可以使用以下命令加入 [root@centos ~]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr
[root@centos ~]# groupadd mysql [root@centos ~]# useradd -g mysql mysql -s /sbin/nologin [root@centos ~]# mkdir -p /data/mysql [root@centos ~]# chown -R mysql:mysql /data/mysql
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget https://downloads.mariadb.org/f/mariadb-10.1.9/source/mariadb-10.1.9.tar.gz [root@centos ~]# tar zvxf mariadb-10.1.9.tar.gz [root@centos ~]# cd mariadb-10.1.9
[root@centos ~]# cmake \ [root@centos ~]# make && make install
[root@centos ~]# ln -s /opt/mysql/lib/lib* /usr/lib/ [root@centos ~]# ln -s /opt/mysql/bin/mysql /bin
[root@centos ~]# cp ./support-files/my-large.cnf /etc/my.cnf [root@centos ~]# vim /etc/my.cnf 在[client]下添加以下内容 default-character-set = utf8 在[mysqld]下添加以下内容
datadir = /data/mysql :wq 保存退出
[root@centos ~]# cd /opt/mysql [root@centos ~]# ./bin/mysql_install_db --basedir=/opt/mysql --datadir=/data/mysql --user=mysql [root@centos ~]# ./bin/mysqld_safe --datadir=/data/mysql 确认运行后,按可以按CTRL+Z结束 [root@centos ~]# ps -ef|grep mysqld [root@centos ~]# lsof -n | grep jemalloc
[root@centos ~]# ./bin/mysql_secure_installation
[root@centos ~]# mysql -u root -p Mysql [(none)]>status; Mysql [(none)]>show engines; Mysql [(none)]>exit;
[root@centos ~]# vim /etc/systemd/system/mysqld.service 录入以下内容
[Unit]
[Install]
[Service]
# Execute pre and post scripts as root # Needed to create system tables etc.
# Start main service # Don't signal startup success before a ping works
# Give up if ping don't get an answer
Restart=always
[root@centos ~]# systemctl list-unit-files|grep enabled|grep mysql [root@centos ~]# systemctl daemon-reload
[root@centos ~]# shutdown -r now [root@centos ~]# systemctl start mysqld.service [root@centos ~]# systemctl status mysqld.service -l [root@centos ~]# ps -ef|grep mysqld [root@centos ~]# lsof -n | grep jemalloc
[root@centos ~]# mysql -u root -p Mysql [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Mysql [(none)]> FLUSH PRIVILEGES; Mysql [(none)]> exit; (root是用户名,%是主机名或IP地址,这里的%代表任意主机或IP地址,也可指定唯一的IP地址;密码是MyPassword )
[root@centos ~]# iptables -L|grep ACCEPT [root@centos ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent [root@centos ~]# firewall-cmd --reload [root@centos ~]# iptables -L|grep ACCEPT
3.编译安装Nginx 3.1安装依赖 [root@centos ~]# yum install zlib-devel openssl-devel -y
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz [root@centos ~]# tar zvxf pcre-8.38.tar.gz [root@centos ~]# cd pcre-8.38 [root@centos ~]# ./configure && make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@centos ~]# tar zvxf zlib-1.2.8.tar.gz [root@centos ~]# cd zlib-1.2.8 [root@centos ~]# ./configure && make && make install
[root@centos ~]# openssl version [root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget https://www.openssl.org/source/openssl-1.0.2e.tar.gz [root@centos ~]# tar zvxf openssl-1.0.2e.tar.gz [root@centos ~]# cd openssl-1.0.2e [root@centos ~]# ./config shared zlib --prefix=/usr [root@centos ~]# make && make install
[root@centos ~]# mv /usr/bin/openssl /usr/bin/openssl_bak [root@centos ~]# mv /usr/include/openssl/ /usr/include/openssl_bak [root@centos ~]# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl [root@centos ~]# ln -s /usr/local/ssl/include/openssl/ /usr/include/openssl [root@centos ~]# echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
[root@centos ~]# ldconfig -v | grep ssl [root@centos ~]# openssl version
3.6 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限 [root@centos ~]# groupadd www [root@centos ~]# useradd -g www www -s /sbin/nologin [root@centos ~]# mkdir -p /data/www/web [root@centos ~]# chmod +w /data/www/web [root@centos ~]# chown -R www:www /data/www/web
***如果没法创建用户,需要检查SELinux状态是否关闭 3.7 安装nginx [root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://nginx.org/download/nginx-1.9.9.tar.gz [root@centos ~]# tar zvxf nginx-1.9.9.tar.gz [root@centos ~]# cd nginx-1.9.9
[root@centos ~]# ./configure --prefix=/opt/nginx \ [root@centos ~]# make && make install
修改 nginx.conf [root@centos ~]# vim /opt/nginx/conf/nginx.conf
user www www; worker_processes auto; error_log logs/error.log crit; pid logs/nginx.pid;
events{
:wq 保存退出
* 如果需要支持http2,参考以下设置(需要https证书,并且OpenSSL 1.0.2+) server { listen 443 ssl http2; ssl_certificate server.crt; ssl_certificate_key server.key; ... } * 完成后,可以在浏览器中,打开此网站,查看是否已经支持http2 chrome://net-internals/#http2
3.9 建立测试首页 [root@centos ~]# vim /data/www/web/index.html
<html> 保存,退出
[root@centos ~]# cd /opt/nginx [root@centos ~]# ldconfig [root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf -t 如果显示下面信息,即表示配置没问题
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
[root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf [root@centos ~]# lsof -n | grep jemalloc
ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
[root@centos ~]# iptables -L|grep ACCEPT [root@centos ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent [root@centos ~]# firewall-cmd --reload [root@centos ~]# iptables -L|grep ACCEPT
3.12 浏览器打开 http://192.168.1.117 显示出欢迎内容,则表示成功
3.13 作为服务,开机后启动 [root@centos ~]# vim /etc/systemd/system/nginx.service 增加以下内容
[Unit]
[Service]
[Install] :wq 保存退出
[root@centos ~]# systemctl list-unit-files|grep enabled|grep nginx
[root@centos ~]# ./sbin/nginx -s stop [root@centos ~]# systemctl daemon-reload [root@centos ~]# systemctl start nginx.service [root@centos ~]# systemctl status nginx.service -l [root@centos ~]# ps -ef|grep nginx [root@centos ~]# lsof -n | grep jemalloc
4 安装PHP 4.1 更新依赖 [root@centos ~]# yum install 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 libXpm* gcc gcc-c++ -y
[root@centos ~]# cd /usr/local/src [root@centos ~]# wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz [root@centos ~]# tar zvxf libiconv-1.14.tar.gz [root@centos ~]# cd libiconv-1.14 [root@centos ~]# ./configure --prefix=/usr/local [root@centos ~]# cd srclib [root@centos ~]# sed -i -e '/gets is a security/d' ./stdio.in.h [root@centos ~]# cd .. [root@centos ~]# make && make install [root@centos ~]# ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/ [root@centos ~]# ldconfig
4.4 安装libmcrypt,libltdl(加密算法库,PHP扩展mcrypt功能对此库有依耐关系,要使用mcrypt必须先安装此库) [root@centos ~]# cd /usr/local/src [root@centos ~]# wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz [root@centos ~]# tar zvxf libmcrypt-2.5.8.tar.gz [root@centos ~]# cd libmcrypt-2.5.8 [root@centos ~]# ./configure && make && make install [root@centos ~]# cd libltdl/ [root@centos ~]# ./configure --enable-ltdl-install [root@centos ~]# make && make install [root@centos ~]# ln -sf /usr/local/lib/libmcrypt.* /usr/lib64/ [root@centos ~]# ln -sf /usr/local/bin/libmcrypt-config /usr/lib64/ [root@centos ~]# ldconfig
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz [root@centos ~]# tar zvxf mhash-0.9.9.9.tar.gz [root@centos ~]# cd mhash-0.9.9.9 [root@centos ~]# ./configure && make && make install [root@centos ~]# ln -sf /usr/local/lib/libmhash.* /usr/lib64/ [root@centos ~]# ldconfig
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz [root@centos ~]# tar zvxf mcrypt-2.6.8.tar.gz [root@centos ~]# cd mcrypt-2.6.8 [root@centos ~]# ./configure && make && make install
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://sourceforge.net/projects/re2c/files/0.15.3/re2c-0.15.3.tar.gz [root@centos ~]# tar zvxf re2c-0.15.3.tar.gz [root@centos ~]# cd re2c-0.15.3 [root@centos ~]# ./configure && make && make install
4.7.1 创建mysql软连接、ldap软连接 [root@centos ~]# mkdir -p /opt/mysql/include/mysql [root@centos ~]# ln -s /opt/mysql/include/* /opt/mysql/include/mysql/ [root@centos ~]# ln -s /usr/lib64/libldap* /usr/lib [root@centos ~]# ln -s /usr/lib64/liblber* /usr/lib
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://am1.php.net/distributions/php-7.0.2.tar.gz [root@centos ~]# tar zvxf php-7.0.2.tar.gz [root@centos ~]# cd php-7.0.2
[root@centos ~]# ./configure \ [root@centos ~]# make ZEND_EXTRA_LIBS='-liconv' [root@centos ~]# make install
[root@centos ~]# cp php.ini-production /opt/php/etc/php.ini
[root@centos ~]# sysctl vm.nr_hugepages=512 [root@centos ~]# cat /proc/meminfo | grep Huge
AnonHugePages: 106496 kB
4.7.5 修改php配置文件,支持ZendOpcache [root@centos ~]# ll /opt/php/lib/php/extensions/no-debug-non-zts-20151012 [root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的内容) extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20151012/"
zend_extension="opcache.so" :wq 保存退出
4.7.6 修改php配置文件,支持pdo_mysql,mysqli [root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行) extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20151012/"
extension = "pdo_mysql.so" :wq 保存退出
[root@centos ~]# cd /usr/local/src/ [root@centos ~]# wget http://xdebug.org/files/xdebug-2.4.0rc3.tgz [root@centos ~]# tar zvxf xdebug-2.4.0rc3.tgz [root@centos ~]# cd xdebug-2.4.0RC3 [root@centos ~]# /opt/php/bin/phpize [root@centos ~]# ./configure --enable-xdebug --with-php-config=/opt/php/bin/php-config [root@centos ~]# make && make install
[root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行) extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20151012/"
[xdebug] :wq 保存退出
4.7.8 安装memcahced扩展 (需要 libmemcached 库) [root@centos ~]# cd /usr/local/src [root@centos ~]# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz [root@centos ~]# tar zvxf libmemcached-1.0.18.tar.gz [root@centos ~]# cd libmemcached-1.0.18 [root@centos ~]# ./configure --with-memcached --prefix=/opt/libmemcached [root@centos ~]# make && make install
[root@centos ~]# cd /usr/local/src [root@centos ~]# yum install git [root@centos ~]# git clone https://github.com/rlerdorf/php-memcached.git [root@centos ~]# cd php-memcached [root@centos ~]# git checkout php7 [root@centos ~]# /opt/php/bin/phpize [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config --with-libmemcached-dir=/opt/libmemcached [root@centos ~]# make && make install [root@centos ~]# ll /opt/php/lib/php/extensions/no-debug-non-zts-20151012/
[root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行) extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20151012/" extension = "memcached.so"
4.7.9 安装redis扩展 [root@centos ~]# cd /usr/local/src [root@centos ~]# yum install git [root@centos ~]# git clone https://github.com/phpredis/phpredis/ [root@centos ~]# cd phpredis [root@centos ~]# git checkout php7 [root@centos ~]# /opt/php/bin/phpize [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config [root@centos ~]# make && make install [root@centos ~]# ll /opt/php/lib/php/extensions/no-debug-non-zts-20151012/
[root@centos ~]# vim /opt/php/etc/php.ini 在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行) extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20151012/" extension = "redis.so"
4.7.10 安装php-fpm [root@centos ~]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf [root@centos ~]# cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/web.conf [root@centos ~]# vim /opt/php/etc/php-fpm.conf
[global] error_log = log/php-fpm.log emergency_restart_threshold = 10 emergency_restart_interval = 1m process_control_timeout = 5s :wq 保存退出
修改内容,并且让其它生效 user = www group = www pm.max_children = 35 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 :wq 保存退出
# pid = run/php-fpm.pid
# error_log = log/php-fpm.log
# log_level = notice
# emergency_restart_threshold = 60
# process_control_timeout = 0
# listen = 127.0.0.1:9000
# listen.backlog = -1
# listen.allowed_clients = 127.0.0.1
# listen.owner = www
# user = www
# pm = dynamic #对于专用服务器,pm可以设置为static。
# pm.max_requests = 1000
# pm.status_path = /status
# ping.path = /ping
# ping.response = pong
# request_terminate_timeout = 0
# request_slowlog_timeout = 10s
# slowlog = log/$pool.log.slow
# rlimit_files = 1024
# rlimit_core = 0
# chroot =
# chdir =
# catch_workers_output = yes
[root@centos ~]# mkdir -p /opt/nginx/conf/vhosts [root@centos ~]# vim /opt/nginx/conf/nginx.conf 删除原来内容,替换成以下内容: user www www; worker_processes auto; error_log logs/error.log crit; pid logs/nginx.pid;
events {
http {
# log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # access_log logs/access.log main;
sendfile on;
# keepalive_timeout 0; # gzip on;
include /opt/nginx/conf/vhosts/*.conf; :wq 保存退出
[root@centos ~]# vim /opt/nginx/conf/vhosts/web.conf 添加以下内容
server { root /data/www/web;
location / {
# for bowers thinkphp without /index.php path
# for thinkphp pathinfo mode :wq 保存退出 4.7.12 将php-fpm服务加到开机启动服务 [root@centos ~]# cp /usr/local/src/php-7.0.2/sapi/fpm/php-fpm.service /etc/systemd/system/ [root@centos ~]# vim /etc/systemd/system/php-fpm.service 删除原来内容,替换成以下内容
[Unit]
[Service]
[Install] 保存,退出
[root@centos ~]# systemctl list-unit-files|grep enabled|grep php-fpm [root@centos ~]# systemctl daemon-reload [root@centos ~]# systemctl start php-fpm.service [root@centos ~]# systemctl status php-fpm.service -l
[root@centos ~]# mkdir -p /data/www/web [root@centos ~]# vim /data/www/web/index.php 输入以下内容
<html> :wq 保存退出
[root@centos ~]# systemctl restart php-fpm 浏览器访问:http://192.168.1.117/index.php
5 安装memcached服务 5.1 安装memcached (需要libevent库) [root@centos ~]# cd /usr/local/src [root@centos ~]# wget http://www.memcached.org/files/memcached-1.4.25.tar.gz [root@centos ~]# tar zvxf memcached-1.4.25.tar.gz [root@centos ~]# cd memcached-1.4.25 [root@centos ~]# ./configure --prefix=/opt/memcached --with-libevent=/usr [root@centos ~]# make && make install
[root@centos ~]# groupadd memcached [root@centos ~]# useradd -g memcached memcached -s /sbin/nologin [root@centos ~]# vim /etc/sysconfig/memcached 添加以下内容
PORT="11211" :wq 保存退出
添加以下内容
[Unit]
[Service]
[Install]
[root@centos ~]# systemctl list-unit-files|grep enabled|grep memcached [root@centos ~]# systemctl daemon-reload [root@centos ~]# systemctl start memcached.service [root@centos ~]# systemctl status memcached.service -l
[root@centos ~]# iptables -L|grep ACCEPT [root@centos ~]# firewall-cmd --zone=public --add-port=11211/tcp --permanent [root@centos ~]# firewall-cmd --reload [root@centos ~]# iptables -L|grep ACCEPT
[root@centos ~]# vim /data/www/web/m.php 添加以下内容
<?php
$mem = new Memcached; $val=$mem->get('test');
echo $val; :wq 保存退出
浏览器访问:http://192.168.1.117/m.php |