分别部署三个服务
一.安装Nginx
1.nginx的编译安装部署
1 yum install -y pcre-devel openssl-devel #用本地yum仓库安装依赖包
2 wget -q http://nginx.org/download/nginx-1.10.2.tar.gz #下载软件源码包
3 useradd -s /sbin/nologin -M www #创建程序用户
4 tar xf nginx-1.10.2.tar.gz -C /usr/src/ #解压缩
5 cd /usr/src/nginx-1.10.2
6 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module #预配置
7 make && make install #编译和安装
8 ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ #给命令做软连接,以便PATH能找到
9 /usr/local/nginx/sbin/nginx #启动nginx
特别提示:
/usr/local/nginx/sbin/nginx -s reload
nginx平滑重启命令
/usr/local/nginx/sbin/nginx -s stop
nginx停止服务命令
2.Nginx主配置文件nginx.conf
1 egrep -v "#|^$" nginx.conf #去掉包含#号和空行的内容 2 worker_processes 1; #worker进程的数量 3 error_log logs/error.log; #错误日志(默认没开) 4 pid logs/nginx.pid; #进程号(默认没开) 5 events { #事件区块开始 6 worker_connections 1024; #每个worker进程支持的最大连接数 7 } #事件区块结束 8 http { #http区块开始 9 include mime.types; #Nginx支持的媒体类型库文件包含 10 default_type application/octet-stream; #默认的媒体类型 11 sendfile on; #开启高效传输模式 12 keepalive_timeout 65; #连接超时。 13 server { #网站配置区域(第一个server第一个虚拟主机站点) 14 listen 80; #提供服务的端口,默认80 15 server_name www.chensiqi.org; #提供服务的域名主机名 16 location / { #第一个Location区块开始 17 root html; #站点的根目录(相对于nginx安装路径) 18 index index.html index.htm; #默认的首页文件,多个用空格分开 19 } 20 error_page 500 502 503 504 /50x.html; #出现对应的http状态码时,使用50x.html回应客户 21 location = /50x.html { #Location区块开始,访问50x.html 22 root html; #指定对应的站点目录为html 23 } 24 } 25 server { #网站配置区域(第二个server第二个虚拟主机站点) 26 listen 80; #提供服务的端口,默认80 27 server_name bbs.chensiqi.org; #提供服务的域名主机名 28 location / { #服务区块 29 root html; #相对路径(nginx安装路径) 30 index index.html index.htm; 31 } 32 location = /50x.html { #发生错误访问的页面 33 root html; 34 } 35 } 36 }
修改配置文件
1 worker_processes 1;
2 events {
3 worker_connections 1024;
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65;
10 server {
11 listen 80;
12 server_name www.yunjisuan.com; #访问域名
13 root /www; #站点目录
14 location / {
15 index index.php;
16 }
17 location ~.*.(php|php5)?$ {
18 fastcgi_pass 192.168.200.153:9000; #指定PHP IP地址
19 fastcgi_index index.php;
20 include fastcgi.conf;
注:修改配置文件后
/usr/local/nginx/sbin/nginx -t 检验配置文件
/usr/local/nginx/sbin/nginx -s reload 平滑重启
3.创建网页文件目录
mkdir /www
1 cd www/ #进入动态网页目录下,创建动态网页
2 echo "html php" > index.php
3 echo "`hostname -I` www.yunjisuan.com" > /etc/hosts #映射文件
4 cat /etc/hosts
5 192.168.200. 140 www.yunjisuan.com
授权目录
chown -R www.www /www
二.安装PHP
1.执行下面命令安装相关的lib软件包
1 yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel 2 yum -y install freetype-devel libpng-devel gd libcurl-devel libxslt-devel
rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel
zlib-devel-1.2.3-29.el6.x86_64
libxml2-devel-2.7.6-14.el6.x86_64
libjpeg-turbo-devel-1.2.1-1.el6.x86_64
#这里仅缺少libiconv-devel包
[root@localhost ~]# rpm -qa freetype-devel libpng-devel gd libcurl-devel libxslt-devel
freetype-devel-2.3.11-14.el6_3.1.x86_64
libpng-devel-1.2.49-1.el6_2.x86_64
libcurl-devel-7.19.7-37.el6_4.x86_64
libxslt-devel-1.1.26-2.el6_3.1.x86_64
gd-2.0.35-11.el6.x86_64
安装yum无法安装的libiconv库
1 wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
1 tar xf libiconv-1.14.tar.gz -C /usr/src/ 2 cd /usr/src/libiconv-1.14/ 3 ./configure --prefix=/usr/local/libiconv && make && make install 4 rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpm
5 warning: libmcrypt-2.5.8-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY 6 Preparing... ########################################### [100%] 7 1:libmcrypt ########################################### [100%] 8 [root@zhangmingjuan ~]# rpm -ivh mhash-0.9.9.9-3.el6.x86_64.rpm 9 warning: mhash-0.9.9.9-3.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY 10 Preparing... ########################################### [100%] 11 1:mhash ########################################### [100%] 12 [root@zhangmingjuan ~]# rpm -ivh libmcrypt-devel-2.5.8-9.el6.x86_64.rpm 13 warning: libmcrypt-devel-2.5.8-9.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY 14 Preparing... ########################################### [100%] 15 1:libmcrypt-devel ########################################### [100%] 16 [root@zhangmingjuan ~]# rpm -ivh mcrypt-2.6.8-10.el6.x86_64.rpm 17 warning: mcrypt-2.6.8-10.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY 18 Preparing... ########################################### [100%] 19 1:mcrypt ########################################### [100%]
注:安装顺序
2.安装PHP(FastCGI方式)服务
获取安装包
1 wget http://cn2.php.net/get/php-5.3.28.tar.gz/from/this/mirror
解压配置PHP
1 tar xf php-5.3.28.tar.gz -C /usr/src/ 2 cd /usr/src/php-5.3.28/ 3 ./configure 4 > --prefix=/usr/local/php5.3.28 5 > --with-mysql=mysqlnd #PHP自己配置MYSQL环境 6 > --with-iconv-dir=/usr/local/libiconv 7 > --with-freetype-dir 8 > --with-jpeg-dir 9 > --with-png-dir 10 > --with-zlib 11 > --with-libxml-dir=/usr 12 > --enable-xml 13 > --disable-rpath 14 > --enable-safe-mode 15 > --enable-bcmath 16 > --enable-shmop 17 > --enable-sysvsem 18 > --enable-inline-optimization 19 > --with-curl 20 > --with-curlwrappers 21 > --enable-mbregex 22 > --enable-fpm 23 > --enable-mbstring 24 > --with-mcrypt 25 > --with-gd 26 > --enable-gd-native-ttf 27 > --with-openssl 28 > --with-mhash 29 > --enable-pcntl 30 > --enable-sockets 31 > --with-xmlrpc 32 > --enable-zip 33 > --enable-soap 34 > --enable-short-tags 35 > --enable-zend-multibyte 36 > --enable-static 37 > --with-xsl 38 > --with-fpm-user=www 39 > --with-fpm-group=www 40 > --enable--ftp
安装成功
3.编译
1 ln -s /usr/local/mysql/lib/libmysqlclient.so.18
2 libmysqlclient.so.18 libmysqlclient.so.18.0.0
3 ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
4 touch ext/phar/phar.phar
5 make
6 #make最后的正确提示
7 Build complete.
8 Don't forget to run 'make test'.
9 make install #安装
4.配置PHP引擎配置文件PHP.ini
设置软连接
1 ln -s /usr/local/php5.3.28/ /usr/local/php
拷贝PHP配置文件到PHP默认目录,并更改文件名称为php.ini
1 cd /usr/src/php-5.3.28/ 2 cp php.ini-production /usr/local/php/lib/php.ini 3 ls -l /usr/local/php/lib/php.ini 4 -rw-r--r--. 1 root root 69627 Jul 14 13:25 /usr/local/php/lib/php.ini
配置PHP(FastCGI方式)的配置文件php-fpm.conf
1 cp php.ini-production /usr/local/php/lib/php.ini 2 ls -l /usr/local/php/lib/php.ini 3 -rw-r--r--. 1 root root 69627 Jul 14 13:25 /usr/local/php/lib/php.ini 4 ]# cd /usr/local/php/etc/ 5 ls 6 pear.conf php-fpm.conf.default 7 cp php-fpm.conf.default php-fpm.conf
启动PHP服务(FastCGI方式)
1 /usr/local/php/sbin/php-fpm
修改配置文件
4.创建程序用户
1 useradd -s /sbin/nologin -g www -M www 2 tail -1 /etc/passwd 3 www:x:500:500::/home/www:/sbin/nologin 4 id www 5 uid=500(www) gid=500(www) groups=500(www)
5.创建网页文件目录
mkdir /www
1 cd www/ #进入动态网页目录下,创建动态网页
2 echo "html php" > index.php
3 echo "`hostname -I` www.yunjisuan.com" > /etc/hosts #映射文件
授权目录
chown -R www.www /www
编辑test_mysql.php,加入如下内容:
[root@zhengweiqiang www]# cat test_mysql.php <?php //$link_id=mysql_connect('192.168.200.154','yunjisuan','123123'); #mysql $link_id=mysql_connect('localhost','root','123123'); if($link_id){ echo "mysql successful by Mr.chen !"; }else{ echo mysql_error(); } ?>
三.安装MySQL
1.创建mysql用户的账号
1 useradd -s /sbin/nologin -g mysql -M mysql 2 tail -1 /etc/passwd 3 mysql:x:501:501::/home/mysql:/sbin/nologin 4 id mysql 5 uid=501(mysql) gid=501(mysql) groups=501(mysql)
2. 采用二进制方式安装MySQL
1 tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /usr/local/ 2 cd /usr/local/ 3 mv mysql-5.5.32-linux2.6-x86_64 mysql-5.5.32 4 ln -s mysql-5.5.32 mysql 5 ls 6 bin games lib libexec mysql-5.5.32 nginx-1.10.2 share 7 etc include lib64 mysql nginx sbin src 8 cd /usr/local/mysql 9 ls 10 bin data include lib mysql-test scripts sql-bench 11 COPYING docs INSTALL-BINARY man README share support-files 12 #提示: 13 二进制安装包,仅需要解压就可以了,不需要执行cmake/configure,make,make install等过程
3.初始化 MySQL配置文件my.cnf
cd /usr/local/mysql ls -l support-files/*.cnf -rw-r--r-- 1 7161 wheel 4691 Jun 19 2013 support-files/my-huge.cnf -rw-r--r-- 1 7161 wheel 19759 Jun 19 2013 support-files/my-innodb-heavy-4G.cnf -rw-r--r-- 1 7161 wheel 4665 Jun 19 2013 support-files/my-large.cnf -rw-r--r-- 1 7161 wheel 4676 Jun 19 2013 support-files/my-medium.cnf -rw-r--r-- 1 7161 wheel 2840 Jun 19 2013 support-files/my-small.cnf /bin/cp support-files/my-small.cnf /etc/my.cnf
4.配置并启动MySQL数据库
1 cd /usr/local/mysql 2 ls 3 bin data include lib mysql-test scripts sql-bench 4 COPYING docs INSTALL-BINARY man README share support-files 5 /bin/cp support-files/mysql.server /etc/init.d/mysqld #拷贝MySQL启动脚本到MySQL的命令路径 6 chmod +x /etc/init.d/mysqld 7 /etc/init.d/mysqld start #启动mysql数据库 8 Starting MySQL... SUCCESS! 9 netstat -antup | grep mysql #检查MySQL数据库是否启动 10 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1485/mysqld 11 chkconfig --add mysqld #设置MySQL开机自启动 12 chkconfig mysqld on 13 chkconfig --list mysqld 14 mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 15 ln -s /usr/local/mysql/bin/* /usr/local/bin/ #配置mysql命令的全局使用路径 16 which mysqladmin 17 /usr/local/bin/mysqladmin
5.数据库方配置
1 mysqladmin -u root password '123123' 2 mysql -uroot -p123123
Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.5.32 MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> grant all on *.* to 'yunjisuan'@'%' identified by '123123'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
6.创建一个专用的管理用户,命令如下:
1 mysql> grant all on wordpress.* to 'yunjisuan'@'%' identified by '123123'; #localhost为客户端地址 2 Query OK, 0 rows affected (0.00 sec) 3 mysql> flush privileges; #刷新权限,使得创建用户生效 4 Query OK, 0 rows affected (0.00 sec) 5 mysql> show grants for 'yunjisuan'@'localhost'; #查看用户对应权限 6 +------------------------------------------------------------------------------------------------------------------+ 7 | Grants for wordpress@localhost | 8 +------------------------------------------------------------------------------------------------------------------+ 9 | GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1' | 10 | GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'localhost' | 11 +------------------------------------------------------------------------------------------------------------------+ 12 2 rows in set (0.00 sec) 13 mysql> select user,host from mysql.user; #查看数据库里创建用户 14 +-----------+-----------+ 15 | user | host | 16 +-----------+-----------+ 17 | root | 127.0.0.1 | 18 | root | localhost | 19 | yunjisuan| % | 20 +-----------+-----------+ 21 3 rows in set (0.00 sec) 22 mysql> quit 23 Bye
四.最终测试结果
成功!