Tuesday, June 6, 2023

Level up your Automation Game

Here's a strategic plan I've been following to help improve my automation programming skills, primarily focusing on Python but also [trying] incorporating some Go.

The efficiency of this plan, similar to many others, hinges on two primary pilars: Deliberate Practice and Consistency

  1. Python Basics and Advanced Concepts: Start by revisiting the Python basics (variables, data types, functions, loops, conditional statements). * Gradually move to more advanced topics (OOP concepts, file handling, exception handling, generators, decorators).

  2. Dive Deeper into Python: Understand Python's standard library. It's broad and powerful, and a lot of what you might want to do for automation might already be covered. * Learn about working with databases, APIs, and web scraping as they are common in automation tasks.

  3. Automation Specific Python Libraries: Learn libraries that are frequently used in automation tasks, like Selenium for web automation, or Pyautogui for GUI automation.

  4. Practice, Practice, Practice: Regular practice is key to mastering any programming language. Try to automate simple tasks that you do daily. It could be anything from organizing your files to web scraping news articles. * Websites like Codewars, LeetCode, and HackerRank provide Python problems that you can practice on.

  5. Go Programming: Once you're confident with Python, start exploring Go. Go is known for its simplicity and efficiency, which can be particularly useful for certain automation tasks. * Begin with the basics (variables, data types, control structures, functions) and move on to more complex topics (pointers, structures, interfaces, concurrency). * Start writing small scripts, then slowly move onto more complex tasks.

  6. Projects: The most effective way to learn is by doing. Apply your skills to real-world projects. These could be work-related or personal projects. * GitHub is a great place to find open-source projects where you could contribute, or get inspiration for your own projects.

  7. Continuous Learning: The tech world is always evolving, so it's crucial to stay up-to-date. Follow relevant blogs, forums, or influencers who can provide insights into the latest trends and best practices.

Remember, it's perfectly okay to feel overwhelmed when learning something new. Be patient with yourself and celebrate your progress, no matter how small it might seem. The key to becoming proficient in any programming language is consistency and practice. Happy coding!

SRE Best Practices: Boosting Reliability, Performance, and Efficiency in the Cloud

Site Reliability Engineering (SRE) is a discipline that combines software engineering principles and practices to create ultra-scalable and highly reliable software systems. Initially developed at Google, SRE has become an industry standard, especially important for cloud-based environments. In this blog post, we'll delve into some SRE best practices to enhance the reliability, performance, and efficiency of services running on hosted cloud environments.

Embrace SLOs, SLIs, and SLAs 

Service Level Objectives (SLOs), Service Level Indicators (SLIs), and Service Level Agreements (SLAs) are vital components of SRE. SLIs are the metrics or indicators used to measure the performance and health of a service. SLOs are the target values or range of values for these metrics. SLAs, on the other hand, are the contracts with customers that specify what happens if an SLO is not met.

These elements play an essential role in balancing reliability and the pace of development. They help quantify reliability, make informed decisions about risk, and prevent reliability from becoming an afterthought.

Automate as Much as Possible

Automation is a core tenet of SRE. From deployments and scaling to incident management and remediation, automation drives consistency, reduces human error, and allows your team to focus on more complex tasks. For example, automating the deployment process through CI/CD pipelines helps ensure reliable releases and faster recovery times when issues arise.

Error Budgets and Risk Management

An error budget is the acceptable level of risk or failure defined by the SLO. If a service's reliability exceeds its SLO, the error budget is "positive," and you can take more risks like accelerating feature deployment. However, if the error budget is "negative," it means you're not meeting your SLO and should focus on improving reliability.

Prioritize Incident Management

Despite your best efforts, incidents will occur. Effective incident management includes defining an incident response process, having an on-call rotation, and following up with a blameless postmortem. This approach not only resolves incidents effectively but also turns them into learning opportunities to prevent recurrence.

Embrace a Culture of Learning and Blamelessness

SRE encourages learning from failures instead of blaming. It's important to create a culture where people feel safe to report and learn from mistakes. Blameless postmortems are a key tool in this respect, focusing on identifying the contributing causes of incidents without pointing fingers.

Monitoring and Observability

