部署所需系统环境
部署的系统版本与内核
[root@moban tools]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@moban scripts]# uname -r 2.6.32-696.el6.x86_64 [root@moban tools]# uname -m x86_64 [root@moban tools]# uname -a Linux moban 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21
系统部署安装包组
# 系统安装包组说明(最小化安装)
Base/Compatibility libraries/Debugging Tools/Development Tools/Dial-up Networking Support
Hardware monitoring utilities/Performance Tools
系统环境重要优化
# 网络配置信息优化
开启eth0 eth1两块网卡,eth0网卡可以访问外网,eth1网卡采用LAN区段模式
# 系统安全策略配置(防护墙关闭 SElinue关闭 临时目录权限1777 )
/etc/init.d/iptables status
getenforce
chmod 1777 /tmp
安装nginx
官网下载nginx
wget http://nginx.org/download/nginx-1.14.0.tar.gz
官网地址:http://nginx.org/
安装依赖
yum install -y pcre-devel openssl-devel gcc
perl正则表达式兼容工具 rewrite模块 匹配一个信息进行替换
openssl实现https访问
创建用户-worker进程由指定用户管理-- www
useradd -s /sbin/nologin -M www
编译安装nginx
cd /server/tools/ tar xf nginx-1.14.0.tar.gz cd nginx-1.14.0 ./configure --prefix=/application/nginx-1.14 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module echo $? make && make install
--prefix=PATH set installation prefix -->设置程序安装路径信息 --user=USER set non-privileged user for worker processes -->设置虚拟用户管理worker进程 --group=GROUP set non-privileged group for worker processes --with-http_ssl_module enable ngx_http_ssl_module -->启用ssl功能 --with-http_stub_status_module enable ngx_http_stub_status_module -->启用监控nginx状态的模块
创建软链接
ln -s /application/nginx-1.14 /application/nginx
启动nginx
/application/nginx/sbin/nginx
安装nginx全过程
mkdir -p /server/tools cd /server/tools/ wget http://nginx.org/download/nginx-1.14.0.tar.gz yum install -y pcre-devel openssl-devel useradd -s /sbin/nologin -M www cd /server/tools/ tar xf nginx-1.14.0.tar.gz cd nginx-1.14.0 ./configure --prefix=/application/nginx-1.14 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module echo $? make && make install ln -s /application/nginx-1.14 /application/nginx
安装MySQL-二进制包安装
MySQL软件安装方式:
1、yum安装mysql
2、编译安装mysql
3、二进制包安装mysql
下载 解压 软链接MySQL
官方下载地址:ftp://ftp.jaist.ac.jp/pub/mysql/Downloads/
cd /server/tools/ tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz mv /server/tools/mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34 ln -s /application/mysql-5.6.34 /application/mysql
添加MySQL用户
useradd -M -s /sbin/nologin mysql
让mysql用户管理数据目录--设定权限
chown -R mysql.mysql /application/mysql/data/
初始化数据库
/application/mysql/scripts/mysql_install_db \ --basedir=/application/mysql \ --datadir=/application/mysql/data \ --user=mysql
初始化数据库干了什么
1、确认软件安装在哪里
2、确认数据存放在哪里
3、确认MySQL使用的用户谁?
初始化数据库成功提示信息:
To start mysqld at boot time you have to copy
#提示我们在support-files目录有个mysql.server是MySQL的启动脚本
support-files/mysql.server to the right place for your system
编写修改启动脚本
# 复制启动脚本并授权
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
# 修改启动脚本文件内容(调整程序安装目录信息)
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
配置my.cnf
# 利用mysql程序默认配置文件替换系统中数据库配置文件
/bin/cp /application/mysql/support-files/my-default.cnf /etc/my.cnf
启动MySQL
# 启动mysql数据库程序服务
/etc/init.d/mysqld start
登录MySQL
#给mysql的root用户设置密码
/application/mysql/bin/mysqladmin -u root -h localhost password '123456'
/application/mysql/bin/mysql -h localhost -uroot -p123456
安装MySQL全过程
cd /server/tools/ tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz mv /server/tools/mysql-5.6.34-linux-glibc2.5-x86_64 /application/mysql-5.6.34 ln -s /application/mysql-5.6.34 /application/mysql useradd -M -s /sbin/nologin mysql chown -R mysql.mysql /application/mysql/data/ /application/mysql/scripts/mysql_install_db \ --basedir=/application/mysql \ --datadir=/application/mysql/data \ --user=mysql cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld /bin/cp /application/mysql/support-files/my-default.cnf /etc/my.cnf /etc/init.d/mysqld start && /application/mysql/bin/mysqladmin -u root password '123456' /application/mysql/bin/mysql -uroot -p123456
安装PHP
安装PHP依赖软件
yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel
#检查是否安装成功
rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
#编译安装字符集转换库
#下载地址:http://www.gnu.org/software/libiconv/ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
cd /server/tools/ tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make && make install echo $?
#安装一些加密软件,以下软件通过epel源安装
yum -y install libmcrypt-devel mhash mcrypt
#检查是否安装成功
rpm -qa libmcrypt-devel mhash mcrypt
#如果没有epel扩展源
#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
下载 解压 编译安装PHP
http://php.net/releases/
cd /server/tools/
tar xf php-5.5.32.tar.gz
cd php-5.5.32
#解决编译过程中的错误
ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
touch ext/phar/phar.phar
./configure \ --prefix=/application/php-5.5.32 \ --with-mysql=/application/mysql-5.6.34 \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir=/usr/local/libiconv \ --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-soap \ --enable-short-tags \ --enable-static \ --with-xsl \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-ftp \ --enable-opcache=no
make && make install
echo $?
#做软链接
ln -s /application/php-5.5.32/ /application/php
配置PHP
cp /server/tools/php-5.5.32/php.ini-production /application/php/lib/php.ini
cp /application/php/etc/php-fpm.conf.default /application/php/etc/php-fpm.conf
cd /server/tools/php-5.5.32 ll php.ini* -rw-r--r--. 1 1001 1001 69236 2016-02-02 21:33 php.ini-development --- 是开发人员调试用配置文件--开启了一些日志功能 -rw-r--r--. 1 1001 1001 69266 2016-02-02 21:33 php.ini-production --- 生产环境常用配置文件
启动PHP
/application/php/sbin/php-fpm
安装PHP全过程
#解决依赖 yum install -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel #字符集转换库 cd /server/tools/ tar zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make && make install echo $? #安装一些加密软件,以下软件通过epel源安装 yum -y install libmcrypt-devel mhash mcrypt cd /server/tools/ tar xf php-5.5.32.tar.gz cd php-5.5.32 #解决编译过程中的错误 ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ touch ext/phar/phar.phar ./configure \ --prefix=/application/php-5.5.32 \ --with-mysql=/application/mysql-5.6.34 \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir=/usr/local/libiconv \ --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-soap \ --enable-short-tags \ --enable-static \ --with-xsl \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-ftp \ --enable-opcache=no make && make install echo $? ln -s /application/php-5.5.32/ /application/php cd /application/php/etc/ cp php-fpm.conf.default php-fpm.conf #启动PHP /application/php/sbin/php-fpm
nginx与PHP建立连接关系
nginx与PHP通过fastcgi建立连接关系
配置nginx虚拟主机配置文件
配置过程:
vim /application/nginx/conf/extra/blog.conf
server { listen 80; server_name blog.abc.com; location / { root html/blog; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }
#使用cat添加
cat >/application/nginx/conf/extra/blog.conf <
#使用cat为nginx.conf配置
cat >/application/nginx/conf/nginx.conf<
重载nginx
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -s reload
测试PHP解析
echo '' >/application/nginx/html/blog/test_info.php
浏览器访问测试:http://blog.abc.com/test_info.php
PHP与MySQL建立连接关系
编写测试代码文件
vim /application/nginx/html/blog/test_mysql.php
#使用cat添加
cat >/application/nginx/html/blog/test_mysql.php <EOF
windows访问测试
http://blog.abc.com/test_mysql.php
下载 解压 移动 wordpress程序
cd /server/tools/
tar xf wordpress-4.7.3-zh_CN.tar.gz
mv /server/tools/wordpress/* /application/nginx/html/blog/
检查代码文件 发现文件权限不正确
修改站点目录下的代码文件权限
chown -R www.www /application/nginx/html/blog
[root@moban tools]# ll /application/nginx/html/blog/ total 200 -rw-r--r-- 1 root root 19 Sep 3 19:43 index.html -rw-r--r-- 1 nobody nfsnobody 418 Sep 25 2013 index.php -rw-r--r-- 1 nobody nfsnobody 19935 Jan 3 2017 license.txt -rw-r--r-- 1 nobody nfsnobody 6956 Mar 7 2017 readme.html -rw-r--r-- 1 root root 20 Sep 6 20:56 test_info.php -rw-r--r-- 1 root root 326 Sep 6 21:26 test_mysql.php -rw-r--r-- 1 nobody nfsnobody 5447 Sep 28 2016 wp-activate.php drwxr-xr-x 9 nobody nfsnobody 4096 Mar 7 2017 wp-admin -rw-r--r-- 1 nobody nfsnobody 364 Dec 19 2015 wp-blog-header.php -rw-r--r-- 1 nobody nfsnobody 1627 Aug 29 2016 wp-comments-post.php -rw-r--r-- 1 nobody nfsnobody 2930 Mar 7 2017 wp-config-sample.php drwxr-xr-x 5 nobody nfsnobody 4096 Mar 7 2017 wp-content -rw-r--r-- 1 nobody nfsnobody 3286 May 25 2015 wp-cron.php drwxr-xr-x 18 nobody nfsnobody 12288 Mar 7 2017 wp-includes -rw-r--r-- 1 nobody nfsnobody 2422 Nov 21 2016 wp-links-opml.php -rw-r--r-- 1 nobody nfsnobody 3301 Oct 25 2016 wp-load.php -rw-r--r-- 1 nobody nfsnobody 33939 Nov 21 2016 wp-login.php -rw-r--r-- 1 nobody nfsnobody 8048 Jan 11 2017 wp-mail.php -rw-r--r-- 1 nobody nfsnobody 16250 Nov 29 2016 wp-settings.php -rw-r--r-- 1 nobody nfsnobody 29896 Oct 19 2016 wp-signup.php -rw-r--r-- 1 nobody nfsnobody 4513 Oct 15 2016 wp-trackback.php -rw-r--r-- 1 nobody nfsnobody 3065 Sep 1 2016 xmlrpc.phpWordPress 博客程序的搭建
创建wordpress数据库 使用的用户为wordpress
/application/mysql/bin/mysql -uroot -p123456
#mysql中的操作;
create database wordpress;
show databases;
grant all on wordpress.* to 'wordpress'@'localhost' identified by '654321';
flush privileges;
#检查创建的用户
select user,host from mysql.user;
#删除多余的用户
drop user ''@localhost;
drop user ''@web01;
drop user 'root'@'::1';
浏览器访问安装wordpress
第一次安装wordpress时出现
将数据库进行分离
db01二进制安装MySQL并启动
将MySQL二进制安装包,放入/server/tools/ 目录中 并执行脚本
sh LNMP.sh 2
web端将数据库备份
/application/mysql/bin/mysqldump -uroot -p123456 --all-databases >/tmp/back.sql
ll -h /tmp/back.sql #<--查看备份文件大小,保证备份正确
scp /tmp/back.sql 10.0.0.51:/tmp
db01端恢复数据
/application/mysql/bin/mysqladmin -uroot password 123456
#恢复数据
/application/mysql/bin/mysql -uroot -p123456 < /tmp/back.sql
#修改wordpress用户权限信息-修改授权主机
/application/mysql/bin/mysql -uroot -p123456
mysql中的操作
select user,host from mysql.user; #检查所有用户
drop user 'wordpress'@'localhost'; #web的要进行远程连接数据库 所以删除原本的指定了localhost主机的wordpress用户
grant all on wordpress.* to 'wordpress'@'10.0.0.%' identified by '654321';
web端修改代码配置文件 并关闭MySQL
vim /application/nginx/html/blog/wp-config.php
找到并修改,将MySQL主机修改为db01的地址
/** MySQL主机 */
define('DB_HOST', '10.0.0.51');
/etc/init.d/mysqld stop
分离上传目录至NFS
确认用户上传数据的位置
01) 利用浏览器页面信息获取数据存储路径
http://blog.etiantian.org/wp-content/uploads/2018/09/oldboy-300x267.jpg
02) 监控目录中的数据变化软件
inotifywait -mrq
03) 利用find查找方法发现变化数据
find /站点目录 -mmin -3
将上传目录中的数据进行备份迁移
cp -a /application/nginx/html/blog/wp-content/uploads /data_backup/
rm -rf /application/nginx/html/blog/wp-content/uploads/*
配置NFS服务端
配置nfs
vim /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=501,anongid=501)
uid gid一定要与web端的www用户uid gid对应
创建对应的www用户
usermod -u501 -G 501 www #如果提示没有对应的guid使用下面的
userdel -r www
useradd -u501 www
设置共享目录权限
chown -R www.www /data
web端进行共享目录挂载,并恢复数据
安装服务
yum install -y rpcbind nfs-utils
挂载目录
mount -t nfs 172.16.1.31:/data /application/nginx/html/blog/wp-content/uploads/
恢复数据
cp -a /data_backup/uploads/* /application/nginx/html/blog/wp-content/uploads/
浏览器检查是否正常