ubuntu16.04安装stackstorm

  1. 安装MongoDB、RabbitMQ和PostgreSQL
    注:由于目前stackstorm3只支持MongoDB3.4版本
sudo apt-get update
sudo apt-get install -y gnupg-curl
sudo apt-get install -y curl

# Add key and repo for the latest stable MongoDB (3.4)
wget -qO - https://www.mongodb.org/static/pgp/server-3.4.asc | sudo apt-key add -
sudo sh -c "cat < /etc/apt/sources.list.d/mongodb-org-3.4.list
deb http://repo.mongodb.org/apt/ubuntu $(lsb_release -c | awk '{print $2}')/mongodb-org/3.4 multiverse
EOT"
sudo apt-get update

sudo apt-get install -y crudini
sudo apt-get install -y mongodb-org
sudo apt-get install -y rabbitmq-server
sudo apt-get install -y postgresql

将MongoDB设置为开机自启动:

sudo systemctl enable mongod
sudo systemctl start mongod

2.设置存储库
以下脚本将检测您的平台和体系结构,并设置适当的StackStorm存储库。它还将添加用于软件包签名的GPG密钥。

curl -s https://packagecloud.io/install/repositories/StackStorm/stable/script.deb.sh | sudo bash

3.安装stackstorm组件

sudo apt-get install -y st2 st2mistral
注:由于stacktorm的仓库在国外,所以有时候,下载速度会非常慢,这个时候重新apt-get update一下,速度会变高一点

4.设置数据存储区加密

DATASTORE_ENCRYPTION_KEYS_DIRECTORY="/etc/st2/keys"
DATASTORE_ENCRYPTION_KEY_PATH="${DATASTORE_ENCRYPTION_KEYS_DIRECTORY}/datastore_key.json"

sudo mkdir -p ${DATASTORE_ENCRYPTION_KEYS_DIRECTORY}
sudo st2-generate-symmetric-crypto-key --key-path ${DATASTORE_ENCRYPTION_KEY_PATH}

# 确保只有st2用户可以访问该文件
sudo chgrp st2 ${DATASTORE_ENCRYPTION_KEYS_DIRECTORY}
sudo chmod o-r ${DATASTORE_ENCRYPTION_KEYS_DIRECTORY}
sudo chgrp st2 ${DATASTORE_ENCRYPTION_KEY_PATH}
sudo chmod o-r ${DATASTORE_ENCRYPTION_KEY_PATH}

# 配置文件中提那家该文件的路径
sudo crudini --set /etc/st2/st2.conf keyvalue encryption_key_path ${DATASTORE_ENCRYPTION_KEY_PATH}

sudo st2ctl restart-component st2api

5.设置Mistral数据库

# 在postgreSQl中创建mistral数据库
cat << EHD | sudo -u postgres psql
CREATE ROLE mistral WITH CREATEDB LOGIN ENCRYPTED PASSWORD 'StackStorm';
CREATE DATABASE mistral OWNER mistral;
EHD

#创建mistral数据库的表等
/opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf upgrade head
# 注册mistral
/opt/stackstorm/mistral/bin/mistral-db-manage --config-file /etc/mistral/mistral.conf populate | grep -v -e openstack -e keystone -e ironicclient

6.配置SSH和SUDO
要运行本地和远程Shell操作,StackStorm使用一个特殊的系统用户(默认为stanley)。对于远程Linux操作,使用SSH。我们建议在所有远程主机上配置基于公钥的SSH访问。我们还建议配置SSH对本地主机的访问,以运行示例和测试。
a.创建StackStorm系统用户,启用无密码sudo,并设置对“ localhost”的ssh访问,以便可以在本地测试基于SSH的操作。您将需要提升的权限才能执行此操作:

# Create an SSH system user (default `stanley` user may already exist)
sudo useradd stanley
sudo mkdir -p /home/stanley/.ssh
sudo chmod 0700 /home/stanley/.ssh

