Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, January 20, 2011

HP-UX: Intro Guardian Service Processor(GSP) & Management Processor(MP)

All of HP's current PA-RISC and Integrity servers include a GSP/MP card which has a LAN console port.This console port is
usually called as GSP/MP port which depends on which card(GSP/MP) is installed in the physical machine.But mostly these days MP card is installed on HP-UX Servers by default.

Features:


* Enables remote server management over the web regardless of the system state.

* In the unlikely event that the operating system in not running,the GSP/MP port can be accessed to power cycle the
server
,view event logs and status logs,enable console re-direction,and more.
* Always-on capability: GSP/MP is alive if the power cord is plugged in.
* User/Password access control: Supports operator and administrator users
* Multiple access methods to GSP/MP:
Local port
Remote/modem port
LAN
*Mirrored console:System console output stream is reflected to all of the connected console users
*Display and/or logging of:
The system console,system event logs (chassis codes),Virtual Front Panel (VFP),and system power and configuration
status.
*GSP/MP provides power control,system reset,and Transfer Of Control (TOC) capabilities.

Note:
This GSP/MP is similar to Sun™ Advanced Lights Out Manager (ALOM)

Procedure to configure IP for GSP Port in HP-PA Server Models

Step 1: Connect a terminal to the console port of the system.

Step 2: Login to the console using username and password. The default username for GSP is typically root and the default password is root.

Step 3: Press Ctrl+B to go to the GSP prompt. Sometimes, it is required to press Ctrl+Ecf to get write access to the console.

Step 4: Type “lc” on the GSP prompt to modify the IP configuration and press “Y” when prompted for modification

Current configuration:

MAC Address : 0x00110a417c09

IP Address : --------------

GSP Host Name : --------------

Subnet Mask : --------------

Gateway : --------------

Web Console Port Number : 2023

Do you want to modify the LAN configuration? (Y/[N]): y

Step 5: Press “Y” when prompted to modify the Current IP Address.

Current IP Address:

Do you want to modify it? (Y/[N]): y

Step 6: Type the IP address of the GSP port and press “Y” to confirm.

New IP Address: 172.16.1.100

Confirm? (Y/[N]): y

Step 7: Press “Y” when prompted to modify the current GSP Host Name.

Current GSP Host Name:

Do you want to modify it? (Y/[N]): y

Step 8: Type the hostname of the GSP port and press “Y” to confirm

New GSP Host Name: m1sys100

Confirm? (Y/[N]): y

Step 9: Press “Y” when prompted to modify the current Subnet Mask.

Current Subnet Mask:

Do you want to modify it? (Y/[N]): y

Step 10: Type the subnet mask of the GSP port and press “Y” to confirm

Enter new Subnet Mask: 255.255.224.0

Confirm? (Y/[N]): y

Step 11: Press “Y” when prompted to modify the current Gateway.

Current Gateway:

Do you want to modify it? (Y/[N]): y

Step 12: Type the gateway of the GSP port and press “Y” to confirm.

Enter New Gateway: 172.16.0.1

Confirm? (Y/[N]): y

Step 13: Press “n” when prompted to modify the current Web Console Port.

Current Web Console Port Number: 2023

Modifying Web Port number will cause all present Web

connections to be dropped.

Do you want to modify it? (Y/[N]): n

-> Reset the GSP for LAN configuration to take effect.

-> Use the R option of the XD command to reset the GSP

Step 14: Type “xd” at the GSP prompt and press “r” to reset the GSP.

Step 15: From any of the lab machines, ping to the newly configured IP address of the GSP and see if it is alive on the network.

Steps to Configure IP for MP-Port in HP Servers

Step 1: Connect a terminal to the console port of the system.

Step 2:
Login tothe console using username and password. The default username for MP is typically Admin and the default
password is Admin.
Step 3: Type “cm” on the MP prompt to go to the MP command menu
Step 4: Type “lc” on the MP CM prompt to modify the LAN configuration and press “A” when prompted for modification
Current LAN Configuration:
- - MAC Address : 0x001635b66433
D - DHCP Status : Disabled
I - IP Address : ---------------
M - MP Host Name: ---------------
S - Subnet Mask : ---------------
G - Gateway Address : ------------
L - Link State : Auto Negotiate
W - Web Console Port Number : 2023
- - SSH Access Port Number : - (MP Feature Not Licensed)
- - IPMI / LAN Port Number : 623A


Enter parameter(s) to change, A to modify All, or [Q] to Quit:


Step 5: Type the IP address of the MP port.

IP Address:
Current ->
127.0.0.1 (default)

Modifying this parameter will cause all present LAN and Web connections to be dropped.
Enter new value, or Q to Quit: 172.16.1.100
Step 6: Type the hostname of the MP port.
Host Name:
Current ->
mp001635b66433 (default)

Enter new value, or Q to Quit: m1sys100
Step 7: Type the Subnet Mask of the MP port.
Subnet Mask:
Current ->
255.255.255.0 (default)

Modifying this parameter will cause all present LAN and Web connections to be dropped.

Enter new value, or Q to Quit: 255.255.224.0
Step 8: Type the Gateway of the MP port.
Gateway Address:
Current ->
127.0.0.1 (default)

Enter new value, or Q to Quit: 172.16.0.1
Step 9: Press “Enter” when prompted for Web Console Port Number.
Web Console Port Number:
Current -> 2023 (default)
Options: 23, 2000 to 2400

Modifying Web Port number will cause all present Web connections to be dropped.

Enter new value, or Q to Quit:

-> Current Web Console Port Number has been retained

Step 10: Press “Enter” when prompted for SSH Console Port Number.
SSH Console Port Number:
Current -> 22 (default)
Options: 22, 2000 to 2400

Enter new value, or Q to Quit:
-> Current SSH Console Port Number has been retained
Step 11: Type “Disabled” or “D” when prompted for DHCP Status.
DHCP Status:
Current -> D - Disabled
E - Enabled (default)

Modifying this parameter will cause all present LAN and Web connections to be dropped.