You can't improve what you can't measure. Comprehensive monitoring and observability are key to understanding your system's behavior and identifying areas for improvement. Utilize logging, metrics, and tracing to gain a full view of your system's performance and health.

Capacity Planning

Capacity planning helps ensure your services can handle the load and meet performance expectations. It includes forecasting demand, managing resource usage, and planning for scalability. It's crucial to use tools for auto-scaling and load balancing in cloud environments to handle sudden traffic spikes or grow over time.

Conclusion

SRE is a powerful approach for managing and improving services running in the cloud. By embracing SRE best practices, you can boost the reliability, performance, and efficiency of your services, ensuring that they not only meet customer expectations but also contribute to the overall success of your business.

Remember that SRE is not just about tools and practices; it's also about culture. By fostering a culture of blamelessness, continuous learning, and a focus on reliability, you can create a robust and resilient cloud ecosystem.

Wednesday, January 20, 2021

Install python2.7 alongside 2.6 on Centos6 or 7

# install python 2.7 alongside 2.6 on centos 6

* note this also works with python3 and 2.6.

 

# Install Dev tools
yum groupinstall -y "development tools"


# Install required libraries
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel


# Install wget if you don't already have it
yum install -y wget


# Download Python 2.7.14 package
wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz


# Unzip it
tar xvf Python-2.7.14.tar.xz


# Go into directory for install
cd Python-2.7.14 Python-2.7.14.tar.xz


# configure python2.7 in /usr/local/bin
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"


# Compile it as an alt-install (SUPER CRITICAL STEP!!!). This will allow you to run both existing python and newly installed python
sudo make && sudo make altinstall

Thursday, November 14, 2019

Trim videos quickly using FFMPEG

You can easily trim videos using command line on a mac or linux.

On a mac, you'll need to install FFMPEG.  you can get this from homebrew.

If you don't have homebrew, you can install it easily following the one liner instructions from their site.

Install Homebrew
       

 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
       
 



Once Homebrew is installed, then install FFMPEG via homebrew.  Open your terminal and use the following command to install FFMPEG.

       

 brew install ffmpeg
       
 


Then run the following command (substitute your input.mp4 and output.mp4 with desired filenames).

       

  ffmpeg -i input.mp4 -ss 00:10:25 -to 01:18:34 -c:v copy -c:a copy output.mp4
       
 

This will cut your input.mp4 video file.  Start will be 10 minutes and 25 seconds.  The end will be 1 hour 18 minutes and 34 seconds.   Also, this should take only about 5-10 seconds.

Enjoy!

Wednesday, December 12, 2018

Setup WebPageTest Private Instances

The following article describes how to run a private instance of WebpageTest on your local host.

Assumptions:  You have docker installed.


step 1. pull down agent and server images
docker pull kmaqsudi/wpt-private-server
docker pull kmaqsudi/wpt-private-agent
step 2: Run the server instance
docker run -d -p 4000:80 kmaqsudi/wpt-private-server
step 3: Run the agent instance
docker run -d -p 4001:80 --network="host" kmaqsudi/wpt-private-agent
Open a browser and navigate to http://localhost:4000 and you should see your private instance.




 


To check the details of your install browse to the following URL:

http://localhost:4000/install/


Saturday, October 6, 2018

Memory




"We remember what we understand; we understand only what we pay attention to; we pay attention to what we want." - Edward Bolles


You can learn to remember more effectively if you learn and use the four keys described below. Each one helps you to enter information into your long term memory.
  1. Choose to remember. Be interested. Pay attention. Want to learn and know. What you want is an important part of learning. When people are interested and want to learn, they learn and remember more effectively.
  2. Visualize or picture in your mind what you wish to remember. For many people, a mental picture or visualization is clearer and easier to remember than words. For each major concept that you want to remember, create a mental picture and then look at it carefully for a few seconds. Once you've seen it clearly, you'll probably be able to recall it.
  3. Relate the ideas and information you wish to remember to each other and to ideas and information you already know. When you relate information to other information, you create a chain of memories which lead to one another. When you label an information chain or group of ideas, you create a kind of "file" that makes it easy to locate and remember the information.
  4. Repeat what you wish to learn until you overlearn it. Say it in your own words. Even though you've already learned something, go over it one more time. Research shows that the time you spend on overlearning and putting ideas into your own words will pay off by making recall easier and more complete.

