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

Tuesday, August 21, 2012

Alternative of "ls" command


It might happen that you will not be able to access "ls" command. It might not even be accessible from miniroot.

Using echo displays a clean list of files within a given directory.

e.g.
Hard system crashes or drives dying can bring systems down to the point where filesystems are so corrupted that they are unable to mount. When this occurs, at times the only way to see the system files is to use echo for displaying the files and directories.


#cd /usr

#ls *
bin  etc  games  include  java  kerberos  lib  libexec  local  man  nsh  openv
X11R6

- An output of ls can be a single or multiple column listing. 

#echo *
bin etc games include libexec local man nsh openv sbin share src tmp X11R6

- When echo is used, the files will all be spaced one right after the other.

Thursday, August 16, 2012

cPanel - mysqltuner script

At times, situation comes where we need to tune mysql on cPanel server's. cPanel server has built in script now a days named - mysqltuner.pl

Location - /usr/local/cpanel/3rdparty/mysqltuner/mysqltuner.pl

We can make use of it in need onto the server.

e.g.

root@[/usr/local/cpanel/3rdparty/mysqltuner]# ./mysqltuner.pl
 >> MySQLTuner 1.1.2 - Major Hayden <major@mhtx.net>
 >> Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >> Run with '--help' for additional options and output filtering
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.63-cll
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 2G (Tables: 23107)
[--] Data in InnoDB tables: 598M (Tables: 5883)
[--] Data in MEMORY tables: 0B (Tables: 205)
[!!] Total fragmented tables: 6835
-------- Performance Metrics -------------------------------------------------
[--] Up for: 44m 31s (95K q [35.748 qps], 2K conn, TX: 263M, RX: 15M)
[--] Reads / Writes: 81% / 19%
[--] Total buffers: 442.0M global + 12.4M per thread (500 max threads)
[OK] Maximum possible memory usage: 6.5G (80% of installed RAM)
[OK] Slow queries: 0% (134/95K)
[OK] Highest usage of available connections: 2% (11/500)
[OK] Key buffer size / total MyISAM indexes: 384.0M/1.7G
[OK] Key buffer hit rate: 99.8% (9M cached / 19K reads)
[OK] Query cache efficiency: 73.0% (53K cached / 73K selects)
[!!] Query cache prunes per day: 21284
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 3K sorts)
[!!] Joins performed without indexes: 372
[!!] Temporary tables created on disk: 29% (2K on disk / 10K total)
[OK] Thread cache hit rate: 99% (11 created / 2K connections)
[!!] Table cache hit rate: 12% (512 open / 4K opened)
[OK] Open file limit used: 21% (876/4K)
[OK] Table locks acquired immediately: 99% (33K immediate / 33K locks)
[!!] InnoDB data size / buffer pool: 598.5M/8.0M
-------- Recommendations -----------------------------------------------------
General recommendations:
 Run OPTIMIZE TABLE to defragment tables for better performance
 MySQL started within last 24 hours - recommendations may be inaccurate
 Adjust your join queries to always utilize indexes
 When making adjustments, make tmp_table_size/max_heap_table_size equal
 Reduce your SELECT DISTINCT queries without LIMIT clauses
 Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
 query_cache_size (> 32M)
 join_buffer_size (> 128.0K, or always use indexes with joins)
 tmp_table_size (> 16M)
 max_heap_table_size (> 16M)
 table_cache (> 512)
 innodb_buffer_pool_size (>= 598M)
root@ [/usr/local/cpanel/3rdparty/mysqltuner]#

Tuesday, July 31, 2012

dmidecode: DMI type numbers

Dmidecode reports information about your system's hardware as described in your system BIOS according to the SMBIOS/DMI standard (see a sample output). 


This information typically includes system manufacturer, model name, serial number, BIOS version, asset tag as well as a lot of other details of varying level of interest and reliability depending on the manufacturer. This will often include usage status for the CPU sockets, expansion slots (e.g. AGP, PCI, ISA) and memory module slots, and the list of I/O ports (e.g. serial, parallel, USB).


