Samba服务(基于CentOS 7.0)

Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成,Samba主要用于Linux或UNIX和Windows系统之间的文件共享。

SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。

服务安装

  1. [root@centos-python ~]# yum install samba -y

启动服务

  1. [root@centos-python ~]# systemctl start smb      #启动samba服务
  2. [root@centos-python ~]# systemctl status smb      #查看服务状态
  3. smb.service - Samba SMB Daemon
  4. Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled)
  5. Active: active (running) since Tue 2017-05-30 21:14:18 EDT; 8s ago
  6. Main PID: 2958 (smbd)
  7. Status: "smbd: ready to serve connections..."
  8. CGroup: /system.slice/smb.service
  9. ?..2958 /usr/sbin/smbd
  10. ?..2959 /usr/sbin/smbd
  11.  
  12. May 30 21:14:18 centos-python smbd[2958]: [2017/05/30 21:14:18.242052, 0] ../lib/util/become_daemon.c:136(daemon_ready)
  13. May 30 21:14:18 centos-python systemd[1]: Started Samba SMB Daemon.
    [root@centos-test ~]# systemctl enable smb        #设置开机启动
    ln -s '/usr/lib/systemd/system/smb.service' '/etc/systemd/system/multi-user.target.wants/smb.service'

配置一个访问用户

  1. [root@centos-python ~]# useradd usertest     #增加一个用户
  2. [root@centos-python ~]# smbpasswd -a usertest    #将该用户配置为samba用户
  3. New SMB password:
  4. Retype new SMB password:
  5. Added user usersmb.

配置防火墙和SELinux

  1. [root@centos-python ~]# firewall-cmd --permanent --add-service=samba    #放行samba服务,使外部能够访问该服务
  2. success
  3. [root@centos-python ~]# firewall-cmd --reload        #使防火墙配置生效
  4. success
    [root@centos-test ~]# getenforce         #查看SELinux状态,关闭即可
    Disabled

验证

windows下使用运行工具,输入Linux服务器共享地址:ip地址+家目录

确定连接后,提示输入用户名和密码,即smbpasswd -a usertest的用户名和密码

登陆成功即可看到共享的文件信息

服务配置-基于用户的共享目录

配置文件:/etc/samba/smb.conf

全局配置项说明(部分):[global]配置节

  1. [global]
  2. workgroup = MYGROUP       #工作组,如果设置为WORKGROUP,则在windows的网络发现内可以直接看到共享
  3. server string = Samba Server Version %v     #该服务器的说明信息
  4. ; netbios name = MYSERVER
  5. ; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
  6. ; hosts allow = 127. 192.168.12. 192.168.13.        #允许哪些ip地址或者网段访问该服务器,默认允许所有,去掉;生效
                                       格式:127.表示127开头的网段,192.168.12.表示192.168.12网段,192.168.13.1表示一个主机
    ; max protocol = SMB2                   
  7. # log files split per-machine:
  8. log file = /var/log/samba/log.%m         #日志文件的存放路径
  9. # maximum size of 50KB per log file, then rotate:
  10. max log size = 50           #日志文件的最大容量
  11. security = user      #samba服务的安全访问级别,user是基于smb配置的用户的
  12. passdb backend = tdbsam
  13. ; security = domain
  14. ; passdb backend = tdbsam
  15. ; realm = MY_REALM
  16. ; password server = <NT-Server-Name>
  17. ; security = user
  18. ; passdb backend = tdbsam
  19. ; domain master = yes
  20. ; domain logons = yes
  21. # the following login script name is determined by the machine name
  22. # (%m):
  23. ; logon script = %m.bat
  24. # the following login script name is determined by the UNIX user used:
  25. ; logon script = %u.bat
  26. ; logon path = \\%L\Profiles\%u
  27. # use an empty path to disable profile support:
  28. ; logon path =
  29. # various scripts can be used on a domain controller or a stand-alone
  30. # machine to add or delete corresponding UNIX accounts:
  31. ; add user script = /usr/sbin/useradd "%u" -n -g users
  32. ; add group script = /usr/sbin/groupadd "%g"
  33. ; add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u"
  34. ; delete user script = /usr/sbin/userdel "%u"
  35. ; delete user from group script = /usr/sbin/userdel "%u" "%g"
  36. ; delete group script = /usr/sbin/groupdel "%g"
  37. ; local master = no
  38. ; os level = 33
  39. ; preferred master = yes
  40. ; wins support = yes
  41. ; wins server = w.x.y.z
  42. ; wins proxy = yes
  43. ; dns proxy = yes
  44. load printers = yes
  45. cups options = raw
  46. ; printcap name = /etc/printcap
  47. # obtain a list of printers automatically on UNIX System V systems:
  48. ; printcap name = lpstat
  49. ; printing = cups
  50. ; map archive = no
  51. ; map hidden = no
  52. ; map read only = no
  53. ; map system = no
  54. ; store dos attributes = yes