Enter new value, or Q to Quit: Disabled

Step 12: Press “Enter” when prompted for Link State.
Link State:
Current -> A - Auto Negotiate (default)
T - 10BaseT

Modifying this parameter will cause all present LAN and Web connections to be dropped.


Enter new value, or Q to Quit:

-> Current Link State has been retained

Step 13: Type “xd” on the MP CM prompt and press “r” to reset MP.
Step 14: From any of the lab machines, ping to the newly configured IP address of the GSP and see if it is alive on the
network.

Wednesday, December 15, 2010

Linux audit files to see who made changes to a file

http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html

Tuesday, November 23, 2010

How to install Linux / UNIX *.tar.gz tarball files

Q. I’m new to Linux. Over few days I found lots software distributed as .tar.gz file. How do I install tar.gz files under Linux?

A. tar.gz also known as tarball, an archive format for electronic data and software. Most Linux tarball contains a source code for software. If you are new to Linux I recommend using apt-get, rpm and yum command to install all binary packages.

Tarballs are a group of files in one file. Tarball files have the extension .tar.gz, .tgz or .tar.bz2. Most open source software use tarballs to distribute programs/source codes.

dpkg -l | grep gcc -->> kiem tra gcc install trên server
apt-get install gcc --> install gcc

# 1: Uncompress tarball

To uncompress them, execute the following command(s) depending on the extension:
$ tar zxf file.tar.gz
$ tar zxf file.tgz
$ tar jxf file.tar.bz2
$ tar jxf file.tbz2

Now change directory
$ ls
$ cd path-to-software/

# 2: Build and install software

Generally you need to type 3 commands as follows for building and compiling software:
# ./configure
# make
# make install

Where,

  • ./configure will configure the software to ensure your system has the necessary functionality and libraries to successfully compile the package
  • make will compile all the source files into executable binaries.
  • Finally, make install will install the binaries and any supporting files into the appropriate locations.

# 3: Read INSTALL / README file

Each tarball comes with installation and build instructions. Open INSTALL or README file for more information:
$ vi INSTALL

Saturday, November 20, 2010

Backup on Ubuntu (Samba or Windows Share)

Intro
These notes are my reminder notes on how to use rsync for backup with Samba or Windows shares on your LAN.

Installing Backup Tools
The following tools are needed:
  • Samba file system (smbfs)
  • Grapical interface for rsync (grsync)
Install the tools with:
sudo apt-get install smbfs grsync

"Map" remote share
Create folder for mounting remote share:
mkdir /home/username/smb
mkdir /home/username/smb/backup


Backup process
Step1: Mount remote share:
smbmount //samba_server_name/samba_share /home/username/smb/backup -o username=samba_username,password=samba_password

Step2: Synchronize folders
run Grsync, by click on Applications->Internet->Grsync


This happened to be working great for me. If you want to backup the whole home folder be careful to mount your samba share somewhere else (not as subfolder within home). Grsync is nice front GUI for rsync.
I am using this setup to perform daily backups of my Documents folder to the remote Samba share. Grsync can be used with a local hard drive or USB key without need to mount remote samba share.

Friday, November 19, 2010

Kiểm tra cấu hình phần cứng

Inside the /proc directory, you’ll see two types of content — numbered directories, and system information files.

/proc is not a real file system, it is a virtual file system. For example, if you do ls -l /proc/stat, you’ll notice that it has a size of 0 bytes, but if you do “cat /proc/stat”, you’ll see some content inside the file.

Several Linux commands access the information from /proc, and displays in a certain format.

1. /proc Directories with names as numbers

Do a ls -l /proc, and you’ll see lot of directories with just numbers. These numbers represents the process ids, the files inside this numbered directory corresponds to the process with that particular PID.

Following are the important files located under each numbered directory (for each process):

  • cmdline – command line of the command.
  • environ – environment variables.
  • fd – Contains the file descriptors which is linked to the appropriate files.
  • limits – Contains the information about the specific limits to the process.
  • mounts – mount related information

Following are the important links under each numbered directory (for each process):

  • cwd – Link to current working directory of the process.
  • exe – Link to executable of the process.
  • root – Link to the root directory of the process.

2. /proc Files about the system information

Following are some files which are available under /proc, that contains system information such as cpuinfo, meminfo, loadavg.

  • /proc/cpuinfo – information about CPU,
  • /proc/meminfo – information about memory,
  • /proc/loadvg – load average,
  • /proc/partitions – partition related information,
  • /proc/version – linux version

Some Linux commands read the information from this /proc files and displays it. For example, free command, reads the memory information from /proc/meminfo file, formats it, and displays it.

To learn more about the individual /proc files, do “man 5 FILENAME”.

  • /proc/cmdline – Kernel command line
  • /proc/cpuinfo – Information about the processors.
  • /proc/devices – List of device drivers configured into the currently running kernel.
  • /proc/dma – Shows which DMA channels are being used at the moment.
  • /proc/fb – Frame Buffer devices.
  • /proc/filesystems – File systems supported by the kernel.
  • /proc/interrupts – Number of interrupts per IRQ on architecture.
  • /proc/iomem – This file shows the current map of the system’s memory for its various devices
  • /proc/ioports – provides a list of currently registered port regions used for input or output communication with a device
  • /proc/loadavg – Contains load average of the system
    The first three columns measure CPU utilization of the last 1, 5, and 10 minute periods.
    The fourth column shows the number of currently running processes and the total number of processes.
    The last column displays the last process ID used.
  • /proc/locks – Displays the files currently locked by the kernel
    Sample line:
    1: POSIX ADVISORY WRITE 14375 08:03:114727 0 EOF
  • /proc/meminfo – Current utilization of primary memory on the system
  • /proc/misc – This file lists miscellaneous drivers registered on the miscellaneous major device, which is number 10
  • /proc/modules – Displays a list of all modules that have been loaded by the system
  • /proc/mounts – This file provides a quick list of all mounts in use by the system
  • /proc/partitions – Very detailed information on the various partitions currently available to the system
  • /proc/pci – Full listing of every PCI device on your system
  • /proc/stat – Keeps track of a variety of different statistics about the system since it was last restarted
  • /proc/swap – Measures swap space and its utilization
  • /proc/uptime – Contains information about uptime of the system
  • /proc/version – Version of the Linux kernel, gcc, name of the Linux flavor installed.

