systemd 를 사용하여 multi service 관리 하기.

Controlling a Multi-Service Application with systemd

DEC 4TH, 2016 11:15 PM

Is your application delivered as a set of services running on top of Linux? Did you think about writing a custom controller service that would start your application services in the correct order and monitor their health? Please, stop thinking about it! In this blog post I would like to convince you that you can leverage the existing systemd service manager to control your application services to your greatest benefit.

systemd is the default service manager on all major L…

http://alesnosek.com/blog/2016/12/04/controlling-a-multi-service-application-with-systemd/

Using KVM with Libvirt and macvtap Interfaces · Scott’s Weblog · The weblog of an IT pro specializing in virtualization, networking, open source, and cloud computing

Offering technical posts and how-to articles from an IT pro specializing in virtualization, networking, open source, & cloud computing

소스: Using KVM with Libvirt and macvtap Interfaces · Scott’s Weblog · The weblog of an IT pro specializing in virtualization, networking, open source, and cloud computing

How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7 | DigitalOcean

Introduction

A LEMP software stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the ENginx web server (which replaces the Apache component of a LAMP stack). The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.

In this guide, we’ll get a LEMP stack installed on an CentOS 7 VPS. CentOS will fulfill our first requirement: a Linux operating system.

Note: The LEMP stack can be installed automatically on your Droplet by adding this script to its User Data when launching it. Check out this tutorial to learn more about Droplet User Data.

Prerequisites

Before you begin with this guide, you should have a separate, non-root user account set up on your server. You can learn how to do this by completing steps 1-4 in the initial server setup for CentOS 7.

Note about SELinux: If you run into issues with Nginx not running, make sure the SELinux context of your Nginx configuration files is correct or change the SELinux mode to permissive or disabled.

Step One — Install Nginx

In order to display web pages to our site visitors, we are going to employ Nginx, a modern, efficient web server.

To add the CentOS 7 EPEL repository, open terminal and use the following command:

  • sudo yum install epel-release

Since we are using a sudo command, these operations get executed with root privileges. It will ask you for your regular user’s password to verify that you have permission to run commands with root privileges.

Now that the Nginx repository is installed on your server, install Nginx using the following yum command:

  • sudo yum install nginx

Afterwards, your web server is installed.

Once it is installed, you can start Nginx on your VPS:

  • sudo systemctl start nginx

You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):

Open in a web browser:
http://server_domain_name_or_IP/

You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

CentOS 7 Nginx Default

If you see this page, then your web server is now correctly installed.

Before continuing, you will want to do is enable Nginx to start on boot. Use the following command to do so:

  • sudo systemctl enable nginx

How To Find Your Server’s Public IP Address

If you do not know what your server’s public IP address is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.

From the command line, you can find this a few ways. First, you can use the iproute2 tools to get your address by typing this:

  • ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’

This will give you one or two lines back. They are both correct addresses, but your computer may only be able to use one of them, so feel free to try each one.

An alternative method is to use an outside party to tell you how it sees your server. You can do this by asking a specific server what your IP address is:

  • curl http://icanhazip.com

Regardless of the method you use to get your IP address, you can type it into your web browser’s address bar to get to your server.

Step Two — Install MySQL (MariaDB)

Now that we have our web server up and running, it is time to install MariaDB, a MySQL drop-in replacement. MariaDB is a community-developed fork of the MySQL relational database management system. Basically, it will organize and provide access to databases where our site can store information.

Again, we can use yum to acquire and install our software. This time, we’ll also install some other “helper” packages that will assist us in getting our components to communicate with each other:

  • sudo yum install mariadb-server mariadb

When the installation is complete, we need to start MariaDB with the following command:

  • sudo systemctl start mariadb

Now that our MySQL database is running, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running:

  • sudo mysql_secure_installation

The prompt will ask you for your current root password. Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter. Then the prompt will ask you if you want to set a root password. Go ahead and enter Y, and follow the instuctions:

mysql_secure_installation prompts:
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

New password: password
Re-enter new password: password
Password updated successfully!
Reloading privilege tables..
 ... Success!

For the rest of the questions, you should simply hit the “ENTER” key through each prompt to accept the default values. This will remove some sample users and databases, disable remote root logins, and load these new rules so that MySQL immediately respects the changes we have made.

The last thing you will want to do is enable MariaDB to start on boot. Use the following command to do so:

  • sudo systemctl enable mariadb

