目录
nginx服务的搭建及测试
添加YUM仓库
[root@localhost ~]# ls /etc/yum.repos.d/#查看yum仓库里面包含的内容
[root@localhost ~]# rm -rf /etc/yum.repos.d/*#删除yum仓库里的所有仓库
[root@localhost ~]# ls /etc/yum.repos.d/#查看清理是否完成
[root@localhost ~]# mount /dev/cdrom /mnt#挂载光盘
[root@localhost ~]# yum-config-manager --add file:///mnt#添加新的yum仓库
[root@localhost ~]# vim /etc/yum.repos.d/mnt.repo #编辑yum仓库
...
gpgcheck=0
...
[root@localhost ~]# yum clean all#清理yum仓库
[root@localhost ~]# yum repolist#显示所有yum仓库信息
安装Nginx
[root@localhost ~]# tar xf lnmp_soft.tar.gz#解压lnmp压缩包
[root@localhost ~]# cd lnmp_soft/#切换到lnmp的目录下
[root@localhost lnmp_soft]# tar xf nginx-1.10.3.tar.gz#解压1.10版本的NGINX服务压缩包
[root@localhost lnmp_soft]# cd nginx-1.10.3/#切换到NGINX目录下
[root@localhost nginx-1.10.3]# useradd nginx#添加NGINX用户
[root@localhost nginx-1.10.3]# yum -y install gcc pcre-devel openssl-devel#安装gcc环境和pcre以及openssl底层环境
[root@localhost nginx-1.10.3]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module#安装NGINX服务
[root@localhost nginx-1.10.3]# make && make install#安装完成后编译
启动Nginx
[root@localhost nginx-1.10.3]# ls /usr/local/nginx/sbin/
[root@localhost nginx-1.10.3]# /usr/local/nginx/sbin/nginx#启动NGINX服务
增加链接
[root@localhost ~]# ln -s /usr/local/nginx/sbin/nginx /bin/#链接
平滑升级
[root@localhost ~]# cd /root/lnmp_soft/#切换到lnmp目录下
[root@lnmp_soft ~]# tar xf nginx-1.12.2.tar.gz#解压1.12版本NGINX的压缩包
[root@lnmp_soft ~]# cd nginx-1.12.2/#切换到1.12版本NGINX目录下
[root@nginx-1.12.2 ~]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module#安装1.12版本的NGINX服务
[root@nginx-1.12.2 ~]# make#安装完成后编译
[root@nginx-1.12.2 ~]# cd /usr/local/nginx/sbin/#切换到NGINX的sbin目录下
[root@sbin ~]# mv nginx nginx.old#移动NGINX到NGINX.old
[root@sbin ~]# cd -#跳转到上一级目录
[root@nginx-1.12.2 ~]# cp objs/nginx /usr/local/nginx/sbin/#将1.12版本中的NGINX目录拷贝到原先的NGINX家目录下
[root@nginx-1.12.2 ~]# make upgrade#更新NGINX服务
[root@nginx-1.12.2 ~]# nginx -V#查看NGINX版本信息
配置用户认证
[root@localhost ~]# nginx#开启NGINX服务
[root@localhost ~]# mount /dev/cdrom /mnt挂载光盘
[root@localhost ~]# yum -y install httpd-tools安装httpd-tools服务
[root@localhost ~]# cd /usr/local/nginx/conf/#切换到NGINX的配置文件所在目录下
[root@conf ~]# cp nginx.conf nginx.conf.bak备份NGINX配置文件
[root@conf ~]# vim nginx.conf#编辑NGINX配置文件
location / {
root html;
index index.html index.htm;
auth_basic 'Input your name and pass';
auth_basic_user_file /usr/local/nginx/pass;
}
[root@conf ~]# htpasswd -c /usr/local/nginx/pass admin#添加NGINX认证用户
[root@conf ~]# nginx -s reload#重新启动NGINX服务
基于域名的虚拟主机
[root@conf ~]# cd /usr/local/nginx/conf#切换到NGINX服务配置文件所在的目录下
[root@conf ~]# vim nginx.conf#编辑NGINX配置文件
server {
listen 80;
server_name www.aa.com;
location / {
root html;
index index.html index.htm;
}
server {
listen 80;
server_name www.bb.com;
location / {
root www;
index index.html index.htm;
}
}
[root@conf ~]# cd ..跳转到上一级目录
[root@nginx ~]# mkdir www创建访问主页文件目录
[root@nginx ~]# echo www.aa.com > html/index.html创建www.aa.com的访问主页文件
[root@nginx ~]# echo www.bb.com > www/index.html创建www.bb.com的访问主页文件
[root@nginx ~]# nginx -s reload#重新启动NGINX服务
[root@nginx ~]# vim /etc/hosts#编辑Linux自带的域名解析文件
...
127.0.0.1 www.aa.com www.bb.com
...
[root@nginx ~]# firefox www.aa.com#访问www.aa.com
[root@nginx ~]# firefox www.bb.com#访问www.bb.com
添加https网站
[root@conf ~]# cd /usr/local/nginx/conf#切换到NGINX配置文件所在的目录下
[root@conf ~]# openssl genrsa > cert.key 2048#生成公钥
[root@conf ~]# openssl req -new -x509 -key cert.key > cert.pem#生成认证证书
[root@conf ~]# vim nginx.conf#编辑NGINX的配置文件
server {
listen 443 ssl;
server_name www.cc.com;
ssl_certificate cert.pem;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
[root@conf ~]# nginx -s reload#重新开启NGINX服务
[root@conf ~]# vim /etc/hosts#编辑Linux自带的域名解析文件
...
127.0.0.1 www.cc.com
...
[root@conf ~]# firefox https://www.cc.com
lnmp服务,discuz论坛的搭建以及nginx地址重写
安装LNMP
[root@localhost ~]# mount /dev/cdrom /mnt/#挂载光盘
[root@localhost ~]# nginx #启动nginx服务
[root@localhost ~]# yum -y install mariadb-server mariadb-devel#安装mariadb数据库以及与mariadb数据库相关的底层环境
[root@localhost ~]# yum -y install php php-mysql#安装php
[root@localhost ~]# cd lnmp_soft/
[root@localhost lnmp_soft ~]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm#安装php-fpm服务
[root@localhost lnmp_soft ~]# systemctl start mariadb#开启mariadb数据库
[root@localhost lnmp_soft ~]# systemctl enable mariadb#设置mariadb数据库开机自启动
[root@localhost lnmp_soft ~]# systemctl start php-fpm#开启php-fpm服务
[root@localhost lnmp_soft ~]# systemctl enable php-fpm#设置php-fpm开启自启动
[root@localhost lnmp_soft]# netstat -anput | grep :3306#通过查看3306端口使用情况来检查mariadb数据库是否已经被开启
[root@localhost lnmp_soft]# netstat -anput | grep :9000#通过查看9000端口使用情况来检查php-fpm服务是否已经开启
[root@localhost lnmp_soft]# mysql连接数据库
[root@localhost lnmp_soft]# cd /usr/local/nginx/conf#切换NGINX的配置文件所在目录下
[root@localhost conf]# vim nginx.conf #编辑NGINX服务的配置文件
server {
listen 80;
server_name www.aa.com;
location / {
root html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
}
测试PHP页面
[root@localhost conf]# nginx -s reload#重新启动NGINX
[root@localhost conf]# cd /usr/local/nginx/html#进入NGINX服务的主业目录下
[root@localhost html]# vim test.php#编写一个php脚本文件
<?php
$i=33;
echo $i;
?>
[root@localhost html]# firefox www.aa.com/test.php#测试php服务是否开启,NGINX是否支持php页
测试PHP链接MySQL页面
[root@localhost ~]# cp /root/lnmp_soft/php_scripts/mysql.php /usr/local/nginx/html/#拷贝php链接的MySQL主页文件到NGINX的默认主页文件目录下
[root@localhost ~]# firefox www.aa.com/mysql.php#通过php脚本文件访问www.aa.com
开机启动网卡
[root@localhost ~]# nmcli connection modify ens33 connection.autoconnect yes#设置网卡开机自启动
[root@localhost ~]# nmcli connection up ens33 #启用网卡
[root@localhost ~]# ifconfig#查看当主机ip地址信息
下载、部署论坛
[root@localhost ~]# wget ftp://192.168.7.66/Discuz.zip通过wget工具下载Discuz.zip压缩包
[root@localhost ~]# unzip Discuz.zip #解压Discuz.zip压缩包
[root@localhost ~]# cp -rf dir_SC_UTF8/upload/ /usr/local/nginx/html/bbs#拷贝解压后目录下的upload目录到NGINX默认主页目录下
[root@localhost ~]# cd /usr/local/nginx/html/#切换到NGINX默认主页目录下
[root@localhost html]# chown apache -R bbs/#修改bbs目录的属主
[root@localhost nginx]# setenforce 0#关闭安全linux
[root@localhost nginx]# vim /etc/sysconfig/selinux#编辑selinux文件
...
SELINUX=permissive#设置selinux为静默状态
...
[root@localhost nginx]# firefox www.aa.com/bbs#通过bbs目录访问www.aa.com
Nginx地址重写
[root@localhost html]# echo aaaaaaa > a.html#向a.html文件中写入aaaaa
[root@localhost html]# echo bbbbbb > b.html#向b.html文件中写入bbbbbbb
[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf#编辑NGINX服务的配置文件
server {
listen 80;
server_name www.aa.com;
location / {
root html;
index index.html index.htm index.php;
rewrite '/a.html$' /b.html;
}
[root@localhost nginx]# nginx -s reload#重新开启NGINX服务
[root@localhost nginx]# firefox www.aa.com/a.html#通过a.html文件访问www.aa.com
Nginx URL 重写
[root@localhost nginx]#vim /usr/local/nginx/conf/nginx.conf#编写NGINX服务的配置文件
...
server {
listen 80;
server_name www.bb.com;
location / {
root www;
index index.html index.htm;
rewrite ^/(.*) http://www.aa.com/bbs/$1;#NGINX访问url重写
}
}
...
[root@localhost nginx]# nginx -s reload#重新启动NGINX服务
[root@localhost nginx]# firefox www.bb.com#访问www.bb.com
nginx反向代理
进入多用户模式
3台虚拟机均做配置
[root@localhost ~]# systemctl set-default multi-user.target#设置启用多用户终端
[root@localhost ~]# reboot#重新启动进入命令行模式
IP规划
服务器A:
仅主机 192.168.154.128
NAT 192.168.242.5
[root@localhost ~]# nmcli connection modify ens33 ipv4.addresses 192.168.242.5/24 ipv4.method manual#为网卡配置ip地址
[root@proxy ~]# nmcli connection modify ens33 ipv4.gateway 192.168.242.2#设置主机网关地址
[root@localhost ~]# nmcli connection up ens33#启动网卡
[root@localhost ~]# ping 192.168.242.2
[root@localhost ~]# hostnamectl set-hostname proxy.com#修改主机名
服务器B:
192.168.242.100
[root@localhost ~]# nmcli connection modify ens33 ipv4.addresses 192.168.242.100/24 ipv4.method manual#修改网卡ip地址信息
[root@localhost ~]# nmcli connection up ens33#启动网卡
[root@localhost ~]# ping 192.168.242.2
[root@localhost ~]# hostnamectl set-hostname web100.com#修改主机名
服务器C:
192.168.242.200
[root@localhost ~]# nmcli connection modify ens33 ipv4.addresses 192.168.242.200/24 ipv4.method manual#配置网卡ip
[root@localhost ~]# nmcli connection up ens33#启用网卡
[root@localhost ~]# ping 192.168.242.2
[root@localhost ~]# hostnamectl set-hostname web200.com#修改主机名
下载lnmp安装文件
三台服务器上操作
[root@proxy ~]# wget ftp://192.168.7.66/lnmp.tar.gz#使用wget工具下载lnmp.tar.gz压缩包
[root@proxy ~]# scp lnmp.tar.gz 192.168.242.100:/root#远程传输文件
[root@proxy ~]# scp lnmp.tar.gz 192.168.242.200:/root#远程传输文件
[root@proxy ~]# mount /dev/cdrom /mnt/#挂载光盘
[root@proxy ~]# rm -rf /etc/yum.repos.d/*#删除yum仓库内所有东西
[root@proxy ~]# yum-config-manager --add file:///mnt#配置新的yum仓库
[root@proxy ~]# echo gpgcheck=0 >> /etc/yum.repos.d/mnt.repo
[root@proxy ~]# yum clean all#清理yum仓库
[root@proxy ~]# yum repolist#显示yum仓库的所有信息
[root@proxy ~]# firewall-cmd --set-default-zone=trusted#设置防火墙默认状态为trusted
[root@proxy ~]# setenforce 0#关闭安全linux
[root@proxy ~]# yum -y install gcc pcre-devel openssl-devel
[root@proxy ~]# cd /root/lnmp_soft/nginx-1.12.2/
[root@proxy nginx-1.12.2]# ./configure --with-stream --with-http_ssl_module
[root@proxy nginx-1.12.2]# make && make install
[root@proxy nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /bin/
[root@proxy nginx-1.12.2]# nginx
web100
[root@web100 nginx-1.12.2]# echo 192.168.242.100 > /usr/local/nginx/html/index.html
web200
[root@web200 nginx-1.12.2]# echo 192.168.242.200 > /usr/local/nginx/html/index.html
代理服务器
[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
upstream myweb{
server 192.168.242.100;
server 192.168.242.200;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://myweb;
root html;
index index.html index.htm;
}
}
TCP/UDP代理
[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
stream {
upstream backend {
server 192.168.242.100:22;
server 192.168.242.200:22;
}
server {
listen 12345;
proxy_connect_timeout 1s;
proxy_timeout 100s;
proxy_pass backend;
}
}
[root@proxy ~]#nginx -s reload
memchched
[root@web100 ~]# yum -y install memcached
[root@web100 ~]# yum -y install telnet
[root@web100 ~]# systemctl restart memcached
SVN仓库的搭建
搭建svn仓库
[root@localhost ~]# mount /dev/cdrom /mnt
[root@localhost ~]# vim /etc/yum.repos.d/mnt.repo
[Centos7]
name='CentOS7.4'
baseurl=file:///mnt
enable=1
gpgcheck=0
[root@localhost ~]# yum clean all
[root@localhost ~]# yum repolist
[root@localhost ~]# yum -y install subversion
[root@localhost ~]# mkdir /var/svn
[root@localhost ~]# svnadmin create /var/svn/project1
[root@localhost ~]# vim /var/svn/project1/conf/svnserve.conf
...
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
...
[root@localhost ~]# vim /var/svn/project1/conf/passwd
...
harry = 123456
sally = 123456
...
[root@localhost ~]# vim /var/svn/project1/conf/authz
...
[groups]
harry_and_sally = harry,sally
[/]
@harry_and_sally = rw
* =
...
[root@localhost ~]# svnserve -dr /var/svn/