Wednesday, October 27, 2010

Linux System Monitoring

1.You need to determine which process is monopolizing or eating the CPUs. Following command will displays the top 10 CPU users on the Linux system.

# ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
OR
# ps -eo pcpu,pid,user,args | sort -r -k1 | less

2.http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

Sunday, October 3, 2010

RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams

RAID stands for Redundant Array of Inexpensive (Independent) Disks.

On most situations you will be using one of the following four levels of RAIDs.

  • RAID 0
  • RAID 1
  • RAID 5
  • RAID 10 (also known as RAID 1+0)

This article explains the main difference between these raid levels along with an easy to understand diagram.

In all the diagrams mentioned below:

  • A, B, C, D, E and F – represents blocks
  • p1, p2, and p3 – represents parity

RAID LEVEL 0


Following are the key points to remember for RAID level 0.

  • Minimum 2 disks.
  • Excellent performance ( as blocks are striped ).
  • No redundancy ( no mirror, no parity ).
  • Don’t use this for any critical system.

RAID LEVEL 1

Following are the key points to remember for RAID level 1.

  • Minimum 2 disks.
  • Good performance ( no striping. no parity ).
  • Excellent redundancy ( as blocks are mirrored ).

RAID LEVEL 5


Following are the key points to remember for RAID level 5.

  • Minimum 3 disks.
  • Good performance ( as blocks are striped ).
  • Good redundancy ( distributed parity ).
  • Best cost effective option providing both performance and redundancy. Use this for DB that is heavily read oriented. Write operations will be slow.

RAID LEVEL 10



  • Minimum 4 disks.
  • Excellent performance ( as blocks are striped )
  • Excellent redundancy ( as blocks are mirrored )
  • If you can afford the dollar, this is the BEST option for any mission critical applications (especially databases).
http://www.acnc.com/04_01_00.html

Thursday, August 12, 2010

10 Awesome Examples for Viewing Huge Log Files in Unix

http://www.thegeekstuff.com/2009/08/10-awesome-examples-for-viewing-huge-log-files-in-unix/

Sunday, August 8, 2010

Squid cache chậm

squid cache bị chậm thường do I/O trên disk cache mà ra. Để gia tăng vận tốc, nên trải disk cache ra nhiều thư mục khác nhau nằm trên nhiều đĩa khác nhau (để gia tăng băng thông). Thay vì:
cache_dir ufs /path/to/cache 500000 16 256

nên chẻ nó ra:
cache_dir ufs /path/to/cache1 100000 16 256
cache_dir ufs /path/to/cache2 100000 16 256
cache_dir ufs /path/to/cache3 100000 16 256
cache_dir ufs /path/to/cache4 100000 16 256

Khi mount các partition trên, nên sử dụng noatime và nodfratime options. Nếu hệ thống squid này an toàn và không có ai sử dụng (không access trực tiếp) thì nên thêm noxattr. Những cái này sẽ gia tăng hiệu suất cho disk cache. nếu được, nên dùng ReiserFS thay vì ext3 cho disk cache.

Ngoài ra nên chỉnh các directives:
maximum_object_size
minimum_object_size
maximum_object_size_in_memory

cho thích hợp. Không phải cái gì cũng cache thì tốt.

Nên set giá trị max_open_disk_fds cho thích hợp thay vì để mặc định nếu có vấn đề với disk I/O bởi vì nếu set 0 (unlimited) mà ulimit lại ấn định thấp hơn thì sẽ khiến squid bị trì trệ. Trên OS level, nên set file descriptor lên ít nhất là 8192 và nên áp dụng cùng giá trị này cho max_open_disk_fds.

Thursday, April 15, 2010

50 UNIX / Linux Sysadmin Tutorials

Merry Christmas and Happy Holidays to all TGS Readers.