共享配置项说明:[homes]配置节

该配置节用来共享smb用户本身的"家"目录,当使用smb用户登入samba server 后,默认能够看到用户的家目录。

  1. [homes]
  2. comment = Home Directories
  3. browseable = no
  4. writable = yes
  5. ; valid users = %S
  6. ; valid users = MYDOMAIN\%S

共享配置项说明:[printers]配置节

  打印共享配置此处略

共享配置项说明:匿名(公开)共享,允许所有用户访问共享目录

  1. [public]            #共享模块名
  2. comment = Public Stuff    #共享的注释说明信息
  3. path = /share     #共享目录路径,除了smb设置的共享权限外,该目录在操作系统层面的权限也会限制读写权限
  4. public = yes    #是否配置为匿名共享,但是当前smb安全级别为user,所以必须登录用户,当安全级别为share时无需登录
  5. writable = yes     #smb设置的写权限,赋予所有用户写入权限,当与read only冲突时,无视read only配置
  6. printable = no        #是否允许打印
  7. write list = +staff

共享配置项权限管理:

  browseable  在浏览资源中显示共享目录,若为否则必须指定共享路径才能存取

  hide dot ftles  隐藏隐藏文件

  public  公开共享,若为否则进行身份验证(只有当security = share 时此项才起作用)

  guest ok  公开共享,若为否则进行身份验证(只有当security = share 时此项才起作用)

  read only  以只读方式共享当与writable发生冲突时也writable为准

  writable  不以只读方式共享当与read only发生冲突时,无视read only

  vaild users  设定只有此名单内的用户才能访问共享资源(拒绝优先)(用户名/@组名)

  invalid users  设定只有此名单内的用户不能访问共享资源(拒绝优先)(用户名/@组名)

  read list  设定此名单内的成员为只读(用户名/@组名)

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

  create mask  建立文件时所给的权限

  directory mask  建立目录时所给的权限

  force group  指定存取资源时须以此设定的群组使用者进入才能存取(用户名/@组名)

  force user  指定存取资源时须以此设定的使用者进入才能存取(用户名/@组名)

  allow hosts  设定只有此网段/IP的用户才能访问共享资源

  deny hosts  设定只有此网段/IP的用户不能访问共享资源

nginx服务(基于CentOS7.0)

服务安装(yum)

nginx服务安装包没有封装在系统镜像中,需要到epel源仓库中获取。

  1. [root@centos-test yum.repos.d]# yum install epel-release -y      #安装epel源文件,使yum能够访问epel源
  2. [root@centos-test yum.repos.d]# yum install nginx -y          #安装nginx软件包

