Hiển thị các bài đăng có nhãn NGINX. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn NGINX. Hiển thị tất cả bài đăng

Thứ Sáu, 26 tháng 2, 2016

How to Install Nginx on Ubuntu 14.04 LTS

Nginx is a free, open source, high-performance web server. Need HTTP and HTTPS but don’t want to run Apache? Then nginx may be your next go-to, at least for Linux.

Pre-Flight Check

  • These instructions are intended specifically for installing nginx on Ubuntu 14.04 LTS.
  • I’ll be working from a Liquid Web Self Managed Ubuntu 14.04 server, and I’ll be logged in as root.

Step #1: Install nginx

First, you’ll follow a simple best practice: ensuring the list of available packages is up to date before installing anything new.
sudo apt-get -y update
Then it’s a matter of just running one command for installation via apt-get:

sudo apt-get -y install nginx

Step #2: Find Your IP Address; Visit Your Site

Once the installation is complete the nginx service should automatically start and begin listening on port 80. 
Find your server’s IP address run the following command:
ip addr show eth0 | grep inet
In this case we are assuming that eth0 is configured with the primary public IP of your server. Your result may look similar to:

inet xxx.xxx.xxx.xxx/22 brd yyy.yyy.yyy.yyy scope global eth0
Where xxx.xxx.xxx.xxx is the IP address of your server.
Verify that nginx is running by visiting http://xxx.xxx.xxx.xxx. For example: http://1.2.3.4.
You should receive a page similar to:

Step #3: Manage the nginx Service

Start the nginx Service:
service nginx start
Stop the nginx Service:

service nginx stop
Restart the nginx Service:

service nginx restart
Check the Status of the nginx Service:

service nginx status
Assure that nginx starts at boot:

update-rc.d nginx defaults
When running the last command you may receive:

System start/stop links for /etc/init.d/nginx already exist.
The above error simply means that nginx is already configured to start when the server boots.

Thứ Năm, 25 tháng 2, 2016

Setting Up MUNIN on Ubuntu Server 14.04 with NGINX

This post explains how to configure munin on a single Ubuntu 14.04 server that uses nginx.

sudo apt-get update
sudo apt-get install nginx
Monitoring is supposed to save time by debugging and predicting / avoiding catastrophes. However, setting up munin on Ubuntu was a time-consuming trial-and-error process for me. The official instructions and various blog posts that cover this topic skip important steps, such as having monit's FastCGI processes start automatically at boot time. I have documented the setup that worked for me, hoping that others can reuse my work.


Ubuntu packages

Run the following command to install the packages needed for munin.

sudo apt-get install munin munin-node spawn-fcgi libcgi-fast-perl
The following sections configure the munin packages.

Munin configuration

Write the munin configuration below to /etc/munin/munin-conf.d/90-fcgi

graph_strategy cgi
html_strategy cgi
cgiurl_graph /munin/munin-cgi-graph

NGINX configuration

Write the nginx configuration below to /etc/nginx/sites-available/munin.conf

server {
  #listen 443 ssl;
  listen 7000;
  charset utf-8;
  #server_name munin.your-domain.com;
  location ~ ^/munin/munin-cgi-graph/ {
    fastcgi_split_path_info ^(/munin/munin-cgi-graph)(.*);
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/var/run/munin/fastcgi-graph.sock;
    include fastcgi_params;
  }
  location /munin/static/ {
    alias /etc/munin/static/;
    expires modified +1w;
  }
  location /munin/ {
    fastcgi_split_path_info ^(/munin)(.*);
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/var/run/munin/fastcgi-html.sock;
    include fastcgi_params;
  }
  location / {
    rewrite ^/$ munin/ redirect; break;
  }
}
This configuration assumes that you have a DNS entry set aside for reaching the monit pages. I have separate DNS entries for all my applications, and they're all CNAMEs for the (same) machine that they're running on.
Once you're done tweaking the script, reload nginx.

sudo /etc/init.d/nginx reload

FastCGI daemons

Write the script below to /etc/init.d/munin-fcgi
#!/bin/bash

### BEGIN INIT INFO
# Provides:          munin-fcgi
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start munin FCGI processes at boot time
# Description:       Start the FCGI processes behind http://munin.*/
### END INIT INFO

graph_pidfile="/var/run/munin/fcgi_graph.pid"
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-graph
graph_cgi="/usr/lib/munin/cgi/munin-cgi-graph"
html_pidfile="/var/run/munin/fcgi_html.pid"
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-html
html_cgi="/usr/lib/munin/cgi/munin-cgi-html"

retval=0

. /lib/lsb/init-functions

start() {
  echo -n "Starting munin graph FastCGI: "
  start_daemon -p ${graph_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
      -s /var/run/munin/fastcgi-graph.sock -U www-data ${graph_cgi}
  echo
  echo -n "Starting munin html FastCGI: "
  start_daemon -p ${html_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
      -s /var/run/munin/fastcgi-html.sock -U www-data ${html_cgi}
  echo
  retval=$?
}
stop() {
  echo -n "Stopping munin graph FastCGI: "
  killproc -p ${graph_pidfile} ${graph_cgi} -QUIT
  echo
  echo -n "Stopping munin html FastCGI: "
  killproc -p ${html_pidfile} ${html_cgi} -QUIT
  echo
  retval=$?
}
case "$1" in
  start)
    start
  ;;
  stop)
    stop
  ;;
  restart)
    stop
    start
  ;;
  *)
    echo "Usage: munin-fcgi {start|stop|restart}"
    exit 1
  ;;
esac
exit $retval
Make the script executable, and fix some permissions while you're at it.

sudo chmod +x /etc/init.d/munin-fcgi
sudo chown munin /var/log/munin/munin-cgi-*
Now that the init.d script is in place, start it and have it run on every boot.

sudo /etc/init.d/munin-fcgi start
sudo update-rc.d munin-fcgi defaults

Debugging

You should be able to point your browser to http://[ip_address]:7000 and see many graphs. If that doesn't work out, the logs below should give you a clue as to what went wrong.

/var/log/nginx/error.log
/var/log/munin/munin-cgi-graph.log
/var/log/munin/munin-cgi-html.log

Conclusion

I hope that you have found my post useful, and I hope that it helped you get your munin monitoring setup up and running in a manner of minutes.