To wrap this year, I’ve collected 50 UNIX / Linux sysadmin related tutorials that we’ve posted so far. This is lot of reading. Bookmark this article for your future reference and read it whenever you get free time.

  1. Disk to disk backup using dd command: dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. It can also be used to copy data. This article explains how to backup entire hard disk and create an image of a hard disk using dd command.
  2. 15 rsync command examples: Every sysadmin should master the usage of rsync. rsync utility is used to synchronize the files and directories from one location to another. First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast.
  3. Three sysadmin rules: If you are a sysadmin, you can’t (and shouldn’t) break these three sysadmin rules.
  4. User and group disk quota: This article explains how to setup user and group quote with soft limit, hard limit and grace period. For example, if you specify 2GB as hard limit, user will not be able to create new files after 2GB.
  5. Troubleshoot using dmesg: Using dmesg you can view boot up messages that displays information about the hardware devices that the kernel detects during boot process. This can be helpful during troubleshooting process.
  6. RPM package management examples: 15 examples provided in this article explains everything you need to know about managing RPM packages on redhat based system (including CentOS).
  7. 10 netstat examples: Netstat command displays various network related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships etc.,
  8. Manage packages using apt-* commands: These 13 practical examples explains how to manage packages using apt-get, apt-cache, apt-file and dpkg commands.
  9. Modprobe command examples: modprobe utility is used to add loadable modules to the Linux kernel. You can also view and remove modules using modprobe command.
  10. Ethtool examples: Ethtool utility is used to view and change the ethernet device parameters. These examples will explain how you can manipulate your ethernet NIC card using ethtool.
  11. NFS mount using exportfs: This is a linux beginners guide to NFS mount using exportfs. This explains how to export a file system to a remote machine and mount it both temporarily and permanently.
  12. Change timezone: Depending on your Linux distribution, use one of the methods explained in this article to change the timezone on your system.
  13. Install phpMyAdmin: phpMyAdmin is a web-based tool written in PHP to manage the MySQL database. Apart from viewing the tables (and other db objects), you can perform lot of DBA functions through the web based interface. You can also execute any SQL query from the UI.
  14. Setup squid to control internet access: Squid is a proxy caching server. You can use squid to control internet access at work. This guide will give a jump-start on how to setup squid on Linux to restrict internet access in an network.
  15. Add new swap space: Use dd, mkswap and swapon commands to add swap space. You can either use a dedicated hard drive partition to add new swap space, or create a swap file on an existing filesystem and use it as swap space.
  16. Install and configure snort: Snort is a free lightweight network intrusion detection system for both UNIX and Windows. This article explains how to install snort from source, write rules, and perform basic testing.
  17. Register RHEL/OEL linux to support: If you have purchased support from Oracle for your Linux, you can register to oracle support network (ULN) using up2date as explained here.
  18. tftpboot setup: You can install Linux from network using PXE by installing and configuring tftpboot server as explained here.
  19. Delete all iptables rules: When you are starting to setup iptables, you might want to delete (flush) all the existing iptables as shown here.
  20. Disable ping replies: Someone can flood the network with ping -f. If ping reply is disabled as explained here we can avoid this flooding.
  21. Block ip address using fail2ban: Fail2ban is a intrusion preventon framework that scans log files for various services ( SSH, FTP, SMTP, Apache, etc., ) and bans the IP that makes too many password failures. It also updates iptles firewall rules to reject these ip addresses.
  22. Package management using dpkg: On debian, you can install or remove deb packages using dpkg utility.
  23. Alfresco content management system: Alfresco is the best open source content management system. Everything you need to know to install and configure Alfresco is explained here.
  24. Bugzilla bug tracking system: Bugzilla is the best open source bug tracking system. Everything you need to know to install and configure Bugzilla is explained here.
  25. Rpm, deb, dpot and msi packages: This article explains how to view and extract files from various package types used by different Linux / UNIX distributions.
  26. Backup using rsnapshot: You can backup either a local host or remote host using rsnapshot rsync utility. rsnapshot uses the combination of rsync and hard links to maintain full-backup and incremental backups. Once you’ve setup and configured rsnapshot, there is absolutely no maintenance involved in it. rsnapshot will automatically take care of deleting and rotating the old backups.
  27. Create Linux user: This article explains how to create users with default configuration, create users with custom configuration, create users interactively, and creating users in bulk.
  28. Mount and view ISO file: ISO files are typically used to distribute the operating system. Most of the linux operating system that you download will be on ISO format. This explains how to view and mount any ISO file both as regular use and as root user.
  29. Manage password expiration and aging: Linux chage command can be used to perform several practical password aging activities including how-to force users to change their password.
  30. ifconfig examples: Interface configurator command ifconfig is used to initialize the network interface and to enable or disable the interfaces as shown in these 7 examples.
  31. Oracle db startup an sthudown: Every sysadmin should know some basic DBA operations. This explains how to shutdown and start the oracle database.
  32. PostgreSQL install and configure: Similar to mySQL, postgreSQL is very famous and feature packed free and open source database. This is a jumpstart guide to install and configure postgresql from source on Linux.
  33. Magic SysRq key: Have you wondered what the SysRq key on your keyboard does. Here is one use for it. You can safely reboot Linux using the magic SysRq key as explained here.
  34. Wakeonlan Tutorial: Using Wakeonlan WOL, you can turn on the remote servers where you don’t have physical access to press the power button.
  35. List hardware spec using lshw: ls+hw = lshw, which lists the hardware specs of your system.
  36. View hardware spec using dmidecode: dmidecode command reads the system DMI table to display hardware and BIOS information of the server. Apart from getting current configuration of the system, you can also get information about maximum supported configuration of the system using dmidecode. For example, dmidecode gives both the current RAM on the system and the maximum RAM supported by the system.
  37. Use the support effectively: Companies spend lot of cash on support mainly for two reasons: 1) To get help from vendors to fix critical production issues 2) To keep up-to-date with the latest version of the software and security patches released by the vendors. In this article, I’ve given 10 practical tips for DBAs, sysadmins and developers to use their hardware and software support effectively.
  38. Install/Upgrade LAMP using Yum: Installing LAMP stack using yum is a good option for beginners who don’t feel comfortable installing from source. Also, Installing LAMP stack using yum is a good choice, if you want to keep things simple and just use the default configuration.
  39. Template to track your hardware assests: If you are managing more than one equipment in your organization, it is very important to document and track ALL information about the servers effectively. In this article, I have listed 36 attributes that needs to be tracked for your equipments, with an explanation on why it needs to be tracked. I have also provided a spreadsheet template with these fields that will give you a jumpstart.
  40. Disable SELinux: If you don’t understand how SELinux works and the fundamental details on how to configure it, keeping it enabled will cause lot of issues. Until you understand the implementation details of SELinux you may want to disable it to avoid some unnecessary issues as explained here.
  41. Install PHP5 from source: This is a step-by-step guide to install PHP5 from source on UNIX environment.
  42. Install MySQL from source: This is a step-by-step guide to install MySQL from source on UNIX environment.
  43. Launch Linux clients on windows: If you are using SSH client to connect to Linux server from your Windows laptop, sometimes it may be necessary to launch UI application on the remote Linux server, but to display the UI on the windows laptop. Cygwin can be used to install software on Linux from Windows and launch Linux X client software on Windows.
  44. IPCS: IPC allows the processes to communicate with each another. The process can also communicate by having a file accessible to both the processes. Processes can open, and read/write the file, which requires lot of I/O operation that consumes time. This explains different types of IPCS and provides 10 IPCS command examples.
  45. Logical Volume Manager: Using LVM we can create logical partitions that can span across one or more physical hard drives.You can create and manage LVM using vgcreate, lvcreate, and lvextend lvm2 commands as shown here.
  46. 15 Tcpdump examples: tcpdump is a network packet analyzer. tcpdump allows us to save the packets that are captured, so that we can use it for future analysis. The saved file can be viewed by the same tcpdump command. We can also use open source software like wireshark to read the tcpdump pcap files.
  47. Manage partition using fdisk: Using fdisk you can create a maximum of four primary partition, delete an existing partition, or change existing partition. Using fidsk you are allowed to create a maximum of four primary partition, and any number of logical partitions, based on the size of the disk.
  48. VMWare fundamentals: At some point every sysadmin should deal with virtualization. VMWare is a very popular choise to virtualize your server environment. This article will provide the fundamental information for you to get a jumpstart on VMWare.
  49. Rotate the logs automatically: Manging log files is an importat part of sysadmin life. logrotate make it easy by allowing you to setup automatica log rotation based on several configurations. Using logrotate you can also configure it to execute custom shell scripts immediately after log rotation.
  50. Passwordless SSH login setup: Using ssh-keygen and ssh-copy-id you can setup passwordless login to remote Linux server. ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file.