Author: keeleym@bucks.edu








Monday, February 5, 2018

Create SAN certificate CSR on macOS

Steps to create SAN certificate CSR on your MacOS





Assuming that your domains are the following 4 domains

www.example.com
www.example1.com
www.example2.com
www.example3.com
www.example4.com


Step 1:

#Open your terminal app and create a file called sancert.cnf

Step 2:

#In this new file you just created insert the following lines of text.

[ req ]
default_bits        = 2048
distinguished_name = req_distinguished_name
req_extensions              = req_ext

[ req_distinguished_name ]
countryName                  = Country Name (2 letter code)
stateOrProvinceName    = State or Province Name (full name)
localityName              = Locality Name (eg, city)
organizationName    = Organization Name (eg, company)
commonName      = Common Name (e.g. server FQDN or YOUR name)

[ req_ext ]
subjectAltName = @alt_names

[alt_names]
DNS.1   = www.example.com
DNS.2   = www.example1.com
DNS.3   = www.example2.com
DNS.4   = www.example3.com
DNS.5   = www.example4.com


Step 3:
Save your file and go back to your terminal app.

Step 4:

# In your terminal, type the following command (in the same dir as the file you just created)

$ openssl req -out sslcert-example.csr -newkey rsa:2048 -nodes -keyout sslcert-example.key -config sancert.cnf



This will create 2 files. 
1.  sslcert-example.csr
2.  sslcert-example.key





Thursday, October 6, 2016

Revert Git changes

To rollback to a specific revision on github (Helpful if you accidentally merged and pushed to branch)

# switch to branch you need to rollback
git checkout branch_name

# make sure you have the updated version
git pull

# rollback to specific version
git reset --hard 56e08f23

# push your changes back to github
git push -f




To remove a specific commit that has been pushed to remote repos

#Identify the commit hash
git revert -m 1 56e08f23

# confirm the revert was correctly done and push back up to remote repos
git push -f

Saturday, February 13, 2016

Hello World

Wow, I must have been asleep all of 2015 to not have posted.  Will pick this up again in 2016.  :)

Saturday, October 25, 2014

Yahoo messenger breaks if you upgrade to Yosemite. - fixed

Short post....

If you upgrade your mac to Yosemite, your yahoo messenger will not work.

All credit to Chris Knight for this fix.




Download the following patched Adium and you're good to go.
http://www.ghostwheel.com/adium-yahoo-fix/Adium.app.zip






Original post can be found here...

http://www.ghostwheel.com/merlin/Personal/notes/tag/yosemite/

-Khalid






Friday, October 3, 2014

Connecting to Citrix Netscaler via browser on a Mac

If you need to connect to a citrix netscaler via your browswer using Mac OS X and getting an error message stating 'Missing Java plugin', follow the steps below to correct it.


Open Preferences


Click on Java on the bottom and a new Java console window will open...


In the Temporary internet files section of the 'General' tab, click on 'Settings..."

Then make sure that "Keep temporary files on my computer" is unchecked.



Restart your browser and you should be able to connect.  



Thursday, July 3, 2014

Are you interested or committed?


Are You Interested Or Committed?

I was thinking about what to write this week when this quote popped into my head:
"Interested people do what is convenient. Committed people do whatever it takes."
I’ve heard this term applied to entrepreneurs who want to have a successful business. Basically the question is – are you interested or committed to have a successful business?

However, the real question is:  Are you interested or committed to achieving your goals?

And that question is for everyone.

Do you have a list of goals? Pull them out or if they’re in your head – write them down. Look at each goal: are you interested in achieving that goal or are you committed to achieving it?

Interested says: I’d really like to achieve this goal, it’d be cool! 
Committed says: I will achieve this goal and here is what I’m doing.