The DMI type numbers, shown below, used individually or in a comma separated list provide you with targeted information.



Type Information
—————————————-
0 BIOS
1 System
2 Base Board
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply


Usage:


e.g.
#dmidecode -t 1
#dmidecode -t 1,19

Thursday, June 21, 2012

Test if suPHP works with your apache installation


echo ‘Current script owner: ‘ . get_current_user(). ‘
’;

echo ‘UID:’ . getmyuid() . ‘
’;

echo ‘GID:’ . getmygid() . ‘
’;

echo ‘PID:’ . getmypid() . ‘
’;

echo ‘
’;

echo “PHP runs under the user: [" . system('whoami') . "]
”;

?>

How to detect CPU architecture/bitmode (32-bit or 64-bit)

#cat /proc/cpuinfo | grep flags

You will find one of them with name "tm(transparent mode)" or "rm(real mode)" or "lm(long mode)"


1. rm tells ,it is a 16 bit processor


2. tm tells, it is a 32 bit processor


3. lm tells, it is a 64 bit processor

Saturday, June 2, 2012

How to install SSL with PFX file?


If you wish to install exported SSL with .pfx file to your cPanel server. You may refer to the following step.


Assume, you have a file named domain.pfx.


1) Export key file,


#openssl pkcs12 -in domain.pfx -nocerts -out domain.key


2) Export decrypted key file,


#openssl rsa -in domain.key -out domain.decrypted.key


3) Export Certificate, crt file,


#openssl pkcs12 -in domain.pfx -clcerts -nokeys -out domain.crt


4) Export cabundle file,


#openssl pkcs12 -in domain.pfx -cacerts -nokeys -out cabundle.pem


5) You should now able install your SSL through WHM.

What is an express transfer?


An express transfer, in addition to transferring the requested cPanel account(s), performs the following actions on the source server:


1) Updates the account's A record to point to the destination server.
2) Whenever appropriate, changes the domain's nameserver entry to point to the destination server.
3) Updates the mail databases to point to the destination server.
4) Adds a redirect for the Account Moved page (cgi-sys/movingpage.cgi)
5) Blocks SSH and FTP logins to the source server for accounts that were transferred.


In all, if you transfer one account abc.com (from previous IP or server xx.xx.xx.1), the zone file for abc.com on server xx.xx.xx.1 will be altered automatically using IP where the account is being transferred i.e. xx.xx.xx.3


Note:- in this case nameservers are like,


for server xx.xx.xx.1,
ns1.server1.com (xx.xx.xx.1)
ns2.server1.com (xx.xx.xx.2)


for server xx.xx.xx.3
ns3.server1.com (xx.xx.xx.3)
ns4.server1.com (xx.xx.xx.2)


Thus, the domain will start resolving to new IP address - xx.xx.xx.3 using nameservers (ns2.server1.com & ns4.server1.com)


Express transfer option can be seen from option WHM >> Copy multiple account from another server



Ref:-
http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AllFAQ/WHMsFAQ#What is an express transfer?

What is the WHM Autofixer?

The Autofixer is a collection of scripts that can be run from WHM to fix some common issues not otherwise fixable or accessible from command line. i.e. SSH access is not available by some reason.


Few common autofixers:-


- test — Test autofixer on your system, nothing gets changed.
- bsdbindfix — Resolve port issue with BIND 9.
- compresszlibfix — Fix for compress zlib error.
- dbdmysql — DBD::mysql fix for older version of Red Hat (i.e. 7.3).
- fpindexfile — Fix for FrontPage index.
- iptablesflush — Flush iptables rules from WHM if you are firewalled from SSH access.
- libxml64fix — Fix for libXML on 64-bit systems.
- resellerresourceacctounts — Fix for reseller resource accounts.
- vfilterfix — Restores /etc/vfilters files.
- yumduprpmfix — This script will attempt to locate and resolve any duplicate RPMs.


- safesshrestart — Restores SSH Config and restarts SSH, should you be locked out.
>> This is one of the best fixer I have dealt with :) It just re-configures SSHD service on port 22


How to make use of it?