Tuesday, March 2, 2010

In File PDF Trên Ubuntu

Sử dụng okular để mở và in file pdf chứa ảnh. Một số phần mềm evince , Adobe reader và epdfviewer cài đặt trên ubuntu sẽ in file pdf rất chậm.

Thursday, December 24, 2009

Cấu hình dịch vụ xinetd

Nguồn: http://linux.web.cern.ch/linux/scientific4/docs/rhel-rg-en-4/s1-tcpwrappers-xinetd.html

1. Khái niệm
xinetd daemon (viết tắt của eXtended InterNET Daemon) là một TCP wrapped super service, để kiểm soát truy cập một tập con những dịch vụ mạng thông dụng như: FTP, IMAP và Telnet, ... Nó cũng cung cấp những tuỳ chọn cấu hình xác định để kiểm soát truy cập, logging, binding, redirection và việc sử dụng tài nguyên

Khi client thử kết nối đến một dịch vụ mạng được kiểm soát bởi xinetd, nó nhận được yêu cầu và kiểm tra bất kỳ truy cập TCP wrappers nào. Nếu truy cập được cho phép, xinetd xác nhận rằng kết nối được cho phép dưới access rules cho dịch vụ đó, và dịch vụ đó được gán một lượng tài nguyên xác định được định nghĩa trong rules. Sau đó một instance của dịch vụ yêu cầu được khởi tạo và trao sự kiểm soát kết nối cho nó. Khi kết nối được thiết lập, xinetd không gây bất cứ trở ngại nào trong việc giao tiếp giữa client host và server nữa.

2. Các files cấu hình cho xinetd
Những files cấu hình cho xinetd như sau:
/etc/xinetd.conf - File cấu hình toàn cục
Thư mục /etc/xinetd.d - thư mục chứa tất cả các file cấu hình cho mỗi dịch vụ xác định

  • File cấu hình /etc/xinetd.conf

xinetd.conf chứa đựng các cấu hình chung cho tất cả các dịch vụ được kiểm soát bởi xinetd. Nó chỉ được đọc khi dịch vụ xinetd được khởi tạo, do đó bất kỳ thay đổi nào trong cấu hình, bạn đều phải restart (hoặc reload) xinetd để có hiệu lực. Dưới đây là ví dụ cho Fedora 8:
Code:
 defaults
{
log_type = SYSLOG daemon info
log_on_failure = HOST
log_on_success = PID HOST DURATION EXIT

cps = 50 10
instances = 50
per_source = 10
}

includedir /etc/xinetd.d

Ý nghĩa của các tham số:
log_type: SYSLOG authpriv: chỉ định đầu ra của service log. Bạn có thể gửi nó đến SYSLOG
log_on_success: Cấu hình cho việc log nếu kết nối thành công. HOST name và Process ID sẽ được log vào /var/log/secure
log_on_failure: cấu hình cho việc log khi kết nối bị dropped hoặc không được phép truy cập /var/log/secure
cps: giới hạn tỷ lệ các kết nối. Bao gồm 2 tham số. Tham số đầu tiên là giới hạn số lượng kết nối trong 1s. Nếu tỷ lệ các kết nối cao hơn giá trị này, dịch vụ sẽ tạm thời bị disabled. Tham số thứ 2 là thời gian chờ (tính bằng s) để enable lại dịch vụ sau khi nó bị disabled. Giá trị mặc định là 50 connections và thời gian nghỉ là 10s
instances: số lượng lớn nhất các requests mà xinetd có thể handle tại một thời điểm
per_source: giới hạn số lượng kết nối cho mỗi địa chỉ nguồn
includedir: đọc các file cấu hình cho các dịch vụ khác nằm trong thư mục /etc/xinetd.d

  • Thư mục /etc/xinetd.d

Thư mục này chứa đựng các file cấu hình cho mỗi dịch vụ được quản lý bởi xinetd. Cũng như xinetd.conf, thư mục này cũng chỉ được đọc khi xinetd được khởi tạo. Để bất kỳ thay đổi này có hiệu lực, bạn phải khởi động lại dịch vụ xinetd
Định dạng của các file nằm trong thư mục /etc/xinetd.d cũng sử dụng quy ước tương tự như /etc/xinetd.conf. Lý do chính để cấu hình của mỗi dịch vụ được lưu trong 1 file riêng biệt là nhằm tạo sự dễ dàng trong việc tuỳ biến, cũng như đỡ ảnh hưởng đến các dịch vụ khác

Ví dụ về rsync:
Code:
 # default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = yes
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}

Ý nghĩa các tham số:
service: định nghĩa tên dịch vụ, luôn phải thuộc /etc/services
disable: dịch vụ có được active hay không
flags: Gán thuộc tính cho kết nối.
socket_type: loại socket mạng. Trường này có thể nhận các giá trị: stream, dgram, raw
wait: định nghĩa dịch vụ là single-threaded (yes) hay multi-threaded (no)
user: người dùng có quyền chạy dịch vụ đó. root hoặc nobody thường được dùng ở đây.
server: đường dẫn của dịch vụ
server_args: chỉ định các tham số đưa vào cho server. Trong ví dụ này: rsync là một daemon nên yêu cầu đưa vào tuỳ chọn --daemon
log_on_failure: định nghĩa các tham số logging được thêm vào với những gì đã định nghĩa trong xinetd.conf

