Linux: Apache Tomcat tips and tricks
by Ali on Nov.16, 2008, under Linux
JAVA_HOME or JRE_HOME variables are not defined:
Edit bash_profile for the user running Tomcat:
nano ~/.bash_profile
Add the following line and edit to point to correct directory:
export JRE_HOME=/usr/local/jre
Save and exit, then execute the following command:
source ~/.bash_profile
Running Apache Tomcat on privileged ports (lower then 1024) as non-root user:
The best way is to set an iptables rule to forwards incoming requests from port 80 to 8080:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
or setup apache with mod_jk connector to pass http requests to tomcat
Linux: A simple and quick way of sharing a folder with Windows systems using Samba
by Ali on Nov.13, 2008, under Linux
Here is the quickest way to share a folder with read/write access.
Get rid of all lines in your /etc/samba/smb.conf and replace them with:
[global]
workgroup = workgroup or domain
server string = %h server
security = user
obey pam restrictions = Yes
passdb backend = tdbsam
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *password\supdated\ssuccessfully* .
syslog = 0
log file = /var/log/samba/log.%m
max log size = 1000
dns proxy = No
panic action = /usr/share/samba/panic-action %d
encrypt passwords = yes
invalid users = root
[Share name]
path = /home/share/
comment = comment
public = yes
browseable = yes
writeable = yes
valid users = user who will access the share
create mask = 0755
Restart your samba server:
/etc/init.d/samba restart
You must have an smb account for specified user. To create one:
smbuser <username>
smbpasswd <username>
Enter password for user.
Linux: Crontab notes for different users – run a cron job every time a system reboots
by Ali on Nov.13, 2008, under Linux
Each user has its own crontab in Linux. Root crontab is only available to root and cannot be modified by other users. To edit your non-root crontab:
crontab -e
To list available crontab:
crontab -l
To delete:
crontab -r
Privileged users can access others crontab:
crontab -u
Run cron jobs as a different user:
su - <user> -c <command or script>
Depending on your default editor crontab will either open in vi or nano. Crontab line format should look like:
# m h dom mon dow user command
Under which you will have to specify when your cron job should run:
m: minute of the day, from 0 to 59
h: hour of the day, from 0 to 23
dom: day of month, from 1 to 31
dow: day of week, from 1 to 7
user: user your cron job should run as
command: command or script that should run
Root has access to two crontabs. One is accessible through crontab and the other can be opened in your editor: vi /etc/crontab or nano /etc/crontab. Systemwide cron jobs should be added to /etc/crontab which take precedence over your regular cron.
A sample cron job should look like the following line. Here is a line I have in my crontab to sync time with external time servers:
# m h dom mon dow user command
01 0 * * * root ntpdate us.pool.ntp.org
This cron job will sync time at 12:01 AM every night with pool.ntp.org
Tip: to create a cron job to run every time your system reboots (game servers, etc.) start your line with @reboot:
@reboot /home/user/script
Notice that you don’t need to specify anything but @reboot and path to executable. Regular and privileged users can both use this command.
Other commands:
@reboot = run at boot and reboot only
@yearly = run at midnight Jan 1 (0 0 1 1 *)
@annually = run at midnight Jan 1(0 0 1 1 *)
@monthly = run at midnight on the first day of every month (0 0 1 * *)
@weekly = run at midnight every Sunday (0 0 * * 0)
@daily = run at midnight every day (0 0 * * *)
@midnight = run at midnight (0 0 * * *)
@hourly = run on the first second of every hour (0 * * * *)
VMware ESX and ESXi – tips and tricks
by Ali on Nov.11, 2008, under VMware
To clear connection history in VIC go to regedit and delete the line “RecentConnections” from HKEY_CURRENT_USER\Software\VMware\VMware Infrastructure Client\Preferences.
To allow root access to logon through ssh in ESX:
Logon to console as root
Edit sshd_config: nano /etc/ssh/sshd_config and change “PermitRootLogin” from “no” to “yes”
Restart ssh: service sshd restart
To allow root access to logon through ssh in ESXi:
Open console and press Alt+F1
Type "unsupported" and enter root password to log on
Open inetd.conf in vi: vi /etc/inetd.conf
Find the line that starts with #ssh, uncomment, save and close the file, and then restart services on your ESXi server: /sbin/services.sh restart
To allow non-root access to logon through ssh in ESXi:
Log on to console: press Alt-F1 (or through root ssh)
Edit inetd.conf: vi /etc/inetd.conf
Find this line: "ssh stream tcp nowait root /sbin/dropbearmulti dropbear ++min=0,swap,group=shell -i" and add -w to the end. Save and close the file.
Create the new users and home directory: useradd -d /home/username -P username
Reboot
Linux: Find and delete files/directories recursively in Linux
by Ali on Nov.08, 2008, under Linux
To have the OS find and delete files and directories recursively in Linux try the following command:
find <path> -name <filename> -exec rm -rf {} ;
Example:
find /vmware -name *.log -exec rm -rf {} ;
To find and replace strings within files look here.