e.g.

https://xx.xx.xx.xx:2087/scripts2/doautofixer?autofix=safesshrestart
https://xx.xx.xx.xx:2087/scripts2/doautofixer?autofix=disable_cphulkd



xx.xx.xx.xx - replace with your server IP address


Autofixer scripts can always be found at http://httpupdate.cpanel.net/autofixer/




Ref - 
http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AllFAQ/WHMsFAQ#What is the WHM Autofixer?

Thursday, May 17, 2012

FSCK - how much % fsck is completed

Note : Make sure that partition is not mounted while running fsck.

Many time due to big partition size ,we have to wait for the long time at that time we think fsck process is stuck at that time we can use the following fsck command because its showing the % for the fsck process, so that we are able to see how much % fsck is completed and remaining.


#fsck -y -C0 -v /dev/sdb1


-C [ "fd" ]Display completion/progress bars for those filesystem checkers (currently only for ext2 and ext3) which support them. Fsck will manage the filesystem checkers so that only one of them will display a progress bar at a time. GUI front-ends may specify a file descriptor fd, in which case the progress bar information will be sent to that file descriptor.

YUM plug-ins to control package versions

1) versionlock


- How to install it?


#yum install yum-plugin-versionlock


- The next step is to use the versionlock plug-in to create its file of package versions.


#yum versionlock \*


- Now, if you try to install updates they will be rejected. So how do you update?


- Update the package version in the version list file, /etc/yum/pluginconf.d/versionlock.list, and then run


#yum upgrade


- To add files that you want version locked, use the following yum command:


#yum versionlock [package-name]


Versionlock allows you specify what version of a package should be installed. You can find out more about it in the baseurl.org yum wiki - http://yum.baseurl.org/wiki/Faq


2) allow-downgrade


if you've already installed a newer version of the package, you'll have to downgrade it. In that case, make sure you've got yum's downgrade plugin installed:


- If you're downgrading, you may need to throw in the --allow-downgrade flag.


# yum --allow-downgrade install php-gd-5.2.6

Monday, December 5, 2011

Thursday, October 20, 2011

Why do the CPU stats vary with ps and top?


The commands ps and top express CPU time differently. While ps calculates it by “total CPU time” divided by “time task is running”, top shows the value as a percentage of overall CPU time.

For ps, this means that the longer a process is running without a high CPU utilization the smaller the value of%cpugets (it converges to zero).

For top, this means that it displays this value as share of the CPU time since last screen update and is therefore more accurate in terms of “current CPU utilization”.

One CD disk, multiple Linux distributions: Netboot CD

I have nothing to say.....below URL itself shouting a lot

Friday, September 16, 2011

How to restrict linux users logging from shell except root?

Sometimes you have to disable the login to all users,except root
e.g. when you have to do a backup, you have to use pam_nologin.so

1) Edit the pam file for the service you want to control, in this example i modify ssh pam control file, located in /etc/pam.d/sshd

Add this line
account required pam_nologin.so


2) touch /etc/nologin

This should disable the login from ssh. If you want to disable the login from terminal, modify the /etc/pam.d/login file.

3) To re-enable the login just remove /etc/nologin



Tuesday, September 6, 2011

Clean up buffer and cached memory by defrag_mem

This command is very useful to free buffers when you face lack of memory issue. Free memory can be seen from the output of common linux command “free”:

[root]# free
total       used       free     shared    buffers     cached
Mem:       1033972     987192      46780          0     159204     309176
-/+ buffers/cache:     518812     515160
Swap:      4192956         68    4192888
Here we can see that free memory calculation formula is:

Real free memory = free + buffers + cached
To clean up buffers and cached memory, use defrag_mem:

[root]# gcc -o defrag_mem
[root]# ./defrag_mem 500M

[root]# free
total       used       free     shared    buffers     cached
Mem:       1033972     482504     551468          0        612       7760
-/+ buffers/cache:     474132     559840
Swap:      4192956     112964    4079992

Sunday, August 21, 2011

How to add user in DRAC 6 ?