# Generate ssh keys
sudo ssh-keygen -f /home/stanley/.ssh/stanley_rsa -P ""

# Authorize key-based access
sudo sh -c 'cat /home/stanley/.ssh/stanley_rsa.pub >> /home/stanley/.ssh/authorized_keys'
sudo chown -R stanley:stanley /home/stanley/.ssh

# Enable passwordless sudo
sudo sh -c 'echo "stanley    ALL=(ALL)       NOPASSWD: SETENV: ALL" >> /etc/sudoers.d/st2'
sudo chmod 0440 /etc/sudoers.d/st2

# Make sure `Defaults requiretty` is disabled in `/etc/sudoers`
sudo sed -i -r "s/^Defaults\s+\+?requiretty/# Defaults +requiretty/g" /etc/sudoers

b.如果您使用其他用户或他们的SSH密钥的路径,则需要在以下位置更改此部分/etc/st2/st2.conf:

[system_user]
user = stanley
ssh_key_file = /home/stanley/.ssh/stanley_rsa

c.启动服务

sudo st2ctl start#启动服务
sudo st2ctl reload#重新注册传感器,规则和动作

验证stackstorm是否安装成功:

st2 --version

st2 -h

# List the actions from a 'core' pack
st2 action list --pack=core

# Run a local shell command
st2 run core.local -- date -R

# See the execution results
st2 execution list

# Fire a remote comand via SSH (Requires passwordless SSH)
st2 run core.remote hosts='localhost' -- uname -a

# Install a pack
st2 pack install st2

7.配置身份验证
使用基于文件的提供程序设置身份验证:
使用密码创建用户:

# 安装相应安装包
sudo apt-get install -y apache2-utils
# 设置用户密码
echo '123456' | sudo htpasswd -i /etc/st2/htpasswd st2admin

启动和配置身份验证/etc/st2/st2.conf:

[auth]
# ...
enable = True
backend = flat_file
backend_kwargs = {"file_path": "/etc/st2/htpasswd"}
# ...

重新启动st2api服务:

sudo st2ctl restart-component st2api

进行身份验证,并检查其是否有效:

# 登录stackstorm,使用上面设置的密码
st2 login st2admin

# 检查stackstorm是够正常
st2 action list

8.安装WEBUI和设置SSL终止
NGINX用于提供WebUI静态文件,将HTTP重定向到HTTPS,提供SSL终止以及反向代理st2auth和st2api API端点。要设置它:安装 st2web和nginx软件包,生成证书或将您现有的证书放在下 /etc/ssl/st2,并使用StackStorm提供的站点配置文件st2.conf配置nginx 。
StackStorm取决于> = 1.7.5的Nginx版本。

# 添加密钥和nginx源
sudo apt-key adv --fetch-keys http://nginx.org/keys/nginx_signing.key
sudo sh -c "cat < /etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/ubuntu/ $(lsb_release -c | awk '{print $2}') nginx
EOT"
sudo apt-get update

# Install st2web and nginx
# note nginx should be > 1.4.6
sudo apt-get install -y st2web nginx

# Generate self-signed certificate or place your existing certificate under /etc/ssl/st2
sudo mkdir -p /etc/ssl/st2
sudo openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/st2/st2.key -out /etc/ssl/st2/st2.crt \
-days XXX -nodes -subj "/C=US/ST=California/L=Palo Alto/O=StackStorm/OU=Information \
Technology/CN=$(hostname)"

# Remove default site, if present
sudo rm /etc/nginx/conf.d/default.conf
# Copy and enable the supplied nginx config file
sudo cp /usr/share/doc/st2/conf/nginx/st2.conf /etc/nginx/conf.d/

sudo service nginx restart

注:这里需要修改http的80端口,不然会导致冲突,启动不了nginx
最后:
使用浏览器连接到https://${ST2_HOSTNAME}WebUI并登录。
ubuntu16.04安装stackstorm_第1张图片

你可能感兴趣的:(自动化运维)