Install Huginn on Ubuntu/Debian

Precautions##

Since the article contains many examples and commands that you may use, this guide will be very long.

This installation guide is based on Ubuntu/Debian and has been tested on the aforementioned systems. Please read Required Hardware and Operating System to understand the required hardware and software requirements.

This is an official guide used to guide the deployment of Huginn in a production environment. If you need to install in a development environment or want to know about other installation options, please check Start.

The following steps have been proven to be effective, please be careful when using this guide to avoid deviation, and ensure that you do not violate any of the installation environment we require. For example, many people have permission problems when running because they changed the location of the folder or used other users to run the service.

If you find any bugs or errors in this guide, please submit a pull request.

If there is no special statement, all commands will run under super user authority.

When you encounter any problems during installation, please check the [Problem Solving] (https://github.com/cantino/huginn/blob/master/doc/manual/installation.md#troubleshooting) chapter.

Overview##

The installation of Huginn requires the following parts

  1. Software package/standalone package
  2. Ruby
  3. system user
  4. database
  5. Huginn
  6. Nginx

1. Package/Independent Package##

Debian does not install sudo by default. Make sure your system is up to date and install it.

run as root! apt-get update -y apt-get upgrade -y apt-get install sudo -y

12345 # run as root! apt-get update -y apt-get upgrade -y apt-get install sudo -y

**Note: ** During the entire installation process, some files need to be modified manually. If you are familiar with vim, you can set vim as the default editor on the command line. If you are not familiar with vim, please skip this step and continue to use the default editor.

Install vim and set as default editor sudo apt-get install -y vim sudo update-alternatives --set editor /usr/bin/vim.basic

1234 # Install vim and set as default editorsudo apt-get install -y vimsudo update-alternatives --set editor /usr/bin/vim.basic

Introduce the node.js repository (Ubuntu and Debian Jessie can skip this step)

curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

|12| curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -|
|--------|--------|

Install the required packages (need to compile Ruby and local Ruby gems extensions)

sudo apt-get install -y runit build-essential git zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs graphviz

12 sudo apt-get install -y runit build-essential git zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs graphviz

2. Ruby

In the production version of Huginn, if you use a Ruby version management tool like RVM, rbenv or chruby, it will often cause problems that are difficult to diagnose. Therefore, we do not recommend using a version management program to install Ruby. We strongly recommend that you follow the steps below to use the system's own Ruby.

If there is an older version of Ruby, remove it first:

sudo apt-get remove -y ruby1.8 ruby1.9

12 sudo apt-get remove -y ruby1.8 ruby1.9

Download the new Ruby version and compile it:

mkdir /tmp/ruby && cd /tmp/ruby curl -L --progress http://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2 | tar xj cd ruby-2.3.0 ./configure --disable-install-rdoc make -jnproc sudo make install

|1234567| mkdir /tmp/ruby && cd /tmp/rubycurl -L --progress http://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.bz2 | tar xjcd ruby-2.3.0./configure --disable-install-rdocmake -jnprocsudo make install|
|--------|--------|

Install bundler and foreman with gem:

sudo gem install rake bundler foreman --no-ri --no-rdoc

12 sudo gem install rake bundler foreman --no-ri --no-rdoc

4. database##

Install the database package

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev # Pick a MySQL root password (can be anything), type it and press enter, # retype the MySQL root password and press enter

12345 sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev # Pick a MySQL root password (can be anything), type it and press enter,# retype the MySQL root password and press enter

Check the installed MySQL version (only when the version number is greater than 5.5.3 can the .env configuration file run normally)

mysql --version

12 mysql --version

Ensure installation safety

sudo mysql_secure_installation

12 sudo mysql_secure_installation

Log in to MySQL

mysql -u root -p # passwordEnter the MySQL root password

1234 mysql -u root -p # passwordEnter the MySQL root password

To create a Huginn user, do not type mysql> first, this part must be done first. After that, choose a real password and replace $password in the command line

mysql> CREATE USER 'huginn'@'localhost' IDENTIFIED BY '$password';

12 mysql> CREATE USER 'huginn'@'localhost' IDENTIFIED BY '$password';

Make sure you can use the InnoDB engine, it can guarantee a long index.

mysql> SET storage_engine=INNODB; # If this step fails, check your MySQL config file (eg /etc/mysql/*.cnf, /etc/mysql/conf.d/*) # Check the settings of innodb "innodb = off"

12345 mysql> SET storage_engine=INNODB; # If this step fails, check your MySQL config file (eg /etc/mysql/*.cnf, /etc/mysql/conf.d/*)# Check the settings of innodb "innodb = off"

Ensure that Huginn users can allow access to the database

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON huginn_production.* TO 'huginn'@'localhost';

12 mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON huginn_production.* TO 'huginn'@'localhost';

Exit the database

mysql> \q

12 mysql> \q

Try to connect to the new database with a new user

sudo -u huginn -H mysql -u huginn -p -D huginn_production # Type the password you replaced $password with earlier # Enter the real password you chose before instead of $password

12345 sudo -u huginn -H mysql -u huginn -p -D huginn_production # Type the password you replaced $password with earlier# Enter the real password you chose before instead of $password

You should now see ERROR 1049 (42000): Unknown database'huginn_production', which shows that our operation is correct. Because we will create the database later.

Now that the installation of the database is complete, you can continue with the rest of the installation.

6. Huginn

Clone from source###

We will install Huginn in the "huginn" user folder under our home file cd /home/huginn # clone from Huginn repository sudo -u huginn -H git clone https://github.com/cantino/huginn.git- b master huginn # Go to Huginn's installation directory cd /home/huginn/huginn # Copy Huginn's default configuration sudo -u huginn -H cp .env.example .env # Create log/, tmp/pids/ and tmp/ in the directory sockets/ directories sudo -u huginn mkdir -p log tmp/pids tmp/sockets # Make sure Huginn can write data to the log/ and tmp/ folders sudo chown -R huginn log/ tmp/ sudo chmod -R u+rwX, go-w log/ tmp/ # Ensure that the permissions are set correctly sudo chmod -R u+rwX,go-w log/ sudo chmod -R u+rwX tmp/ sudo -u huginn -H chmod o-rwx .env # Copy Unicorn's The default configuration file sudo -u huginn -H cp config/unicorn.rb.example config/unicorn.rb

123456789101112131415161718192021222324252627 # We will install Huginn in the "huginn" user folder under our home file cd /home/huginn # clone from Huginn repository sudo -u huginn -H git clone https://github.com/cantino/huginn.git- b master huginn # Go to Huginn's installation directory cd /home/huginn/huginn # Copy Huginn's default configuration sudo -u huginn -H cp .env.example .env # Create log/, tmp/pids/ and tmp/ in the directory sockets/ directories sudo -u huginn mkdir -p log tmp/pids tmp/sockets # Ensure that Huginn can write data to the log/ and tmp/ folders sudo chown -R huginn log/ tmp/sudo chmod -R u+rwX,go -w log/ tmp/ # Make sure the permissions are set correctly sudo chmod -R u+rwX,go-w log/sudo chmod -R u+rwX tmp/sudo -u huginn -H chmod o-rwx .env # Copy Unicorn's default Configuration file sudo -u huginn -H cp config/unicorn.rb.example config/unicorn.rb

Configuration

Update Huginn's configuration file, and then follow the instructions below to continue sudo -u huginn -H editor .env

123 # Update Huginn's configuration file, and then follow the instructions below to continue sudo -u huginn -H editor .env

If you use a local database server, the database configuration file will look like this (use the MySQL user password of Huginn you set earlier):

DATABASE_ADAPTER=mysql2 DATABASE_RECONNECT=true DATABASE_NAME=huginn_production DATABASE_POOL=20 DATABASE_USERNAME=huginn DATABASE_PASSWORD='$password' #DATABASE_HOST=your-domain-here.com #DATABASE_PORT=3306 #DATABASE_SOCKET=/tmp/mysql.sock DATABASE_ENCODING=utf8 # MySQL only: If you are running a MySQL server >=5.5.3, you should # set DATABASE_ENCODING to utf8mb4 instead of utf8 so that the # database can hold 4-byte UTF-8 characters like emoji. #DATABASE_ENCODING=utf8mb4

12345678910111213141516 DATABASE_ADAPTER=mysql2DATABASE_RECONNECT=trueDATABASE_NAME=huginn_productionDATABASE_POOL=20DATABASE_USERNAME=huginnDATABASE_PASSWORD='$password'#DATABASE_HOST=your-domain-here.com#DATABASE_PORT=3306#DATABASE_SOCKET=/tmp/mysql.sock DATABASE_ENCODING=utf8# MySQL only: If you are running a MySQL server >=5.5.3, you should# set DATABASE_ENCODING to utf8mb4 instead of utf8 so that the# database can hold 4-byte UTF-8 characters like emoji.#DATABASE_ENCODING=utf8mb4

**Note: ** The RAILS_ENV setting is annotated to ensure that Huginn is actually running in a production environment

RAILS_ENV=production

12 RAILS_ENV=production

If necessary, change the configuration file of Unicorn. In requirements.md there is a part that explains and recommends the appropriate number of unicorns.

If you have a very high number of instances to run, increase the number of workers# If your server has at least 2 GB of memory, then 2 is more than enough for most users# Reduce the number of workers to 1 sudo -u huginn -H editor config/unicorn.rb

12345 # If you have a very high number of instances to run, increase the number of workers# If your server has at least 2 GB of memory, then 2 is more than enough for most users# Reduce the number of workers to 1 sudo -u huginn -H editor config/unicorn.rb

**Note: ** Make sure you modify .env and unicorn.rb to ensure that the program runs normally

**Note: ** We recommend using HTTPS, if necessary, please visit Use HTTPS to view additional steps.

**Note: ** In order to ensure that your changes are saved, every time you complete the initial installation, you must re-import the starting script file to .env, unicorn.rb or Procfile! (For details, see Install Init Script)

Install Gems

**Note: ** In bundler 1.5.2 version, you can use bundle install -jN (N is the number of processes) to evoke multiple processes for installation, and you can also install multiple gems in a measurable time difference (fast 60%). Use nproc to check the number of your processors. For more information, see post. First, make sure your bundler >= 1.5.2 (run bundle -v), there are many issues already in version 1.5.2 fix.

sudo -u huginn -H bundle install --deployment --without development test

12 sudo -u huginn -H bundle install --deployment --without development test

Initialize the database###

Create database sudo -u huginn -H bundle exec rake db:create RAILS_ENV=production # Migrate to the latest version sudo -u huginn -H bundle exec rake db:migrate RAILS_ENV=production # Create administrator user and sample agent, and use the default admin/password login sudo -u huginn -H bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=admin SEED_PASSWORD=password

123456789 # Create database sudo -u huginn -H bundle exec rake db:create RAILS_ENV=production # Migrate to the latest version sudo -u huginn -H bundle exec rake db:migrate RAILS_ENV=production # Create administrator user and sample agent, and use the default admin/password login sudo -u huginn -H bundle exec rake db:seed RAILS_ENV=production SEED_USERNAME=admin SEED_PASSWORD=password

When finished check out See the Huginn Wiki for more Agent examples! https://github.com/cantino/huginn/wiki

**Note: ** This will create the initial user, you can change your username and password by setting SEED_USERNAME and SEED_PASSWORD in the environment variables. If you don't want to change the password (it will be set as the default password), please wait for the installation to complete and go online to the Internet, you can log in to the server to change your password.

Edit resource file###

sudo -u huginn -H bundle exec rake assets:precompile RAILS_ENV=production

12 sudo -u huginn -H bundle exec rake assets:precompile RAILS_ENV=production

Installation initial script###

Huginn uses foreman, it will migrate the initialization script according to the Procfile

Modify Procfile, and choose one of our suggested modifications to adapt to the production environment.

sudo -u huginn -H editor Procfile

12 sudo -u huginn -H editor Procfile

Comment this two lines

web: bundle exec rails server -p ${PORT-3000} -b ${IP-0.0.0.0} jobs: bundle exec rails runner bin/threaded.rb

123 web: bundle exec rails server -p ${PORT-3000} -b ${IP-0.0.0.0}jobs: bundle exec rails runner bin/threaded.rb

Use these two lines or these (ie remove the comment)

web: bundle exec unicorn -c config/unicorn.rb # jobs: bundle exec rails runner bin/threaded.rb

123 # web: bundle exec unicorn -c config/unicorn.rb# jobs: bundle exec rails runner bin/threaded.rb

Introduce the initialization script:

sudo bundle exec rake production:export

12 sudo bundle exec rake production:export

**Note: ** Every time you modify .env or Procfile, you must re-import the initialization script.

Create Logrotate

sudo cp deployment/logrotate/huginn /etc/logrotate.d/huginn

12 sudo cp deployment/logrotate/huginn /etc/logrotate.d/huginn

Make sure your Huginn instance is running

sudo bundle exec rake production:status

12 sudo bundle exec rake production:status

7. Nginx

**Note: ** Nginx is an officially recommended server for Huginn. If you don’t want to use Nginx as your server, you can move to the wiki to view the use of apache

installation###

sudo apt-get install -y nginx

12 sudo apt-get install -y nginx

Web page settings###

Copy the sample web page settings:

sudo cp deployment/nginx/huginn /etc/nginx/sites-available/huginn sudo ln -s /etc/nginx/sites-available/huginn /etc/nginx/sites-enabled/huginn

123 sudo cp deployment/nginx/huginn /etc/nginx/sites-available/huginnsudo ln -s /etc/nginx/sites-available/huginn /etc/nginx/sites-enabled/huginn

Make sure you modify the configuration file to ensure your establishment. If you run multiple nginx web pages, then remove the default_server parameter from the listen directive.

Change YOUR_SERVER_FQDN to the fully-qualified # domain name of your host serving Huginn. sudo editor /etc/nginx/sites-available/huginn

1234 # Change YOUR_SERVER_FQDN to the fully-qualified# domain name of your host serving Huginn.sudo editor /etc/nginx/sites-available/huginn

If nginx only runs a huginn service, then delete the default nginx initial webpage:

sudo rm /etc/nginx/sites-enabled/default

12 sudo rm /etc/nginx/sites-enabled/default

**Note: ** If you want to use the HTTPS we recommend, use huginn-ssl instead of huginn in the Nginx configuration file. See more details in Use HTTPS.

Test configuration file###

Use the following command to test whether your Nginx configuration file is correct:

sudo nginx -t

12 sudo nginx -t

You should see syntax is okay and test is successful. If you see an error message, check the typographical errors of huginn or huginn-ssl in your Nginx configuration file, and troubleshoot the error based on the error message.

Restart###

sudo service nginx restart

12 sudo service nginx restart

carry out#

First login###

Log in to your server address in the browser to log in to Huginn for the first time. Huginn has created a default account for you, you can use the following to log in:

admin (or your SEED_USERNAME) password (or your SEED_PASSWORD)

123 admin (or your SEED_USERNAME)password (or your SEED_PASSWORD)

**Enjoy it! ** :sparkles: :star: :fireworks:

You can use cd /home/huginn/huginn && sudo bundle exec rake production:start and cd /home/huginn/huginn && sudo bundle exec rake production:stop to start or stop your Huginn service.

Make sure you have read how to Update it after completing Huginn installation! You can also use Capistrano to ensure that your installation is always up to date.

Some advanced settings##

Use HTTPS

Use HTTPS on Huginn.

  1. In .enb

  2. Set FORCE_SSL to true.

  3. Use huginn-ssl instead of huginn configuration:

  4. sudo cp deployment/nginx/huginn-ssl /etc/nginx/sites-available/huginn

  5. Update YOUR_SERVER_FQDN

  6. Update ssl_certificate and ssl_certificate_key.

  7. Check the configuration file and consider applying other security and performance enhancement features

Restart Nginx, import the initialization script, and restart Huginn:

cd /home/huginn/huginn sudo service nginx restart sudo bundle exec rake production:export

1234 cd /home/huginn/huginnsudo service nginx restartsudo bundle exec rake production:export

The use of self-signed certificates is discouraged. If you do, you must follow the steps in the correct order before generating the certificate.

sudo mkdir -p /etc/nginx/ssl/ cd /etc/nginx/ssl/ sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out huginn.crt -keyout huginn.key sudo chmod o-r huginn.key

12345 sudo mkdir -p /etc/nginx/ssl/cd /etc/nginx/ssl/sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out huginn.crt -keyout huginn.keysudo chmod o-r huginn.key

Troubleshooting##

If you encounter problems during the installation process, please make sure you install in the correct order and do not miss any step.

When your Huginn instance is not running, run the following script to check.

cd /home/huginn/huginn sudo bundle exec rake production:check

123 cd /home/huginn/huginnsudo bundle exec rake production:check

If there are other problems, we regret to tell you that you need to check various log files to determine the error message.

Nginx error log/var/log/nginx/huginn_error.log

This file should be empty, but it is the first place you need to check. Because nginx is the first application to process the request sent to Huginn.

Common problems:

Unicorn log/home/huginn/huginn/log/unicorn.log

This should contain the entry of the HTTP request, similar to: 10.0.2.2--[18/Aug/2015:21:15:12 +0000] "GET / HTTP/1.0" 200-0.0110

If you find ruby traceback information, or other error messages below:

Rails application log /home/huginn/huginn/log/production.log

This file is very lengthy. If We're sorry, but something went wrong. appears when you use Huginn, this is a typical example of backtracking information that can help you or the developers of Huginn locate the problem.

NoMethodError (undefined method name' for nil:NilClass):`` app/controllers/jobs_controller.rb:6:in index'`` config/initializers/silence_worker_status_logger.rb:5:incall_with_silence_worker_status'`

Runit/Background process log/home/huginn/huginn/log/*/current

If one of your agents is not running correctly, these files will contain error messages or other traceback information. The easiest way to debug an agent is to look at your log files. These log files will be generated when you change or trigger the agent on the Huginn web page.

The location of these log files depends on your Procfile file. These commands will give you a list of available log files:

ls -al /home/huginn/huginn/log/*/current

When you want to observe the background process, you can easily view all changed files:

tail -f /home/huginn/huginn/log/*/current

Still have questions? ?

You may find other error messages or unexpected backtracking messages that you cannot resolve. Please create a new issue with enough information so that you can get a solution to this problem.

This article is translated by Huginn中文网 and has been authorized by the project author. For the original text, please visit Installation from source
My blog will be synced to Tencent Cloud + community, I invite everyone to join us: https://cloud.tencent.com/developer/support-plan?invite_code=9bmt0ib957kd

Recommended Posts

Install Huginn on Ubuntu/Debian
Install Docker on Centos7
install vscode on ubuntu18
Install Redis on Ubuntu
install LNMP on centos7.4
Install R4 on ubuntu20
Install Java on Centos 7
Install nvtop on Ubuntu 18.04
Install docker on Ubuntu
Nodejs install on centos7
Install Docker on ubuntu18.04
Install nodejs10 on Ubuntu16
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Install Pytorch+CUDA on Ubuntu 16.04
Install MongoDB on CentOS 7
Install rJava on Ubuntu18
Install Surelog on CentOS8
Install JDK10+ on Ubuntu
Install Python3 on Ubuntu 16.04
Openjdk install on centos7
Install Jenkins on centos7
install RabbitMQ on centos
Install RabbitMQ on CentOS 7
install Docker on centos6.5
Install Docker on Ubuntu18
Install Python3.7 on Ubuntu
install oracle on centos
Install flashplayer on Ubuntu
Install Elasticsearch 6 on centos7
Install RabbitMQ on CentOS7
Install ubuntu on virtual machine
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Install QQ robot on Ubuntu 16.04
Install ElasticSearch 7.x on CentOS 7
Install Python 3.7 on Ubuntu 18.04 LTS
Install Android Studio on Ubuntu
Install python3 on linux, keep python2
Install scrapy framework on ubuntu
Install Mysql offline on Ubuntu
Install Oracle Java8 on Ubuntu
install EPEL repo on centos
Install Odoo 11 stack on Ubuntu 16.04
Install Go locale on Ubuntu16
Install Zabbix 3.4 based on CentOS 7
install virtualbox on centos server
Install non-portable QQ on ubuntu
Install Docker on Ubuntu 18.04 offline
Install Nginx server on CentOS 7
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
Install and use dig under ubuntu/debian
Install JDK8 in rpm on CentOS7
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install Protobuf 3 on Ubuntu