[Linux Notes] samba source code installation and basic usage instructions
Some time ago, the project encountered the need to upload multimedia files from a windows machine to a linux Server (manual review and triggering synchronization), and investigated several upload mechanisms or implementation solutions:
1) Upload to WebServer in http mode
PHP or Python scripts are used to upload files to the WebServer. However, due to the hundreds of megabytes of multimedia files, PHP is first excluded due to the maximum execution time, in addition, because the control logic such as failure retry needs to be added for script uploading, although Python can implement these functions, it is not the optimal solution considering the development cost and service stability.
2) flash upload
For example, the Baidu cloud web client uses the flash upload method. The chrome debugging tool shows that the Baidu cloud web Client's upload button calls swfupload. For more information about swfupload, can refer to here or here), but because I have no idea about this solution, the development cost is too high, so I can only give up -_-
3) ftp upload
Build an ftp server on a Linux server, install the ftp client tool on a Windows client, and drag and drop the tool to upload files. However, due to the particularity of the network topology in the factory and the specifications of server O & M, this method can meet service requirements, but it is troublesome to implement it.
4) other open-source file synchronization tools
Samba is the first open-source tool to consider business requirements and machine business specifications. It is found that samba can easily meet requirements.
The following sections take notes on Samba source code installation and basic configuration methods.
1. What is Samba?
Samba is an open-source software that can share files or printers between machines with different operating systems. Samba is especially convenient when files need to be shared between the Window client and the Linux server. For more information, see the official website or wiki pedia.
2. Install the source code
Take v4.1.9 as an example. The source code compilation/installation steps (the installation requires the root permission) are as follows:
1) download the latest version of the source code from the samba website, decompress it, and go to the source code directory.
2) Make sure that the default python version is 2.7 + and -- enable-shared is configured during python compilation. Otherwise, an error will be reported during samba compilation.
3) execute the command:./configure & make install. samba will be installed under/usr/local/samba/path by default.
4) Configure/usr/local/samba/etc/smb. conf as needed, such as setting the shared directory and user.
5) Start two daemon related to samba in sequence:
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 above startup command is the actual path of the configuration file after samba is installed.
NOTE 2: echo $? Check the process startup status or run ps aux | grep db to check whether the process already exists. You can also run netstat-tnlp to check whether smbd is in port listening status (tcp ports 139 and 445, for more information about how to listen to two ports, see the Firewall Configuration section.) nmdb uses udp port 137.
6. Run/usr/local/samba/bin/smbclient-U %-L localhost on the terminal to test whether the samba daemon service is normal. If no error is reported, the samba service has been started successfully.
For the official Install Guide, refer to here.
3. Basic Samba Configuration
The typical path of samba configuration file is/etc/samba/smb. conf or/usr/local/samba/etc/smb. conf, File Syntax and windows. ini is similar: the file contains multiple sections marked with "[]". The configuration items under each section follow the format of key = value.
In samba. conf, each section represents a meta-service or shared configuration of the samba server. [Global] is special. The configuration items contained in it affect the configuration of the entire samba server. [homes] or [printers] are called meta-service, by default, the former sets each user's home directory as a writable shared directory for this user. The latter provides print queue support and configures the storage path for print tasks from samba clients.
We can configure multiple sections as needed, for example:
[Shared] comment = Global Share - All Users path = /samba/shared read only = No guest ok = Yes public = Yes browseable = Yes create mask = 0666 directory mask = 0777
The role of the preceding configuration is that all users (including guest and public users) can browse or read/write/samba/shared directories. The default permission for creating a new directory under this shared directory is 777, the default permission for creating a new file is 666.
The following configuration can disable the default "printer and fax" shared directory.
load printers = no printcap name = /dev/null ## hide printers and faxes share disable spoolss = yes
For more information about how to configure hidden files or folders, see the instructions on the official website.
4. Samba user management
Samba user management depends on linux User management, that is, Samba users must also be added to Linux systems, but passwords can be independent.
The typical steps to add a new user are as follows:
1) Use the linux root Account to execute the adduser command to add the linux system user and the password for logging on to the linux system (this user name is also the username for logging on to samba)
2) use the smbapasswd tool to set the password for logging on to samba for the new user added in the previous step.
3) in the correct section of smb. conf, set a valid user for the shared directory. The typical configuration is as follows:
[video-upload] comment = Shared Director for 3rd-party videos path = /home/slvher/cooperate-uploads valid users = slvher public = 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. In this case, you can log on to the samba server on a windows client to share files.
5. Windows clients access the Samba Service
If the preceding steps are correctly executed, you can log on to the samba server by running the command line \ samba-svr-ip \ slvher and entering the username/password in the pop-up dialog box.
After successful logon, a shared folder will be opened. You can drag the file with the mouse to trigger automatic samba synchronization.
[References]
1. Samba Official Website
2. Installing Samba on a Unix System
3. online-doc: using_samba: ch09. Users and Security