CenOS 7 安裝配置Samba服務

參考http://www.howtoforge.com/samba-server-installation-and-configuration-on-centos-7

實現windows 7與centos 7的文件夾共享,本人的是windows7系統下安裝的centos7 虛擬機,橋接模式

不知是不是因爲VM的原因,共享文件夾不可用,所以迫不得已使用samba共享,以下是具體步驟,個人驗證可用

一、編輯C:\Windows\System32\drivers\etc\hosts

 

  1. # Copyright (c) 1993-2009 Microsoft Corp.  

  2. #  

  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.  

  4. #  

  5. # This file contains the mappings of IP addresses to host names. Each  

  6. # entry should be kept on an individual line. The IP address should  

  7. # be placed in the first column followed by the corresponding host name.  

  8. # The IP address and the host name should be separated by at least one  

  9. # space.  

  10. #  

  11. # Additionally, comments (such as these) may be inserted on individual  

  12. # lines or following the machine name denoted by a '#' symbol.  

  13. #  

  14. # For example:  

  15. #  

  16. #      102.54.94.97     rhino.acme.com          # source server  

  17. #       38.25.63.10     x.acme.com              # x client host  

  18.   

  19. # localhost name resolution is handled within DNS itself.  

  20. #   127.0.0.1       localhost  

  21. #   ::1             localhost  

  22.   

  23. 127.0.0.1 genuine.microsoft.com  

  24. 127.0.0.1 mpa.one.microsoft.com  

  25. 127.0.0.1 sls.microsoft.com  

  26. 192.168.10.187 localhost.localdomain centos  

  27. #ip地址是centos的ip,localhost.localdomain表示centos的hostname,最後一個參數centos表示centos的別名,即可以通過\\centos訪問centos的共享文件夾</span>  

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

127.0.0.1 genuine.microsoft.com
127.0.0.1 mpa.one.microsoft.com
127.0.0.1 sls.microsoft.com
192.168.10.187 localhost.localdomain centos
#ip地址是centos的ip,localhost.localdomain表示centos的hostname,最後一個參數centos表示centos的別名,即可以通過\\centos訪問centos的共享文件夾</span>


直接打開hosts文件是無法修改的,有兩種解決方法:

一是以管理員權限打開記事本程序,然後在記事本程序裏打開hosts文件,二是把hosts文件拷貝出來修改後再進行覆蓋


二、安裝samba服務相關包

yum install samba samba-client samba-common


查看相關包
~#: rpm -qa| grep samba
samba-common-4.1.1-37.el7_0.x86_64
samba-4.1.1-37.el7_0.x86_64
samba-libs-4.1.1-37.el7_0.x86_64
samba-client-4.1.1-37.el7_0.x86_64

修改smb.conf,最好先備份原文件,以防修改不正確導致smb無法執行

vi /etc/samba/smb.conf

 

  1. [global]  

  2. workgroup = WORKGROUP  

  3. server string = Samba Server %v  

  4. netbios name = centos  

  5. security = user  

  6. map to guest = bad user  

  7. dns proxy = no  

  8. #============================ Share Definitions ==============================   

  9. [Anonymous]  

  10. path = /samba/anonymous  

  11. browsable =yes  

  12. writable = yes  

  13. guest ok = yes  

  14. read only = no   

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = centos
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ============================== 
[Anonymous]
path = /samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no

 

執行以下命令,啓動samba服務

mkdir -p /samba/anonymous
systemctl enable smb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service


三、 跳過防火牆

 一種方法是關閉防火牆

 systemctl stop firewalld.service

setenforce 0

二方法是添加規則

firewall-cmd --permanent --zone=public --add-service=samba

 

firewall-cmd --reload

 

四、輸入\\centos 即可看到共享文件了,so happy~


#ip地址是centos的ip,localhost.localdomain表示centos的hostname,最後一個參數centos表示centos

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章