Which ones do you think you’ll achieve? 
The one’s you’re interested in or the one’s you’re committed to? Yep, you’re most likely to achieve the goals that you’re committed to.  Take another look at those goals that you’re interested in.  Be really honest with yourself – why do you want to achieve those goals? Because your friend or colleague did? Because someone else told you that you should? Or because you think you should? Do you really need me to tell you that those reasons probably won’t motivate you?


Can you move from interested to committed? Yep! But you need a better reason than “I want to keep up with the Jones’s”. What does achieving that goal really mean to you? What will change by achieving that goal and how is that different from where you are now?  Motivation for a goal you’re committed to comes from within you and not from someone else. It gets you fired up and willing to step outside your comfort zone. It’s powerful.

What goals are you committed to?



Tuesday, June 10, 2014

Kibana 3 with ATG logs



I'm going to give this a shot and see how it goes.  The toolchain used in this demo seems bloated though...

source:

http://atgadapt.com/aggregated-logging-for-atg-with-kibana/




Sunday, March 30, 2014

Adium 1.5.9 'connecting' to yahoo!

If anyone else is having issues connecting to Yahoo Messanger using Adium 1.5.9,  upgrading to the nightly build 1.5.10 seems to have fixed this issue.

Problem description:
When using Adium to log into your Yahoo! messanger account, the status remains on 'connecting'. Gtalk/etc, is working fine.  As is the default Yahoo! messenger app.


Resolution: 
Upgrading to the nightly build version 1.5.10 seems to have solved the issue.



http://nightly.adium.im/adium-adium-1.5.10/Adium_1.5.10hgr5845.dmg




Sunday, March 2, 2014

Live. Love. Matter

Most people are not apathetic fools—they are engaged and intelligent beyond measure. It's just that they spend a shocking amount of time studying foolish things, and so they have gained great intelligence in the inconsequential. They know dozens of batting averages, celebrity baby names, and trivial anecdotes from the latest news alert. They know more about television characters than their coworkers; more about the freeway traffic ahead than their financial future; more about the new tech toy than what's truly missing from their lives.

This of course, does not describe everyone. Yet we have the average American watching four hours of television per day. This amounts to around 13 years of his or her lifetime. Yes, that's 13 years 24/7 in front of the boob tube. Those years slip by episode-to-episode, and often feel like rest and entertainment. But all research shows they amount to very little joy or meaning in one's day or life.

The cost is immense: had those 13 years been used for vital and productive endeavor, they would amass to nearly $1,000,000 more in wages and over $2,000,000 in investment opportunity. Let's not forget how those 13 years could have been used to deepen friendships, travel, create more art, learn languages, develop world-class expertise, contribute, enjoy love, or live life as a human rather than a gape-mouthed consumer of waste.

While television isn't stealing everyone's four hours, most of us now suffer from a sort of recurring "browser blackout" or "app amnesia," losing hours of time each day on our computer or mobile devices without any recollection of what we saw or accomplished. Distraction reigns.

And so the outcome is we have tremendously engaged and intelligent people often tragically consuming and learning meaningless things. We are busy, but at what? We are smart, but at what? We are engaged, but with what?

Not everyone is so lost, but this might help explain the melancholy one feels in our society. For what could be worse than for smart, engaging people to finish their lifetimes without much to show for it but the ability to win a pop culture trivia contest?

Let us choose once again to aim our ambition and intelligence toward meaningful endeavors. Let's be productive. Let's serve. Let's enjoy this gift of life.


- Brendon Burchard

Tuesday, December 24, 2013

Talk is cheap

There are many people who — perhaps with the best of intentions — make promises they somehow never get around to keeping. These folks have usually developed a number of perfectly plausible explanations for not meeting their commitments; they have become experts at explaining away their failures. Successful people, though, are those who accept responsibility for their lives. They know that talk is cheap; actions are all that really matter. The world is waiting for men and women who seek the opportunity to render real service — the kind of service that lightens the burdens of their neighbors, the kind of service that 95 percent of people do not render because they do not understand it. When you provide a truly useful service, enthusiastically and in a spirit of genuine helpfulness, success will automatically follow. The world seeks out such individuals and rewards them accordingly.

- author unknown

Saturday, October 26, 2013

Cisco VPN issue with OS X Mavericks - solved