Ref - http://support.dell.com/support/edocs/software/smdrac3/idrac/idrac15mono/en/ug/pdf/ug.pdf

- Login to linux shell using the DRAC's main IP

- To verify if a user exists, type the following command at the command prompt:
racadm getconfig -u USER

OR

NOTE - (please take this step seriously and ensure the users configured on indexes, if not then you can configure user on the index except the preconfigured user on that index)

- Type the following command once for each index of 1–16:
racadm getconfig -g cfgUserAdmin -i 3

- To add user
racadm config -g cfgUserAdmin -o cfgUserAdminUserName -i 3 USER

- To set password for configured user
racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 3 PASSWORD

- To set read only privileges to user
racadm config -g cfgUserAdmin -i 3 -o cfgUserAdminPrivilege 0x00000001

- To enable the user
racadm config -g cfgUserAdmin -i 3 -o cfgUserAdminEnable 1

- Login to DRAC Web interface with the user you created. 


Note:- Each Dell DRAC comes with a default password; user: “root” password: “calvin”. But, we should change that for security purposes.

Sunday, May 15, 2011

Flush DNS cache in Linux

If you register a new domain name and you can’t access it, it may be your DNS cache that holds the problem. You can flush DNS cache in Linux:
#/etc/rc.d/init.d/nscd restart



Wednesday, May 4, 2011

RHEL / CentOS Support 4GB or more RAM ( memory ) using PAE Kernel

If you have 4 GB or more RAM use the Linux kernel compiled for PAE capable machines. Your machine may not show up total 4GB ram with 32 bit architecture servers. All you have to do is install PAE kernel package.

This package includes a version of the Linux kernel with support for up to 64GB of high memory. It requires a CPU with Physical Address Extensions (PAE). The non-PAE kernel can only address up to 4GB of memory. Install the kernel-PAE package if your machine has more than 4GB of memory (>=4GB).

How Do I Install PAE kernel?

To install PAE kernel, use yum command:
# yum install kernel-PAE
# grub
grub> savedefault --default=0 --once
grub> quit
# reboot

If the kernel boots successfully edit /etc/grub.conf again to set the new kernel as the new default for the future reboots.

Thursday, April 7, 2011

General OpenSSL Commands

These commands allow you to generate CSRs, Certificates, Private Keys and do other miscellaneous tasks.

1) Generate a new private key and Certificate Signing Request
#openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key

2)Generate a self-signed certificate (see How to Create and Install an Apache Self Signed Certificate for more info)
#openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt

3) Generate a certificate signing request (CSR) for an existing private key

#openssl req -out CSR.csr -key privateKey.key -new

4) Generate a certificate signing request based on an existing certificate
#openssl x509 -x509toreq -in certificate.crt -out CSR.csr -signkey privateKey.key

5) Remove a passphrase from a private key
#openssl rsa -in privateKey.pem -out newPrivateKey.pem

Checking Using OpenSSL

If you need to check the information within a Certificate, CSR or Private Key, use these commands. You can also check CSRs and check certificates using our online tools.

1) Check a Certificate Signing Request (CSR)
#openssl req -text -noout -verify -in CSR.csr

2) Check a private key
#openssl rsa -in privateKey.key -check

3) Check a certificate
#openssl x509 -in certificate.crt -text -noout

4) Check a PKCS#12 file (.pfx or .p12)
#openssl pkcs12 -info -in keyStore.p12

No space left on device

Some times apache just fails or stops, fails to restart with an error message like

[emerg] (28)No space left on device: mod_fcgid: Can't create global mutex
or
[crit] (28)No space left on device: mod_rewrite: could not create rewrite_log_lock
or
[emerg] (28)No space left on device: Couldn't create accept lock

The following command can be used to get this problem resolved:-


#ipcs -s | grep $apacheuser | awk '{print "ipcrm sem " $2}' | sh

OR

#ipcs -s | grep nobody | perl -e 'while () {@a=split(/\s+/); print `ipcrm sem $a[1]`}'  ipcrm $(ipcs -s |awk '$3=="nobody"{print "-s",$2}')