Linux基础知识day-6

基础服务:

  配置安装服务之前确保,防火墙和SELinux是关闭状态。如果是开启状态,请自行解决相关的操作。

Samba服务配置:

  1)最小化安装的CentOS没有Samba服务,需手动安装“samba”。

  2)samba的配置位置:/etc/samba/smb.conf

    samba配置文件相关参数:

      全局参数:

      workgroup = MYGROUP

      //设置工作组名

      server string = Samba Server Version %v

      //设置服务器说明

      ;hosts allow = 127. 192.168.12. 192.168.13.

      //配置可访问服务器的IP范围,默认为全部。去掉前方的“;”号启用配置

      max log size = 50

      //配置每个日志文件大小,默认50KB每个

      log file = /var/log/samba/log.%m

      //设定 samba server 日志文件的储存位置和文件名(%m代表客户端主机名)

      security = user

      //配置samba服务的安全级别,共四种:share、user、server、domain

      文件权限参数:

      [public]

      //共享的名字

      comment = Public Stuff

      //共享文件夹的注释说明

      path = /home/samba

      //共享文件夹的真实路径,除了配置文件的权限需要设置外,共享文件的权限也要设置对

      public = yes

      //是否公开共享,若为否则进行身份验证。

      writable = no

      //是否能写入,当与read only同时存在时,无视read only。

      printable = no

      //是否允许打印

      write list = +staff

      //若设定为只读时,则只有此设定的名单内的成员才可作写入动作(用户名/@组名)

      guest ok = yes

      //是否公开共享,若为否则进行身份验证。

      browseable = no

      //是否在浏览资源中显示共享目录。

 

samba示例:    

  1)每个用户有自己的目录,可以浏览内容,也可以删除。

    1.默认samba配置文件中启用了用户家目录的共享。我们只需要建立samba用户就好。

1 [homes]
2         comment = Home Directories
3         valid users = %S, %D%w%S
4         browseable = No
5         read only = No
6         inherit acls = Yes

    2.建立供samba服务的用户,并禁止登录系统。

1 [root@centos-desktop samba]# useradd -s /sbin/nologin smbuser

    3.配置用户登陆samba的登录密码。

1 [root@centos-desktop samba]# smbpasswd -a smbuser
2 New SMB password:
3 Retype new SMB password:
4 Added user smbuser.
5 [root@centos-desktop samba]#

    4.启动samba服务,并设置开机自动启动。

1 [root@centos-desktop samba]# systemctl start smb
2 [root@centos-desktop samba]# systemctl enable smb
3 Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
4 [root@centos-desktop samba]#

    5.如果开启了防火墙,就添加相应的放行规则。

1 [root@centos-desktop home]# firewall-cmd --permanent --add-service=samba
2 success
3 [root@centos-desktop home]# firewall-cmd --reload
4 success
5 [root@centos-desktop home]#

    6.Windows使用UNC路径或者添加网络驱动器方式访问。

    7.Windows下删除共享访问的密码缓存。在CMD中执行:

 1 C:\Users\Rsildsl>net use
 2 不记录新的网络连接。
 3 
 4 
 5 状态       本地        远程                      网络
 6 
 7 -------------------------------------------------------------------------------
 8 OK           Z:        \\172.16.1.128\smbuser    Microsoft Windows Network
 9 命令成功完成。
10 
11 C:\Users\Rsildsl>net use * /del
12 你有以下的远程连接:
13 
14     Z:              \\172.16.1.128\smbuser
15 继续运行会取消连接。
16 
17 你想继续此操作吗? (Y/N) [N]: y
18 在与 Z: 的连接中,有打开的文件和/或没有结束的目录搜索。
19 
20 是否继续断开连接并强行关闭? (Y/N) [N]: y
21 命令成功完成。
22 
23 
24 C:\Users\Rsildsl>

  2)所有的用户共享一个目录,只能浏览内容,不能删。

    1.编辑smb.conf,在文件末尾加入下列内容

1 [smbdir]
2         comment = smb share dir
3         path = /smbdir
4         writable = no
5         public = yes

    2.在根目录建立对应的文件夹

1 [root@centos-desktop /]# mkdir smbdir
2 [root@centos-desktop /]# ls
3 bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  smbdir  srv  sys  tmp  usr  var
4 [root@centos-desktop /]#

    3.重启samba服务

1 [root@centos-desktop /]# systemctl restart smb
2 [root@centos-desktop /]#

 

Nginx服务配置:

  1)centos需要启用epel源来安装Nginx。

1 [root@centos-1 ~]# yum install epel-release -y
2 [root@centos-1 ~]# yum install -y nginx

  2)通过二进制包安装的nginx归systemctl管理,通过 systemctl [stop|start|restart|status] nginx 来启动停止服务

 1 [root@centos-desktop nginx]# systemctl start nginx
 2 [root@centos-desktop nginx]# systemctl stop nginx
 3 [root@centos-desktop nginx]# systemctl status nginx 
4 [root@centos-desktop nginx]# systemctl restart nginx

  3)nginx配置文件位置:/etc/nginx/nginx.conf

    worker_processes auto;

    //同时启动多少个工作进程

    error_log /var/log/nginx/error.log;

    //错误日志文件位置

    worker_connections 1024;

    //每个工作进程有多少个线程

    include       mime.types;

    //导入外部模块

    log_format  main '$remote_addr - $remote_user [$time_local] "$request" '

    //日志格式,main为自定义名称

    access_log  /var/log/nginx/access.log  main;

    //访问日志文件位置,配置使用什么格式

    keepalive_timeout   65;

    //连接超时时间

    listen

    //监听的端口

    root         /usr/share/nginx/html;

      //网站主目录

    index  index.html index.htm

    //网站默认主页名称

 

nginx的负载平衡:

  仅需要在LB分发服务器上配置,成员服务器为正常的nginx服务。如下图关系

  

  4)nginx基于轮询的方式负载平衡

    在配置文件对应位置添加修改下列内容

 1 http {
 2     upstream nginx1 {
 3         server 192.168.16.171;
 4         server 192.168.16.146;
 5         server 192.168.16.115;
 6     }
 7 
 8     server {
 9         listen 80;
10 
11         location / {
12             proxy_pass http://nginx1;
13         }
14     }
15 }

  5)nginx基于权重的方式负载平衡

    在配置文件对应的位置添加修改下列内容:

 1 http {
 2     upstream nginx1 {
 3         server 192.168.16.171 weight=3;
 4         server 192.168.16.146;
 5         server 192.168.16.115;
 6     }
 7 
 8     server {
 9         listen 80;
10 
11         location / {
12             proxy_pass http://nginx1;
13         }
14     }
15 }

  6)基于hash的方式负载平衡

    在配置文件对应的位置添加修改下列内容:

http {
    upstream nginx1 {
    ip_hash;
    server 192.168.16.171;
    server 192.168.16.146;
    server 192.168.16.115;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://nginx1;
        }
    }
}    

  7)如果启用防火墙了,需要放行使用的端口。

1 [root@centos-desktop html]# firewall-cmd --permanent --add-port=8080/tcp
2 [root@centos-desktop html]# firewall-cmd --permanent --add-port=80/tcp
3 [root@centos-desktop html]# firewall-cmd --reload

 

posted @ 2017-05-31 20:30  neuropathy_ldsly  阅读(230)  评论(0)    收藏  举报