Làm việc với xinetd
Khởi động dịch vụ:
Code:
# /etc/init.d/xinetd start

Dừng dịch vụ:
Code:
# /etc/init.d/xinetd stop

Xác định xem xinetd có đang chạy hay không
Code:
 # /etc/init.d/xinetd status
xinetd (pid 2110) is running...

Khởi động lại dịch vụ
Code:
# /etc/init.d/xinetd restart


Tất cả về Linux swap space

Nguồn: http://www.linux.com/feature/121916

Khi máy tính cần chạy những chương trình lớn hơn khả năng có thể của bộ nhớ vật lý (RAM), hệ điều hành sẽ sử dụng một công nghệ có tên gọi swapping. Nói nôm na thì công nghệ này sẽ dùng đến những mảng bộ nhớ tạm được lưu trên đĩa cứng, trong khi phần dữ liệu khác vẫn được chuyển vào RAM. Công nghệ này giúp bạn quản lý việc hoán đổi (swapping) tốt hơn cũng như tăng hiệu năng sử dụng.

Linux chia bộ nhớ vật lý thành các pages. swapping là một tiến trình thực hiện việc copy một page của bộ nhớ đến một không gian đã được cấu hình trước trên đĩa cứng (gọi là swap space), để giải phóng các pages của bộ nhớ. Tổng dung lượng của RAM và không gian hoán đổi (swap space) chính là tổng số bộ nhớ ảo (virtual memory)

swapping cần thiết vì 2 lý do:
1. Khi hệ thống yêu cầu một lượng bộ nhớ nhiều hơn mức RAM cho phép, chức năng hoán đổi của kernel sẽ đẩy bớt các pages được dùng ít hơn ra ngoài và gửi lượng bộ nhớ cho ứng dụng đang cần ngay lập tức.
2. Có một số pages quan trọng được sử dụng bởi 1 ứng dụng trong suốt quá trình startup, có thể chỉ được dùng cho khởi tạo thôi, sau đó không bao giờ dùng lại nữa, hệ thống có thể swap out những pages này ra, giải phóng bộ nhớ cho những ứng dụng khác, hoặc cho việc cache đĩa.

Tuy nhiên, swapping có một bất lợi. Tốc độ truy cập đĩa (milliseconds) chậm hơn từ 10 đến 1000 lần so với tốc độ truy cập RAM (nanoseconds). Thỉnh thoảng sẽ xảy ra sự trao đổi quá mức, kiểu như: một pages vừa được swapped out, ngay sau đó lại
swapped in rồi lại swapped out và cứ thế. Trong trường hợp này, hệ thống vừa phải vật lộn để tìm những phần bộ nhớ rỗi, vừa phải giữa cho các ứng dụng kia vẫn chạy. Cách tốt nhất trong tình huống này là tăng RAM lên.

Có 2 loại swap space, đó là: swap partition và swap file. swap partition là một phân vùng độc lập nằm trên đĩa cứng, chỉ có mục đích là hoán đổi (swapping), không có file nào khác nằm trên đó. swap file là một file riêng biệt nằm trên hệ thống, nó có thể nằm giữa hệ thống của bạn và các file dữ liệu

Để xem swap space trên hệ thống, bạn có thể dùng lệnh swapon -s
Code:
 $ swapon -s
Filename Type size Used Priority
/dev/sda9 partition 1132540 0 -1

Mỗi dòng là một swap space tách biệt trên hệ thống của bạn. Type chỉ ra rằng swap space là partition hay file. Filename như bạn thấy là sda9 (partition). size là kích cỡ tính bằng KB của swap space. Used là lượng swap hiện đang được dùng. Priority chỉ ra swap nào sẽ được dùng trước (nếu bạn có nhiều swap). Một điều thú vị là: nếu bạn mount 2 hoặc nhiều swap space trên 2 thiết bị khác nhau với cùng độ ưu tiên, hệ thống sẽ thực hiện xen kẽ việc swapping giữa 2 swap space này để tăng performance.

Thêm 1 swap partition vào hệ thống
+ Xác định partition nào sẽ lấy làm swap
Code:
 # fdisk -l
/dev/sda9 swap swap defaults 0 0

+ Tạo hệ thống file swap cho nó
Code:
# mkswap /dev/sda9

+ Kích hoạt nó ngay lập tức:
Code:
# swapon /dev/sda9

+ Xác nhận xem nó đã được dùng chưa bằng lệnh:
Code:
# swapon -s

Để mount swap space tự động khi boot, bạn chỉnh sửa /etc/fstab và thêm vào một dòng tương tự như:
/dev/sda9 swap swap defaults 0 0


Để kiểm tra xem swap space đã được mounted tự động chưa mà không cần reboot, bạn có thể gõ, swapoff -a, sau đó lại swapon -a và check bằng swapon -s

Swap file cũng hoàn toàn tương tự như swap partition. Thuận lợi của nó là không cần tìm một partition độc lập hoặc phân vùng lại đĩa cứng để thêm vào. Có thể tạo swap file bằng lệnh dd như sau:
Code:
dd if=/dev/zero of=/swapfile bs=1024 count=1048576

Lệnh này tạo một file trống có kích thước 1048576 KB (1GB), với tên gọi swapfile

Tạo và mount nó:
Code:
 mkswap /swapfile
swapon /swapfile

Thêm một dòng vào /etc/fstab cũng tương tự như trên:
/swapfile swap swap defaults 0 0


