"Linux Notes" Samba source installation and basic usage instructions

Source: Internet
Author: User
Tags ftp client python script

The previous time project encountered the need to upload multimedia files from a Windows machine to a Linux server (manually audited and triggered synchronization), investigating several upload mechanisms or implementations:

1) HTTP mode upload to webserver
With PHP or Python script to the webserver, but because the multimedia files are often hundreds of trillion, PHP due to the maximum execution time limit is first excluded, in addition, because the script upload needs to increase the failure to retry the control logic, although Python can implement these functions, But considering the development cost and the stability of the service, it is not the optimal solution.

2) Flash mode upload
For example, Baidu Cloud Web-based use of flash upload, through the Chrome debugging tools can be seen, Baidu Cloud Web upload button call is SWFUpload, about swfupload introduction, can refer here or here), but because before the program completely did not understand, Development costs are too high, so you can only give up-_-

3) FTP mode upload
In the Linux server to build an FTP server, the Windows Client installation of the FTP client tool, mouse drag to achieve file upload. But because of the particularity of the network topology in the factory and the server operation and maintenance specification, this way although the technology can realize the business demand, it is more troublesome to realize.

4) Other open source file Sync Tool
The first thing that comes to mind in open source tools is samba, which, after considering business requirements and machine business specifications, discovers that samba can easily implement the requirements.

The following sections of this article are notes on the Samba source installation and basic configuration methods.

1. What is Samba?
Samba is a set of open source software that can share files or printers between machines with different operating systems installed. Samba is especially handy when you need to share files between window clients and Linux servers. More systematic introduction can refer to the official website or wiki pedia

2. Source Code Installation procedure
Take v4.1.9 as an example, the source code compilation/installation steps (installation requires root permissions) are as follows:
1) Download the latest version of source code from samba website, unzip, enter the source directory
2) ensure that the default Python version of the system is 2.7+ and the--enable-shared is configured when compiling Python, otherwise the subsequent compilation of samba will error
3) Execute the command:./configure && make && makes Install,samba will be installed by default on/usr/local/samba/path
4) According to the actual business needs, configure/usr/local/samba/etc/smb.conf, such as set up a shared directory and users, etc.
5) Start Samba-related 2 daemons in turn:

shell>/usr/local/samba/sbin/smbd-s/usr/local/samba/etc/smb.conf-dshell>/usr/local/samba/sbin/nmbd-s/usr/ Local/samba/etc/smb.conf-d
Note 1: The/xxx_path/smb.conf in the boot command above is the actual path to the profile after the installation of Samba
Note 2: Can be viewed through the echo $? View process startup status, or via PS aux | grep db to see if the process already exists, also through NETSTAT-TNLP to see if SMBD is in Port listening state (TCP ports 139 and 445, as for why listen to the two ports, refer to the Firewall configuration section here) ; Nmdb is using UDP 137 port
6. Terminal execution/usr/local/samba/bin/smbclient-u%-l localhost, test samba daemon service is normal, if not error, indicate Samba service started successfully

The Official install Guide can be found here

3. Samba Basic Configuration
Samba's configuration file typically has a path of/etc/samba/smb.conf or/usr/local/samba/etc/smb.conf, and the file syntax is similar to the. ini for Windows: Files contain multiple sections identified by "[]" for a number of years , the configuration item under each section adheres to the format of key = value.
samba.conf, each section represents a Meta-service or shared configuration for the Samba server. where [global] is special, it contains configuration items that affect the configuration of the entire Samba server, [homes] or [printers] is called Meta-service, which by default sets each user's own home directory to the user-writable shared directory. The latter provides a print queue that supports and configures the storage path for print jobs from each samba client.
We can configure multiple sections according to the actual needs, such as:

[Shared]   Comment = Global share-all Users   path =/samba/shared   Read Only = No   guest OK = yes public   = yes   bro wseable = Yes   Create mask = 0666   directory mask = 0777
The purpose of the above configuration is: All users (including guest and public users) can browse or read and write to the/samba/shared directory, the default permission to create a new directory under the shared directory is 777, the default permission to create a new file is 666
The following configuration can turn off the default printers and Faxes shared directory
   Load printers = no   printcap name =/dev/null   # hide Printers and Faxes share disable SPOOLSS   = yes
other hidden file or folder configuration method, you can refer to the official website document Description

4. Samba User Management
The user management of samba is dependent on the user management of the Linux system, that is, the users of Samba must also be users of the Linux system, but the passwords can be independent.
The typical steps for adding a new user are:
1) Add the Linux system user and login to the Linux system password (this username is also the username of the login samba) by executing the adduser command in the Linux root account.
2) Use the SMBAPASSWD tool to set the login Samba password for new users added in the previous step
3) in the smb.conf correct section, set up a valid user for the shared directory, typically configured as follows

[Video-upload]   Comment = Shared Director for 3rd-party videos   path =/home/slvher/cooperate-uploads   Valid users = Slvher   Pub LIC = no   writable = yes   printable = no   hide dot files = Yes   Create mask = 0766
After updating the configuration file smb.conf, restart the SMBD and NMBD processes, at which point we can share files in the Windows client by logging into the Samba server

5. Windows Client access to Samba services
You can log in to the Samba server by entering \\samba-svr-ip\slvher on the Windows machine Run command line and entering the username/password in the popup dialog box, provided the above steps are correctly executed.
Once the login is successful, a shared folder will be opened, and the file can be automatically synced by dragging the files with the mouse.

Resources
1. Samba Official website
2. Installing Samba on a Unix System
3. online-doc:using_samba:ch09. Users and Security

"Linux Notes" Samba source installation and basic usage instructions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.