At this point, your database system is now set up and we can move on.

Step Three — Install PHP

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.

We can once again leverage the yum system to install our components. We’re going to include the php-mysql and php-fpm packages as well:

  • sudo yum install php php-mysql php-fpm

Configure the PHP Processor

We now have our PHP components installed, but we need to make a slight configuration change to make our setup more secure.

Open the main php-fpm configuration file with root privileges:

  • sudo vi /etc/php.ini

What we are looking for in this file is the parameter that sets cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to “1” by default.

This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if a PHP file does not match exactly. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn’t be allowed to execute.

We will change both of these conditions by uncommenting the line and setting it to “0” like this:

/etc/php.ini excerpt
cgi.fix_pathinfo=0

Save and close the file when you are finished.

Next, open the php-fpm configuration file www.conf:

  • sudo vi /etc/php-fpm.d/www.conf

Find the line that specifies the listen parameter, and change it so it looks like the following:

/etc/php-php.d/www.conf — 1 of 3
listen = /var/run/php-fpm/php-fpm.sock

Next, find the lines that set the listen.owner and listen.group and uncomment them. They should look like this:

/etc/php-php.d/www.conf — 2 of 3
listen.owner = nobody
listen.group = nobody

Lastly, find the lines that set the user and group and change their values from “apache” to “nginx”:

/etc/php-php.d/www.conf — 3 of 3
user = nginx
group = nginx

Then save and quit.

Now, we just need to start our PHP processor by typing:

  • sudo systemctl start php-fpm

This will implement the change that we made.

Next, enable php-fpm to start on boot:

  • sudo systemctl enable php-fpm

Step Four — Configure Nginx to Process PHP Pages

Now, we have all of the required components installed. The only configuration change we still need to do is tell Nginx to use our PHP processor for dynamic content.

We do this on the server block level (server blocks are similar to Apache’s virtual hosts). Open the default Nginx server block configuration file by typing:

  • sudo vi /etc/nginx/conf.d/default.conf

Currently, with the comments removed, the Nginx default server block looks like this:

/etc/nginx/conf.d/default.conf — original
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

We need to make some changes to this file for our site.

  • First, we need to add an index.php option as the first value of our index directive to allow PHP index files to be served when a directory is requested
  • We also need to modify the server_name directive to point to our server’s domain name or public IP address
  • The actual configuration file includes some commented out lines that define error processing routines. We will uncomment those to include that functionality
  • For the actual PHP processing, we will need to uncomment a portion of another section. We will also need to add a try_files directive to make sure Nginx doesn’t pass bad requests to our PHP processor

The changes that you need to make are in red in the text below. If you prefer, you may just copy and paste everything, then replace the value of server_name with the appropriate domain name or IP address:

/etc/nginx/conf.d/default.conf — updated
server {
    listen       80;
    server_name  server_domain_name_or_IP;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

When you’ve made the above changes, you can save and close the file.

Restart Nginx to make the necessary changes:

  • sudo systemctl restart nginx

Step Five — Test PHP Processing on your Web Server

In order to test that our system is configured properly for PHP, we can create a very basic PHP script.

We will call this script info.php. In order for Apache to find the file and serve it correctly, it must be saved to a very specific directory, which is called the “web root”.

In CentOS 7, this directory is located at /usr/share/nginx/html/. We can create the file at that location by typing:

  • sudo vi /usr/share/nginx/html/info.php

This will open a blank file. We want to put the following text, which is valid PHP code, inside the file:

Test PHP Script
<?php phpinfo(); ?>

When you are finished, save and close the file.

Now we can test whether our web server can correctly display content generated by a PHP script. To try this out, we just have to visit this page in our web browser. You’ll need your server’s public IP address again.

The address you want to visit will be:

Open in a web browser:
http://your_server_IP_address/info.php

The page that you come to should look something like this:

CentOS 7 default PHP info

This page basically gives you information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.

If this was successful, then your PHP is working as expected.

You probably want to remove this file after this test because it could actually give information about your server to unauthorized users. To do this, you can type this:

  • sudo rm /usr/share/nginx/html/info.php

You can always recreate this page if you need to access the information again later.

Conclusion

Now that you have a LEMP stack installed, you have many choices for what to do next. Basically, you’ve installed a platform that will allow you to install most kinds of websites and web software on your server.

소스: How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7 | DigitalOcean

ubuntu에서 rails , nginx 연동

아주 자세히 나와있음.

https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04

Introduction

If you are a Ruby on Rails developer, you probably need a web server to host your web apps. This tutorial shows you how to use Phusion Passenger as your Rails-friendly web server. Passenger is easy to install, configure, and maintain and it can be used with Nginx or Apache. In this tutorial, we will install Passenger with Nginx on Ubuntu 14.04.

An alternate method to deploy your Rails app is with this 1-Click Rails Installation that uses Nginx withUnicorn, a HTTP server that can handle multiple requests concurrently.

By the end of this tutorial, you will have a test Rails application deployed on your Passenger/Nginx web server and accessible via a domain or IP address.

Step One — Create Your Droplet

Create a new Ubuntu 14.04 Droplet. For smaller sites, it is enough to take the 512 MB plan.

Droplet size

You may want to choose the 32-bit Ubuntu image because of smaller memory consumption (64-bit programs use about 50% more memory then their 32-bit counterparts). However, if you need a bigger machine or there is a chance that you will upgrade to more than 4 GB of RAM, you should choose the 64-bit version.

Droplet image

Step Two — Add a Sudo User

After the Droplet is created, additional system administration work is needed. You should create a system user and secure the server.

Follow the Initial Server Setup article.

In this tutorial, you should create a basic user with sudo privileges. We will use the rails user in this example. If your user has another name, make sure that you use correct paths in the next steps.

Step Three (Optional) — Set Up Your Domain

In order to ensure that your site will be up and visible, you need to set up your DNS records to point your domain name towards your new server. You can find more information on setting up a hostname by following the link.

However, this step is optional, since you can access your site via an IP address.

Step Four — Install Ruby

We will install Ruby manually from source.

Before we do anything else, we should run an update to make sure that all of the packages we want to install are up to date:

sudo apt-get update

Next, install some dependencies. This should make the installation as smooth as possible:

sudo apt-get install build-essential libssl-dev libyaml-dev libreadline-dev openssl curl git-core zlib1g-dev bison libxml2-dev libxslt1-dev libcurl4-openssl-dev nodejs libsqlite3-dev sqlite3

Create a temporary folder for the Ruby source files:

mkdir ~/ruby

Move to the new folder:

cd ~/ruby

Download the latest stable Ruby source code. At the time of this writing, this is version 2.1.3. You can get the current latest version from the Download Ruby website. If a newer version is available, you will need to replace the link in the following command:

wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.3.tar.gz

Decompress the downloaded file:

tar -xzf ruby-2.1.3.tar.gz

Select the extracted directory:

cd ruby-2.1.3

Run the configure script. This will take some time as it checks for dependencies and creates a newMakefile, which will contain steps that need to be taken to compile the code:

./configure

Run the make utility which will use the Makefile to build the executable program. This step can take a bit longer:

make

Now, run the same command with the install parameter. It will try to copy the compiled binaries to the/usr/local/bin folder. This step requires root access to write to this directory. It will also take a bit of time:

sudo make install

Ruby should now be installed on the system. We can check it with the following command, which should print the Ruby version:

ruby -v

Finally, we can delete the temporary folder:

rm -rf ~/ruby

Step Five — Install Passenger and Nginx

The preferred method to install Passenger in the past was using a generic installation via RubyGems (passenger-install-nginx-module).

However, you can now install Passenger on Ubuntu with the Advanced Packaging Tool (APT), which is what we’ll be using. In this manner, the installation and — even more importantly — the update process for Passenger with Nginx, is really simple.

First, install a PGP key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7

Create an APT source file (you will need sudo privileges):

sudo nano /etc/apt/sources.list.d/passenger.list

And insert the following line in the file:

deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main

Press CTRL+x to exit, type y to save the file, and then press ENTER to confirm the file location.

Change the owner and permissions for this file:

sudo chown root: /etc/apt/sources.list.d/passenger.list
sudo chmod 600 /etc/apt/sources.list.d/passenger.list

Update the APT cache:

sudo apt-get update

Finally, install Passenger with Nginx:

sudo apt-get install nginx-extras passenger

This step will overwrite our Ruby version to an older one. To resolve this, simply remove the incorrect Ruby location and create a new symlink to the correct Ruby binary file:

sudo rm /usr/bin/ruby
sudo ln -s /usr/local/bin/ruby /usr/bin/ruby

Step Six — Set Up The Web Server

Open the Nginx configuration file:

sudo nano /etc/nginx/nginx.conf

Find the following lines, in the http block:

# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/ruby;

Uncomment both of them. Update the path in the passenger_ruby line. They should look like this:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/local/bin/ruby;

Save and exit the file.

Step Seven — Deploy

At this point you can deploy your own Rails application if you have one ready. If you want to deploy an existing app, you can upload your project to the server and skip to the /etc/nginx/sites-available/defaultstep.

For this tutorial, we will create a new Rails app directly on the Droplet. We will need a the rails gem to create the new app.

Move to your user’s home directory (otherwise, you will get the error No such file or directory - getcwd) –

cd ~

Install the rails gem (without extra documentation to install it faster). This will still take a few minutes:

sudo gem install --no-rdoc --no-ri rails

Now we can create a new app. In our example, we will use the name testapp. If you want to use another name, make sure you use correct paths. We will skip the Bundler installation because we want to run it manually later.

rails new testapp --skip-bundle

Enter the directory:

cd testapp

Now we need to install a JavaScript execution environment. It can be installed as the therubyracer gem. To install it, open the Gemfile:

nano Gemfile

Find the following line:

# gem 'therubyracer',  platforms: :ruby

And uncomment it:

gem 'therubyracer',  platforms: :ruby

Save the file, and run Bundler:

bundle install

We need to disable the default Nginx configuration. Open the Nginx config file:

sudo nano /etc/nginx/sites-available/default

Find the lines:

listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

Comment them out, like this:

# listen 80 default_server;
# listen [::]:80 default_server ipv6only=on;

Save the file.

Now, create an Nginx configuration file for our app:

sudo nano /etc/nginx/sites-available/testapp

Add the following server block. The settings are explained below.

server {
  listen 80 default_server;
  server_name www.mydomain.com;
  passenger_enabled on;
  passenger_app_env development;
  root /home/rails/testapp/public;
}

In this file, we enable listening on port 80, set your domain name, enable Passenger, and set the root to the public directory of our new project. The root line is the one you’ll want to edit to match the upload location of your Rails app.

If you don’t want to assign your domain to this app, you can skip the server_name line, or use your IP address.

To test our setup, we want to see the Rails Welcome aboard page. However, this works only if the application is started in the development environment. Passenger starts the application in the production environment by default, so we need to change this with the passenger_app_env option. If your app is ready for production you’ll want to leave this setting out.

Save the file (CTRL+x, y, ENTER).

Create a symlink for it:

sudo ln -s /etc/nginx/sites-available/testapp /etc/nginx/sites-enabled/testapp

Restart Nginx:

sudo nginx -s reload

Now your app’s website should be accessible. Navigate to your Droplet’s domain or IP address:

http://droplet_ip_address

And verify the result:

Test page

You should see the Rails test app live on your server.

Step Eight — Update Regularly

To update Ruby, you will need to compile the latest version as shown in Step Four in this tutorial.

To update Passenger with Nginx, you will need to run a basic system update:

sudo apt-get update && sudo apt-get upgrade

However, if there is a new system Ruby version available, it will probably overwrite our Ruby (installed from source). For this reason, you might need to re-run the commands for removing the existing version of Ruby and creating a new symlink to the Ruby binary file. They are listed at the end of Step Five in this tutorial.

After the update process, you will need to restart the web server:

sudo service nginx restart

git 서버 종류

찾아보는것은 전부 정리할것!!

  1.  gitlab-ce
    • all-in-one 설치는 간편하게 됨.
    • 완전 패키지 형태라 사용중인 웹서버에 끼워넣기가 쉽지 않다.
    • 저사양에서 돌리면 많이 느림.
    • 시간투자가 좀 필요할듯 함.
  2. http://gitblit.com/ <== 자바기반이라 설치가 간단할듯. 속도는 체크필요.

rtsp relay 서버 정리

relay server 정리중…

http://www.live555.com/liveMedia/
=> 사용 예 : https://emtunc.org/blog/02/2016/setting-rtsp-relay-live555-proxy/
컴파일 : http://dg087.tistory.com/67 , http://blog.mmone.de/2013/06/building-the-live555-streaming-media-framwork-on-windows-with-visual-studio-2012/
내 PC에서는 : C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include\ntwin32.mak , win32.mak 를 복사함.

https://github.com/alessandrod/gst-rtsp-relay

https://sourceforge.net/projects/rtsp/ => Linux & Windows