Tôi nên dành bao nhiêu dung lượng cho swap space?
Không có một nguyên tắc nào cả, nhưng mọi người thường chia theo quy luật:
+ Hệ thống Desktop: nên để bằng 2*RAM - đủ để bạn chạy một số lượng lớn các ứng dụng
+ Server: cần ít hơn (có người cho rằng chỉ cẩn để bằng 1/2*RAM). Tuy nhiên bạn cần theo dõi swap space và tăng lượng RAM nếu cần thiết
+ Older desktop (hệ thống có ít RAM - 128 MB chẳng hạn): bạn có thể dành 3*RAM cho swap, hoặc có thể để 1GB.

Với Linux kernel 2.6 có 1 tham số mới là swappiness - để bạn có thể tweak cách mà Linux hoán đổi. Tham số này có giá trị từ 0 đến 100. Giá trị cao có nghĩa là nhiều paged được swapped, giá trị thấp có nghĩa là nhiều ứng dụng được giữ trong bộ nhớ - ngay cả khi chúng không làm gì cả (idle). Giá trị mặc định của swapiness là 60, bạn có thể thay đổi nó tạm thời (reboot mới có hiệu lực thật sự) bằng lệnh sau (với root):
Code:
echo 50 > /proc/sys/vm/swappiness


Nếu bạn muốn thay đổi vĩnh viễn, có thể chỉnh vm.swappiness trong /etc/sysctl.conf

Quản lý swap space là công việc cần thiết của người quản trị hệ thống. Một kế hoạch tốt kết hợp với việc sử dụng đúng đắn sẽ đem lại nhiều lợi ích. Đừng sợ thử nghiệm, hãy luôn luôn theo dõi hệ thống của bạn, chắc chắn bạn sẽ thu được những kết quả mong muốn.

QuanTA.

Tìm hiểu về umask

Nguồn:
http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
http://www.sun.com/bigadmin/content/submitted/umask_permissions.html

umask là gì?
umask được sử dụng để kiểm soát quyền mặc định của các files mới khi nó được tạo ra. umask gồm 4 chữ số trong hệ cơ số 8 (four-digit octal)

Gán umask mặc định như thế nào?
Bạn có thể gán umask mặc định trong /etc/bashrc hoặc /etc/profile cho tất cả các users. Phần lớn các distro đều gán là 0022 hoặc 0002.
Để gán umask cho một user xác định nào đó, bạn có thể chỉnh sửa ~/.bashrc của user đó và thêm vào dòng sau:
umask 022

Lưu lại, logout và login lại để thay đổi trên có hiệu lực.

0022 và 0002 nghĩa là gì?
umask mặc định 0002 được sử dụng cho normal user. Với mặt nạ (mask) này, quyền mặc định của thư mục sẽ là 775 và quyền mặc định của file sẽ là 664.

umask mặc định cho root là 0022, nghĩa là quyền mặc định của thư mục sẽ là 755 và quyền mặc định của file sẽ là 644.

Nôm na bạn có thể hiểu rằng: Trước khi file hoặc thư mục được tạo ra, quyền truy cập đối với chúng được xác định dựa vào hai giá trị: quyền truy cập cơ sở (base permissions) và mặt nạ (mask). Đối với thư mục, quyền truy cập cơ sở là 0777(rwxrwxrwx), còn đối với files là 0666 (rw-rw-rw).

Thiết lập giá trị mask như thế nào?
Giá trị "mask" được thiết lập nhờ lệnh umask. Tất cả các file và thư mục được tạo ra sau đó sẽ chịu ảnh hưởng của giá trị mask mới.

Để tính toán quyền truy cập thư mục với umask 022 (root user):
Quyền truy cập mặc định: 777
Giá trị umask: 022
Quyền truy cập cho phép: 755

Để tính toán quyền truy cập file với umask 022 (root user):
Quyền truy cập mặc định: 666
Giá trị umask: 022
Quyền truy cập cho phép: 644

Lấy một ví dụ đơn giản: Bạn cần gán umask để các files được tạo ra sau đó sẽ có permissions là 600.
Ta có:
Quyền truy cập mặc định: 666
Giá trị umask: 066
Quyền truy cập cho phép: 600

Code:
 $ umask 066
$ touch test.txt
$ ls -l test.txt
-rw------- 1 quanta quanta 0 2008-02-16 17:38 test.txt

Quyền truy cập cho phép là kết quả giữa phép toán sau:

Quyền truy cập cho phép = "quyền truy cập mặc định" AND (NOT (Giá trị umask))

Ví dụ:
Quyền truy cập mặc định: 666 = 110 110 110
Giá trị umask: 123 = 001 010 011
--> NOT (Giá trị umask) = NOT (001 010 011) = 110 101 100
Quyền truy cập cho phép = 110 110 110 AND 110 101 100 = 110 100 100 = 644


Thursday, October 15, 2009

Backup file trước khi chỉnh sửa

khi bạn muốn "vọc" với những file quan trọng, trước tiên nên backup đã:
sudo cp /etc/sudoers /etc/sudoers.bak

Sau này có gì thì khôi phục lại:
sudo cp /etc/sudoers.bak /etc/sudoers

Configuring sudo and adding users to Wheel group

If a server needs to be administered by a number of people it is normally not a good idea for them all to use the root account. This is because it becomes difficult to determine exactly who did what, when and where if everyone logs in with the same credentials. The sudo utility was designed to overcome this difficulty.

With sudo (which stands for "superuser do"), you can delegate a limited set of administrative responsibilities to other users, who are strictly limited to the commands you allow them. sudo creates a thorough audit trail, so everything users do gets logged; if users somehow manage to do something they shouldn't have, you'll be able to detect it and apply the needed fixes. You can even configure sudo centrally, so its permissions apply to several hosts.

The privileged command you want to run must first begin with the word sudo followed by the command's regular syntax. When running the command with the sudo prefix, you will be prompted for your regular password before it is executed. You may run other privileged commands using sudo within a five-minute period without being re-prompted for a password. All commands run as sudo are logged in the log file /var/log/messages.


The sudo configuration file is /etc/sudoers. We should never edit this file manually. Instead, use the visudo command: # visudo