服务安装(源代码)

  1. [root@centos-test ~]# tar -xzvf nginx-1.12.0.tar.gz     #解压软件包
  2. [root@centos-test ~]# cd nginx-1.12.0/
  3. [root@centos-test nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --without-http_rewrite_module      #配置软件包安装路径,并禁止使用复写模块
  4. [root@centos-test nginx-1.12.0]# make && make install         #安装前提注意安装相应的开发者工具包

服务启动(源代码安装方式)

  1. [root@centos-test ~]# cd /usr/local/nginx/sbin/     #启动脚本所在目录
  2. [root@centos-test sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf      #以/usr/local/nginx/conf/nginx.conf内的配置信息启动服务
  3. [root@centos-test sbin]# netstat -an |grep 80     #查看nginx监听端口是否开启
  4. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
  5. tcp6 0 0 :::52807 :::* LISTEN
  6. udp 0 0 0.0.0.0:4380 0.0.0.0:*
  7. unix 2 [ ACC ] STREAM LISTENING 15680 /var/run/avahi-daemon/socket
  8. unix 3 [ ] STREAM CONNECTED 18680 /var/run/dbus/system_bus_socket
  9. unix 3 [ ] STREAM CONNECTED 18000 /run/systemd/journal/stdout
  10. unix 2 [ ] DGRAM 18001
  11. unix 3 [ ] STREAM CONNECTED 21380
  12. [root@centos-test sbin]# ps aux |grep nginx |grep -v grep
  13. root 5781 0.0 0.2 18496 608 ? Ss 07:23 0:00 nginx: master process ./nginx -c /usr/local/nginx/conf/nginx.conf    #主进程
  14. nobody 5782 0.0 0.5 21028 1356 ? S 07:23 0:00 nginx: worker process        #工作进程

注意,nginx一个主进程可以对应多个工作进程,同时一台机器可以启动多个主进程,但是对应的配置文件必须不同,端口也必须不一个样。

防火墙配置

  1. [root@centos-test sbin]# firewall-cmd --permanent --add-port=80/tcp    #允许访问80端口
  2. success
  3. [root@centos-test sbin]# firewall-cmd --reload   #使配置生效
  4. success
  5. [root@centos-test sbin]# firewall-cmd --list-all   #查询是否开启80端口
  6. public (default, active)
  7. interfaces: eno16777736
  8. sources:
  9. services: dhcpv6-client samba ssh
  10. ports: 80/tcp
  11. masquerade: no
  12. forward-ports:
  13. icmp-blocks:
  14. rich rules:

浏览器访问测试

能够看到该界面表示服务能够正常运行

配置文件说明:

  1. [root@centos-test conf]# cat nginx.conf|grep -v "^$"
  2. #user nobody;
  3. worker_processes 1;     #工作进程数
  4. #error_log logs/error.log;    #错误日志文件所在目录
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;  #每个工作进程的并发连接数
  10. }
  11. http {
  12. include mime.types;   #导入模块,该模块是用来描述信息类型的国际标准,即文件扩展名与文件类型映射表
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '      #日志格式,可以自定义
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;   #连接日志存放路径,并调用main日志格式
  18. sendfile on;
  19. #tcp_nopush on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 65;    #用户访问连接超时时间,单位秒
  22. #gzip on;
  23. server {                            
  24. listen 80;       #监听端口
  25. server_name localhost;                
  26. #charset koi8-r;
  27. #access_log logs/host.access.log main;
  28. location / {                    
  29. root html;    #网站家目录
  30. index index.html index.htm;  #主页文件
  31. }
  32. #error_page 404 /404.html;
  33. # redirect server error pages to the static page /50x.html
  34. #
  35. error_page 500 502 503 504 /50x.html;
  36. location = /50x.html {
  37. root html;
  38. }
  39. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  40. #
  41. #location ~ \.php$ {
  42. # proxy_pass http://127.0.0.1;
  43. #}
  44. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  45. #
  46. #location ~ \.php$ {
  47. # root html;
  48. # fastcgi_pass 127.0.0.1:9000;
  49. # fastcgi_index index.php;
  50. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  51. # include fastcgi_params;
  52. #}
  53. # deny access to .htaccess files, if Apache's document root
  54. # concurs with nginx's one
  55. #
  56. #location ~ /\.ht {
  57. # deny all;
  58. #}
  59. }
  60. # another virtual host using mix of IP-, name-, and port-based configuration
  61. #
  62. #server {
  63. # listen 8000;
  64. # listen somename:8080;
  65. # server_name somename alias another.alias;
  66. # location / {
  67. # root html;
  68. # index index.html index.htm;
  69. # }
  70. #}
  71. # HTTPS server
  72. #
  73. #server {
  74. # listen 443 ssl;
  75. # server_name localhost;
  76. # ssl_certificate cert.pem;
  77. # ssl_certificate_key cert.key;
  78. # ssl_session_cache shared:SSL:1m;
  79. # ssl_session_timeout 5m;
  80. # ssl_ciphers HIGH:!aNULL:!MD5;
  81. # ssl_prefer_server_ciphers on;
  82. # location / {
  83. # root html;
  84. # index index.html index.htm;
  85. # }
  86. #}
  87. }

服务配置(负载均衡)

环境说明:一台访问的代理机器,三台web机器,代理机负责将访问转发给web机

web1机器配置:

  1. [root@nginx-web1 ~]# cd /usr/local/nginx/html/
  2. [root@nginx-web1 html]# mv index.html index.html.apk
  3. [root@nginx-web1 html]# echo server1 >>index.html

web2机器配置:

  1. [root@nginx-web2 ~]# cd /usr/local/nginx/html/
  2. [root@nginx-web2 html]# mv index.html index.html.apk
  3. [root@nginx-web2 html]# echo server2 >>index.html

web3机器配置:

  1. [root@nginx-web3 ~]# cd /usr/local/nginx/html/
  2. [root@nginx-web3 html]# mv index.html index.html.apk
  3. [root@nginx-web3 html]# echo server3 >>index.html

三台web启动nginx:

  1. [root@nginx-web1 html]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  2. [root@nginx-web2 html]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  3. [root@nginx-web3 html]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

验证三台web配置

轮询模式配置

轮询即后端的三台web服务器依次访问一次

修改代理机器配置文件nginx.conf

  1. http {
  2. upstream myapp1 {    #myapp1名字可以随便起,下面调用替换即可
  3. server 192.168.1.1;
  4. server 192.168.1.2;
  5. server 192.168.1.3;
  6. }
  7.  
  8. server {
  9. listen 80;
  10.  
  11. location / {
  12. proxy_pass http://myapp1;
  13. }
  14. }
  15. }

修改完启动服务

  1. [root@nginx-agent ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

轮询验证(访问后不断刷新即可)

最小连接数模式配置

当新的访问过来后,转发给现在连接数最少的web上

修改代理机器配置文件nginx.conf

  1. upstream myapp1 {
  2. least_conn;
  3. 192.168.1.1;
  4. 192.168.1.2;
  5. 192.168.1.3;
  6. }

重新生效配置文件

  1. [root@nginx-agent ~]# /usr/local/nginx/sbin/nginx -s reload

最小链接数验证

(没验证,主机数量限制)

权重模式配置

轮询的过程中加上权重值,权重高的接收的连接数多

修改配置文件

  1. upstream myapp1 {
  2. server 192.168.1.1 weight=3;
  3. server 192.168.1.2;
  4. server 192.168.1.3;
  5. }

权重模式验证

刷新五次页面,会有三次出现server1,一次server2,一次server3,顺序可能不一样。

ip哈希模式配置

当一个访问过来,按照hash算法对发出访问请求的ip地址进行计算,匹配到一个web服务器上

ip哈希模式配置

  1. upstream myapp1 {
  2. ip_hash;
  3. server 192.168.1.1;
  4. server 192.168.1.2;
  5. server 192.168.1.3;
  6. }

ip哈希模式验证

访问后,只会匹配到一个web服务器,不断刷新,访问你的内容不会变

Linux基础系列-Day6的更多相关文章

  1. Linux基础系列-Day2

    基础命令(文件内容管理) 1.cat:在当前终端显示文本文件内容 格式:cat [文件路径] -n 从1开始对所有输出的行数编号 -b 和-n相似,只不过对于空白行不编号:2.head:从文件内容开头 ...

  2. Linux基础系列-Day1

    Linux发展简史 Unix:1969年由美国电话电报公司(AT&T)贝尔实验室的两个工程师所创造的操作系统,它允许计算机同时处理多用户和程序. BSD:重要的Unix分支,1977年由加州大 ...

  3. Linux基础系列—Linux内核源码目录结构

    /** ****************************************************************************** * @author    暴走的小 ...

  4. Linux基础系列—Linux体系结构和Linux内核结构

    /** ****************************************************************************** * @author    暴走的小 ...

  5. Linux基础系列-Day8

    Shell编程基础 Shell介绍 Shell俗称壳(用来区别于核),是指“提供使用者使用界面”的软件(命令解析器).它类似于windows下的的cmd.exe.它接收用户命令,然后调用相应的应用程序 ...

  6. Linux基础系列-Day7

    NFS服务(基于CentOS 7.0) NFS(Network File System),网络文件系统,是linux与linux之间进行文件共享的服务,在NFS应用,本地NFS的客户端可以透明地读写位 ...

  7. Linux基础系列-Day5

    网络管理 ifconfig网络管理工具 ifconfig依赖于命令中使用一些选项属性,不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置,但是通过ifconfig修改的通常为临时配置,即系统 ...

  8. Linux基础系列-Day4

    top系统监控 top命令可以实时动态地查看系统的整体运行情况,是一个综合了多方信息监测系统性能和运行信息的实用工具.通过top命令所提供的互动式界面,用热键可以管理. [root@centos-py ...

  9. Linux基础系列-Day3

    Vim文本编辑器 •Linux设计的重要原则是信息存储在基于文本的文件中.  注:Linux“一切皆文件”是指包含文本文件和用户不可读的二进制文件(如block设备文件) •文本文件:无格式文件,作用 ...

随机推荐

  1. yum快速安装gitlab

    安装gitlab前戏使用官方的源,还是比较慢的,gitlab官方提供了一个清华大学的源 新建 /etc/yum.repos.d/gitlab-ce.repo,内容为 源[gitlab-ce]name= ...

  2. Sass 条件-循环语句

    学习Sass中 @if...@else @for @while @each 一.条件判断 - @if @else 示例: @mixin blockOrHidden($boolean:true){ @i ...

  3. 表单元素(form、文本、按钮、选择)

    表单元素 一.form form代表表单,功能:用于申明表单,定义采集数据的范围,也就是<form>和</form>里面包含的数据将被提交到服务器或者电子邮件里.<for ...

  4. 数据分析之CE找数据大法

    一.基本介绍 CE的全称为Cheat Engine,是一款内存修改编辑工具,其官网是http://www.cheatengine.org,可以在其官网下载到最新的CE工具,目前最新版本是Cheat E ...

  5. 【HNOI】 lct tree-dp

    [题目描述]给定2-3颗树,每个边的边权为1,解决以下独立的问题. 现在通过连接若干遍使得图为连通图,并且Σdis(x,y)最大,x,y只算一次. 每个点为黑点或者白点,现在需要删除一些边,使得图中的 ...

  6. 头像截取 图片上传 js插件

    先看一下整体效果 页面html <div class="row"> <div class="tabs-container"> <u ...

  7. ES6新增的let与const

    1.const 声明常量,一旦声明必须立马赋值,否则报错 const PI = 3.14 const PI; //报错:Uncaught SyntaxError: Missing initialize ...

  8. 增大dma的分配

    前言 项目中需要通过驱动与fpga通讯,获取fpga往内存里写的数据.因为数据量比较大,需要驱动分配600多M的内存给fpga来写数据,且因为是与fpga通讯,需要连续的内存,还得是uncached的 ...

  9. PHP下载APK文件

    PHP下载APK文件(代码如下) /** * //这里不要随便打印文字,否则会影响输出的文件的 * (例如下载没问题,但是apk安装时候提醒解析安装包错误) * @return array */ pu ...

  10. 502 bad gateway,ngix

    1.ftm对nginx的解析出现问题:20171228