If you are having an issue with the Cisco VPN client after upgrading to OS X Mavericks, here is the solution...

open a terminal (iterm)

# edit the sysctl.conf file
sudo vim /etc/sysctl.conf

# comment out the following line.
kern.ipc.maxsuckbuf=512000.

Your file should look like this after you edit...

#
# Tuning network for broadband
#
# START
# kern.ipc.maxsockbuf=512000
net.inet.tcp.sendspace=131072
net.inet.tcp.recvspace=358400
# END



# Last step is to reboot.

Saturday, June 29, 2013

Thursday, June 27, 2013

Do The Work



No book, blog, online course or seminar works until the moment you start doing the work
-- Robin Sharma






Friday, June 14, 2013

What is Web Operations?



Very interesting article on Web Operations.  Its a bit old but very much still relevant from Theo Schlossnagle.  Excellent read.






Thursday, April 18, 2013

FlushDNS cache on Mac OS X and Linux



#flush your DNS cache on your Mac OS X machine


#Yosemite
sudo discoveryutil mdnsflushcache

#Mountain Lion
sudo killall -HUP mDNSResponder


#CentOS
sudo /etc/init.d/nscd restart










Wednesday, April 17, 2013

Expand LVM in CentOS 6


# review your disk layout
fdisk -l

# scan for new disk.
echo "- - -" > /sys/class/scsi_host/host0/scan

# check disk layout again {notice changes}
fdisk -l