This protects from conflicts (when two admins edit this file at the same time) and guarantees that the right syntax is used (the permission bits are correct). The program uses Vi text editor.

All Access to Specific Users
You can grant users bob and bunny full access to all privileged commands, with this sudoers entry.
user1, user2 ALL=(ALL) ALL
This is generally not a good idea because this allows user1 and user2 to use the su command to grant themselves permanent root privileges thereby bypassing the command logging features of sudo.

Access To Specific Users To Specific Files
This entry allows user1 and all the members of the group operator to gain access to all the program files in the /sbin and /usr/sbin directories, plus the privilege of running the command /usr/apps/check.pl.
user1, %operator ALL= /sbin/, /usr/sbin, /usr/apps/check.pl

Access to Specific Files as Another User
user1 ALL=(accounts) /bin/kill, /usr/bin/kill, /usr/bin/pkill

Access Without Needing Passwords
This example allows all users in the group operator to execute all the commands in the /sbin directory without the need for entering a password.
%operator ALL= NOPASSWD: /sbin/

Adding users to the wheel group
The wheel group is a legacy from UNIX. When a server had to be maintained at a higher level than the day-to-day system administrator, root rights were often required. The 'wheel' group was used to create a pool of user accounts that were allowed to get that level of access to the server. If you weren't in the 'wheel' group, you were denied access to root.

If the following line were in sudoers, it would allow members of the wheel group to
run any command as any user with one exception: They would not be allowed to run
passwd to change the root password and #sudo su root


%wheel ALL=(ALL) ALL, !/usr/bin/passwd root, NOEXEC: /bin/su

This will allow anyone in the wheel group to execute commands using sudo (rather than having to add each person one by one).

Now finally use the following command to create wheel group and add any user (e.g- user1) to Wheel group

#groupadd wheel

#useradd -G wheel user1


Useful Commands in Ubuntu

A comprehensive list of commands needed when using Ubuntu:

Command privileges.

sudo command - run command as root
sudo su – root shell open
sudo su user – open shell as a user
sudo -k – forget your password sudo
gksudo command – sudo visual dialog (GNOME)
kdesudo command – sudo visual dialog (KDE)
sudo visudo – edit / etc / sudoers
gksudo nautilus – root file manager (GNOME)
kdesudo konqueror – root file manager (KDE)
passwd – change your password

Command Network


ifconfig – displays information network
iwconfig – displays information from wireless
sudo iwlist scan – scan wireless networks
sudo /etc/init.d/networking restart – reset the network
(file) /etc/network/interfaces – manual configuration
ifup interface – bring online interface
ifdown interface – disable interface

Commands Display

sudo /etc/init.d/gdm restart – reset X (Gnome)
sudo /etc/init.d/kdm restart – reset X (KDE)
(file) /etc/X11/xorg.conf – show Configuration
sudo dpkg-reconfigure - reconfigure xserver-xorg-phigh - reset configuration X
Ctrl+Alt+Bksp – X display reset if frozen
Ctrl+Alt+FN – switch to tty N
Ctrl+Alt+F7 – switch back to X display

Commands Service System.

start service – service to start work (Upstart)
stop service – service to stop working (Upstart)
status service – check if service is running (Upstart)
/etc/init.d/service start – start service (SysV)
/etc/init.d/service stop – stop service (SysV)
/etc/init.d/service status – check service (SysV)
/etc/init.d/service restart – reset service (SysV)
runlevel – get current runlevel

Commands for Firewall.

ufw enable – turn on the firewall
ufw disable – turn off the firewall
ufw default allow – allow all connections by default
ufw default deny – drop all connections by default
ufw status – current rules and
ufw allow port – to allow traffic on port
ufw deny port – port block
ufw deny from ip – ip block

Command System.


lsb_release -a – get the version of Ubuntu
uname -r – get kernel version
uname -a – get all the information kernel

Commands for Package Manager.


apt-get update – refresh updates available
apt-get upgrade – update all packages
apt-get dist-upgrade – version update
apt-get install pkg – installing pkg
apt-get remove pkg – uninstall pkg
apt-get autoremove – removing packages obsotletos
apt-get -f install – try to fix packages
dpkg –configure -a – try to fix a broken package
dpkg -i pkg.deb – install file pkg.deb
(file) /etc/apt/sources.list – list of repositories APT

Special Packages For commands.

ubuntu-desktop – Setting the standard Ubuntu
kubuntu-desktop – KDE Desktop
xubuntu-desktop – desktop XFCE
ubuntu-minimal – core earnings Ubuntu
ubuntu-standard – the standard utilities Ubuntu
ubuntu-restricted-extras – not free, but useful
kubuntu-restricted-extras – ditto KDE
xubuntu-restricted-extras – ditto XFCE
build-essential – packages used to compile
linux-image-generic – latest generic kernel image
linux-headers-generic – latest headlines

Applications commands.

nautilus – File Manager (GNOME)
dolphin – File Manager (KDE)
konqueror – Web browser (KDE)
kate – text editor (KDE)
gedit – text editor (GNOME)

Thursday, August 27, 2009

How to: Backup to FTP with NCFTP

Showing an easy way of copying your files to an remote FTP Server.

Install ncftpapt-get install ncftp

apt-get install ncftp

Create ncftp-serverconfig

/root/.ncftp/backupserver.cfg
host
user
pass

Create CronJob

/etc/cron.d/backup
40 2 * * * root ncftpput -f /root/.ncftp/backupserver.cfg -vZmRF /ftp-directory/ /local-backup/* 1>/dev/null

This way you will recieve warnings/errors.

Flags

-f <Filename> Serverconfig
-m try to create directory
-R recursivly
-v verbose progress
-Z enable PassivTransfer

Debugging

If something is going wrong, try to use the "-d " to enable debugging for more details.

Tips

To keep your BackupSpace clean you can also issue an delete command before uploading.
Simply add: -W "delete /directory/*"
Unfortunately you can't delete recursivly, since it's assuming rm as delete.