fdisk /dev/sda
p  (print partition table)
n  (New partition)
p  (primary partition)
3  (ID #3 (this may be different for you, since I already had /dev/sda1 and 2)

# When asked for block value, add 1 to the end of block value for sda2 partition and use it as the start of the sda3 partition.  

t  (change partition type)
3 (change partition 3)
8e (Type = Linux LVM)
p (print the partition table again)
w (write the partition table)


# Now create a new LVM physical volume from the partition you just created.
lvm pvcreate /dev/sda3
lvm pvdisplay

# Mount the volume group
lvm vgscan
lvm vgchange -ay
* a message will echo that the volume group is activated.

# extend the volume group with the new physical volume.  change the volume group hostname with yours. 
lvm vgextend /dev/vg_vdevd01 /dev/sda3

# now extend the logical volume to include the new partition. 
lvm lvextend /dev/vg_vdevd01/lv_home /dev/sda3

# Mount the volume group
lvm vgscan
lvm vgchange -ay

# Run a filesystem check on the newly expanded disk
e2fsck -f /dv/vg_hostname/lv_root

# resize the filesystem to use the entire disk
resize2fs /dev/vg_vdevd01/lv_home

# reboot and check your new disk 
df -h

Thursday, March 28, 2013

Execution is the Key

Three things that need to be done in order to accomplish your goals.  Don't set vague goals without knowing the details.

1.  Understand what to do.
2.  Understand how to do it.
3.  Execute

Most people set vague goals such as exercising more, improving on A or B, etc.  The key is lay out the plan on what steps are needed to call this goal a success.  "Working on it" is not completing it.  You don't get to check it off your list if your still "working on it".   One good point to remember is that the beginning is usually the most difficult both physically and mentally.  Don't quit! Get past the first few hurdles and keep going.  

-Khalid

Thursday, February 7, 2013

Monday, January 28, 2013

Seth Goden - Beyond Showing up


Beyond showing up

You've probably got that part nailed. Butt in seat, smile on your face. We often run into people who understand their job to be showing up on time to do the work that's assigned.
We've moved way beyond that now. Showing up and taking notes isn't your job. Your job is to surprise and delight and to change the agenda. Your job is to escalate, reset expectations and make us delighted that you are part of the team.
Showing up is overrated. Necessary but not nearly sufficient.

Monday, December 24, 2012

21 tips to get you to your best productivity


Another great article from Robin Sharma via robinsharma.com

Here are 21 tips to get you to your best productivity.
#1. Check email in the afternoon so you protect the peak energy hours of your mornings for your best work.
#2. Stop waiting for perfect conditions to launch a great project. Immediate action fuels a positive feedback loop that drives even more action.
#3. Remember that big, brave goals release energy. So set them clearly and then revisit them every morning for 5 minutes.
#4. Mess creates stress (I learned this from tennis icon Andre Agassi who said he wouldn’t let anyone touch his tennis bag because if it got disorganized, he’d get distracted). So clean out the clutter in your office to get more done.
#5. Sell your TV. You’re just watching other people get successful versus doing the things that will get you to your dreams.
#6. Say goodbye to the energy vampires in your life (the negative souls who steal your enthusiasm).
#7. Run routines. When I studied the creative lives of massively productive people like Stephen King, John Grisham and Thomas Edison, I discovered they follow strict daily routines. (i.e., when they would get up, when they would start work, when they would exercise and when they would relax). Peak productivity’s not about luck. It’s about devotion.
#8. Get up at 5 am. Win the battle of the bed. Put mind over mattress. This habit alone will strengthen your willpower so it serves you more dutifully in the key areas of your life.
#9. Don’t do so many meetings. (I’ve trained the employees of our FORTUNE 500 clients on exactly how to do this – including having the few meetings they now do standing up – and it’s created breakthrough results for them).
#10. Don’t say yes to every request. Most of us have a deep need to be liked. That translates into us saying yes to everything – which is the end of your elite productivity.
#11. Outsource everything you can’t be BIW (Best in the World) at. Focus only on activities within what I call “Your Picasso Zone”.
#12. Stop multi-tasking. New research confirms that all the distractions invading our lives are rewiring the way our brains work (and drop our IQ by 5 points!). Be one of the rare-air few who develops the mental and physical discipline to have a mono-maniacal focus on one thing for many hours. (It’s all about practice).
#13. Get fit like Madonna. Getting to your absolute best physical condition will create explosive energy, renew your focus and multiply your creativity.
#14. Workout 2X a day. This is just one of the little-known productivity tactics that I’ll walk you through in my new online training program YOUR PRODUCTIVITY UNLEASHED (details at the end of this post) but here’s the key: exercise is one of the greatest productivity tools in the world. So do 20 minutes first thing in the morning and then another workout around 6 or 7 pm to set you up for wow in the evening.
#15. Drink more water. When you’re dehydrated, you’ll have far less energy. And get less done.
#16. Work in 90 minute blocks with 10 minute intervals to recover and refuel (another game-changing move I personally use to do my best work).
#17. Write a Stop Doing List. Every productive person obsessively sets To Do Lists. But those who play at world-class also record what they commit to stop doing. Steve Jobs said that what made Apple Apple was not so much what they chose to build but all the projects they chose to ignore.
#18. Use your commute time. If you’re commuting 30 minutes each way every day – get this: at the end of a year, you’ve spent 6 weeks of 8 hour days in your car. I encourage you to use that time to listen to fantastic books on audio + excellent podcasts and valuable learning programs. Remember, the fastest way to double your income is to triple your rate of learning.
#19. Be a contrarian. Why buy your groceries at the time the store is busiest? Why go to movies on the most popular nights? Why hit the gym when the gym’s completely full? Do things at off-peak hours and you’ll save so many of them.
#20. Get things right the first time. Most people are wildly distracted these days. And so they make mistakes. To unleash your productivity, become one of the special performers who have the mindset of doing what it takes to get it flawless first. This saves you days of having to fix problems.
#21. Get lost. Don’t be so available to everyone. I often spend hours at a time in the cafeteria of a university close to our headquarters. I turn off my devices and think, create, plan and write. Zero interruptions. Pure focus. Massive results.
I truly hope these 21 productivity tips have been valuable to you. And that I’ve been of service. Your productivity is your life made visible. Please protect it.
Stay productive.

Tuesday, December 18, 2012

Using mod_jk1.2 with JBoss



Using mod_jk 1.2.x with JBoss/Tomcat bundle and Apache2

Quick Overview


  1. Download Apache2
  2. Download modjk 1.2.x (At least 1.2.27 suggested)
  3. Change the main Apache config to include modjk config
  4. Create the modjk config
  5. Configure the modjk workers (which JBoss/Tomcat nodes Apache uses)
  6. Configure the Apache URIs served by modjk (the applications served by JBoss/Tomcat)
  7. Restart Apache
  8. Configure Tomcat (Give each JBoss/Tomcat a jvmRoute for session stickness)
  9. Restart JBoss
  10. Test it

mod_proxy

Most httpd-2.2.x actual distributions (x>=6) have a decent AJP proxying and don't require to compile an external module. See

More Details


This wiki outlines the various steps required to install a basic load-balancing solution based on JBoss/Tomcat and mod_jk 1.2.

Step 1: Download Apache2 Web Server

Get the latest Apache2 package from Apache.org and install it. We require no special configuration, just use the default settings.
In the following steps, APACHE_HOME will represent the Apache install directory.

Step 2: Download mod_jk 1.2.x

Download the latest package available from Tomcats's 'Download Tomcat connector section' page . Always download the latest stable release if possible.

Rename the lib mod_jk.so and drop it in APACHE_HOME/modules directory.

NOTE: Don't use any release prior to mod_jk 1.2.15. Earlier releases are fairly buggy.

+
Note: Darwin Ports supports the installation of mod_jk on OS X. See http://darwinports.opendarwin.org/ for more info.
+

Step 3: Setup Apache to use modjk

Add this line at the very bottom in APACHE_HOME/conf/httpd.conf :
# Include mod_jk configuration file
Include conf/mod-jk.conf

Step 4: Create the modjk config

Under APACHE_HOME/conf, create mod-jk.conf and populate it as follows:
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers.properties

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicates to send SSK KEY SIZE
# Notes: 
# 1) Changed from +ForwardURICompat. 
# 2) For mod_rewrite compatibility, use +ForwardURIProxy (default since 1.2.24)
# See http://tomcat.apache.org/security-jk.html  
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
JkMount /__application__/* loadbalancer
# Let Apache serve the images
JkUnMount /__application__/images/* loadbalancer

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
# Note: Replaced JkShmFile logs/jk.shm due to SELinux issues. Refer to 
# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
JkShmFile run/jk.shm

# Add jkstatus for managing runtime data
<Location /jkstatus>
JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>

mod_jk is ready to forward requests to JBoss instances. We need now to setup the workers

Note: As of mod_jk 1.2.6+ you need to include "JkMountCopy all" in globals if you intend to specify global JkMount's or JkMountFile's instead of per VirtualHost. If you do not want to copy the same JkMount/JkMountFile for each VirtualHost, you can specify "JkMountCopy On" inside the VirtualHost directive.

-


Step 5: Configuring workers

Under APACHE_HOME/conf, create workers.properties and populate it as follows:
# Define list of workers that will be used
# for mapping requests
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
#
worker.list=loadbalancer,status


# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.prepost_timeout=10000 #Not required if using ping_mode=A
worker.node1.connect_timeout=10000 #Not required if using ping_mode=A
worker.node1.ping_mode=A #As of mod_jk 1.2.27
# worker.node1.connection_pool_size=10 (1)

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host= node2.mydomain.com
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.prepost_timeout=10000 #Not required if using ping_mode=A
worker.node2.connect_timeout=10000 #Not required if using ping_mode=A
worker.node2.ping_mode=A #As of mod_jk 1.2.27
# worker.node1.connection_pool_size=10 (1)

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2

# Status worker for managing load balancer
worker.status.type=status

Important: Please review http://tomcat.apache.org/connectors-doc/reference/workers.html for the directive descriptions. Especially lookout for the comments on cachsize for Apache 1.3.x.

(1) You should only set the connection_pool_size if the number of allowed connection to the Httpd is higher than maxThreads in server.xml

If you specify worker.loadbalancer.sticky_session=Off, each request will be load balanced between node1 and node2. But when a user opens a Session on one server, it is a good idea to always forward this user's requests to the same server. Otherwise the user's session data would need to be synchronized between both servers. This is called a "sticky session", as the client is always using the same server he reached on his first request.
Session stickiness is enabled by default.

Side Note: a non-loadbalanced setup with a single node required the "worker.list=node1" entry before mod_jk would function correctly. Without this setting I would only get a 500 error and no other useful messages in log or otherwise. -Harlequin516

Side Note: I tried both loadbalanced and single node methods on Fedora 4. Both setups causing jk.shm errno=13 and jk-runtime-status errno=13 in the mod_jk.log. Could only get 500 errors. As a last resort disabled selinux on apache server. Restarted service and connection was made first try. -paulbrown


Step 6: Create the URI to worker map file

Create a uriworkermap.properties file in the APACHE_HOME/conf directory. This file should contain the URL mappings you want Apache to forward to Tomcat. The format of the file is /url=worker_name. To get things started, paste this example into the file you created:
# Simple worker configuration file
#

# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
/myapp/*=loadbalancer
!/myapp/images/*=loadbalancer
This will configure mod_jk to forward requests for the /jmx-console/web-console and /myapp contexts to JBoss Web. The '!' at the beginning of the last line results in the URLs for the images dir in the myapp context not being forwarded. Instead httpd will handle them directly (which means they must be available on the httpd server).

Step 7: Restart Apache


Step 8: Configure Tomcat

To complete the configuration, we also need to name each node to match the names specified in workers.properties.

To do this, edit the server.xml file. Where server.xml is located depends on the version of JBoss AS:

  • In JBoss 5, it's $JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml
  • In JBoss 4.2.x and EAP 4.x, it's $JBOSS_HOME/server/all/deploy/jboss-web.deployer/server.xml
  • In earlier releases it's $JBOSS_HOME/server/all/deploy/jbossweb-tomcatXX.sar/server.xml where XX is 40, 50, 55 etc depending on the Tomcat version embedded in the AS.

(In the examples above, replace /all/ with the name of the AS configuration you are running.)

Locate the <Engine/.> element and add an attribute jvmRoute:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
.
</Engine>
The jvmRoute attribute value must match the name specified in workers.properties.

In the server.xml file, make sure that the AJP 1.3 Connector is uncommented, e.g.:

<!-- A AJP 1.3 Connector on port 8009 -->
<Connector port="8009" address="${jboss.bind.address}"
      emptySessionPath="true" enableLookups="false" redirectPort="8443" 
      protocol="AJP/1.3" connectionTimeout="600000" maxThreads="200"/>

If you are only accepting requests via mod_jk, you can comment out the regular HTTP Connector; Tomcat then won't listen on port 8080.

Step 9: Activate the JvmRouteValve in JBoss (not needed with Tomcat Standalone)

Finally, we need to tell JBoss to add a special valve that detects when failover of a session from a distributable webapp has occurred. This JvmRouteValve ensures a new session cookie is emitted that includes the jvmRoute of the server that is now handling the session.

This configuration step is only needed with JBoss 4.2.x and earlier; beginning with JBoss AS 5 the application server uses the existence of a jvmRoute configuration in server.xml as an indication that it should add the JvmRouteValve.

To do this, edit the jboss-service.xml file for the JBoss Web service. Where this is located depends on the version of JBoss AS:

  • In JBoss 5, this step isn't needed.
  • In JBoss 4.2.x and EAP 4.x, it's $JBOSS_HOME/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml
  • In earlier releases it's $JBOSS_HOME/server/all/deploy/jbossweb-tomcatXX.sar/META-INF/jboss-service.xml where XX is 40, 50, 55 etc depending on the Tomcat version embedded in the AS.

Locate the <attribute> element with a name of UseJK, and set its value to "true":
<attribute name="UseJK">true</attribute>


Step 10: Restart JBoss AS.

Step 11: Access the JBoss AS web-console through Apache by browsing to http://localhost/web-console and you should see the JBoss web console page.

-

Note: to use mod_jk with Jboss 2 (e.g. jboss 2.4.6), you must edit jboss.jcml. Add the 'jvmRoute="myWorker"' to the Engine element under the EmbeddedCatalinaSX mbean.
-

-

Note: You may need to use VirtualHost in you mod-jk.conf. For example:
Instead of just
JkMount /jmx-console   loadbalancer
JkMount /jmx-console/* loadbalancer
try
<VirtualHost host.name.or.IP>
  ServerName host.name.or.IP

  JkMount /jmx-console loadbalancer
  JkMount /jmx-console/* loadbalancer
</VirtualHost>
-