Ansible Semaphore安装

342 阅读5分钟

基础环境:

  • Ubuntu:22.04(在VirtualBox)
  • Ansible:2.10.8
  • Git:2.34.1

1、安装Mysql8.0

安装

sudo apt-get install mysql-server

进入mysql

sudo mysql -uroot

修改密码:

mysql> alter user'root'@'localhost' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> create user semaphore@'%' identified by 'semaphore';
Query OK, 0 rows affected (0.10 sec)

mysql> GRANT ALL PRIVILEGES ON semaphore.* TO 'semaphore'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

修改配置文件允许所有人访问:

# 注释掉
# bing 127.0.0.1

重启

sudo service mysqld restart

2、下载安装文件

下载最新版本“semaphore_2.8.77_linux_amd64.deb ”

安装:

sudo dpkg -i semaphore_2.8.77_linux_amd64.deb 

初始化:

semaphore setup

输出内容,需要进行互动添加:

Hello! You will now be guided through a setup to:

1. Set up configuration for a MySQL/MariaDB database
2. Set up a path for your playbooks (auto-created)
3. Run database Migrations
4. Set up initial semaphore user & password

What database to use:
   1 - MySQL
   2 - BoltDB
   3 - PostgreSQL
 (default 1): 1

db Hostname (default 127.0.0.1:3306): 

db User (default root): root

db Password: 123456

db Name (default semaphore): 

Playbook path (default /tmp/semaphore): 

Web root URL (optional, see https://github.com/ansible-semaphore/semaphore/wiki/Web-root-URL): 

Enable email alerts? (yes/no) (default no): zhuchenghai@neusoft.com

Enable telegram alerts? (yes/no) (default no): 

Enable slack alerts? (yes/no) (default no): 

Enable LDAP authentication? (yes/no) (default no): 

Config output directory (default /home/zch): 

Running: mkdir -p /home/zch..
Configuration written to /home/zch/config.json..
 Pinging db..
Running db Migrations..
Executing migration v0.0.0 (at 2023-03-07 09:04:15.551604304 +0800 CST m=+137.879746196)...
Creating migrations table
 [12/0]8]
Executing migration v1.0.0 (at 2023-03-07 09:04:17.37430872 +0800 CST m=+139.702450617)...
 [4/87]
Executing migration v1.2.0 (at 2023-03-07 09:04:17.666222963 +0800 CST m=+139.994364856)...
 [2/0]6]
Executing migration v1.3.0 (at 2023-03-07 09:04:17.837159606 +0800 CST m=+140.165301501)...
 [4/0]]
Executing migration v1.4.0 (at 2023-03-07 09:04:18.040105846 +0800 CST m=+140.368247741)...
 [5/0]]]
Executing migration v1.5.0 (at 2023-03-07 09:04:18.304209175 +0800 CST m=+140.632351068)...
 [4/0]]]
Executing migration v1.6.0 (at 2023-03-07 09:04:18.64115041 +0800 CST m=+140.969292306)...
 [5/0]]
Executing migration v1.7.0 (at 2023-03-07 09:04:18.976090927 +0800 CST m=+141.304232819)...
 [2/0]]
Executing migration v1.8.0 (at 2023-03-07 09:04:19.175021001 +0800 CST m=+141.503162896)...
 [2/0]]
Executing migration v1.9.0 (at 2023-03-07 09:04:19.306155187 +0800 CST m=+141.634297082)...
 [2/0]]
Executing migration v2.2.1 (at 2023-03-07 09:04:19.424102636 +0800 CST m=+141.752244533)...
 [5/0]]]
Executing migration v2.3.0 (at 2023-03-07 09:04:19.714943602 +0800 CST m=+142.043085494)...
 [4/0]]
Executing migration v2.3.1 (at 2023-03-07 09:04:20.412687764 +0800 CST m=+142.740829660)...
 [7/0]]]
Executing migration v2.3.2 (at 2023-03-07 09:04:21.453706344 +0800 CST m=+143.781848239)...
 [6/0]]]
Executing migration v2.4.0 (at 2023-03-07 09:04:21.800613479 +0800 CST m=+144.128755375)...
 [2/0]]
Executing migration v2.5.0 (at 2023-03-07 09:04:22.025743742 +0800 CST m=+144.353885637)...
 [2/0]]
Executing migration v2.5.2 (at 2023-03-07 09:04:22.163617883 +0800 CST m=+144.491759780)...
 [2/0]]
Executing migration v2.7.1 (at 2023-03-07 09:04:22.292732357 +0800 CST m=+144.620874250)...
 [2/0]]
Executing migration v2.7.4 (at 2023-03-07 09:04:22.422672566 +0800 CST m=+144.750814457)...
 [2/0]]
Executing migration v2.7.6 (at 2023-03-07 09:04:22.548968119 +0800 CST m=+144.877110016)...
 [2/0]6]
Executing migration v2.7.8 (at 2023-03-07 09:04:22.712267425 +0800 CST m=+145.040409316)...
 [4/57]
Executing migration v2.7.9 (at 2023-03-07 09:04:23.260518096 +0800 CST m=+145.588659989)...
 [2/77]
Executing migration v2.7.10 (at 2023-03-07 09:04:23.549987792 +0800 CST m=+145.878129684)...
 [1/43]
Executing migration v2.7.12 (at 2023-03-07 09:04:23.776819865 +0800 CST m=+146.104961760)...
 [3/0]]
Executing migration v2.7.13 (at 2023-03-07 09:04:24.053429526 +0800 CST m=+146.381571418)...
 [3/0]2]
Executing migration v2.8.0 (at 2023-03-07 09:04:24.268320247 +0800 CST m=+146.596462139)...
 [8/0]]
Executing migration v2.8.1 (at 2023-03-07 09:04:24.850764623 +0800 CST m=+147.178906514)...
 [1/63]
Executing migration v2.8.7 (at 2023-03-07 09:04:25.051188397 +0800 CST m=+147.379330290)...
 [1/43]
Executing migration v2.8.8 (at 2023-03-07 09:04:25.170439252 +0800 CST m=+147.498581144)...
 [2/98]]
Executing migration v2.8.20 (at 2023-03-07 09:04:25.417266131 +0800 CST m=+147.745408023)...
 [3/0]9]
Executing migration v2.8.25 (at 2023-03-07 09:04:25.611593617 +0800 CST m=+147.939735509)...
 [5/0]]]
Executing migration v2.8.26 (at 2023-03-07 09:04:25.922152136 +0800 CST m=+148.250294033)...
 [2/0]]
Executing migration v2.8.36 (at 2023-03-07 09:04:26.108523584 +0800 CST m=+148.436665477)...
 [4/0]]
Executing migration v2.8.38 (at 2023-03-07 09:04:26.436836441 +0800 CST m=+148.764978337)...
 [9/0]]]
Executing migration v2.8.39 (at 2023-03-07 09:04:26.86694142 +0800 CST m=+149.195083315)...
 [8/0]]]
Executing migration v2.8.40 (at 2023-03-07 09:04:27.651169989 +0800 CST m=+149.979311886)...
 [7/0]]
Executing migration v2.8.42 (at 2023-03-07 09:04:28.264338455 +0800 CST m=+150.592480353)...
 [1/26]
Executing migration v2.8.51 (at 2023-03-07 09:04:28.356317581 +0800 CST m=+150.684459473)...
 [3/0]]
Executing migration v2.8.57 (at 2023-03-07 09:04:28.55042064 +0800 CST m=+150.878562536)...
 [3/0]]
Executing migration v2.8.58 (at 2023-03-07 09:04:28.882671374 +0800 CST m=+151.210813265)...
 [1/57]
Migrations Finished


 > Username: zhuchenghai
 > Email: zhuchenghai@neusoft.com
WARN[0171] no rows in result set                         level=Warn
 > Your name: zhuchenghai
 > Password: 123456

 You are all setup zhuchenghai!
 Re-launch this program pointing to the configuration file

./semaphore server --config /home/zch/config.json

 To run as daemon:

nohup ./semaphore server --config /home/zch/config.json &

 You can login with zhuchenghai@neusoft.com or zhuchenghai.

3、启动

根据安装好之后的提示语句进行启动

cd /usr/bin/
nohup ./semaphore server --config /home/zch/config.json &

查看服务是否启动:

zch@zch-VirtualBox:~$ cat nohup.out 
Error: unknown command "/tmp/semaphore/semaphore_config.json" for "semaphore"
Run 'semaphore --help' for usage.
unknown command "/tmp/semaphore/semaphore_config.json" for "semaphore"
Error: unknown command "/tmp/semaphore/semaphore_config.json" for "semaphore"
Run 'semaphore --help' for usage.
unknown command "/tmp/semaphore/semaphore_config.json" for "semaphore"
MySQL root@127.0.0.1:3306 semaphore
Tmp Path (projects home) /tmp/semaphore
Semaphore v2.8.77
Interface 
Port :3000
Server is running

可以看到“Server is running”

4、登录:

网址应该是:http://localhost:3000,用户名密码是在初始化时设置的

5、变成服务

这里正对的是Ubuntu系统,在通过deb安装好之后,查看程序所在位置:

user@user-D830MT:~$ whereis semaphore
semaphore: /usr/bin/semaphore /usr/include/semaphore.h

注册服务:

sudo cat > /etc/systemd/system/semaphore.service <<EOF
[Unit]
Description=Semaphore Server
Documentation=https://github.com/semaphoreui/semaphore
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecReload=/bin/kill -HUP \$MAINPID
ExecStart=/usr/bin/semaphore server --config=/home/user/config.json
SyslogIdentifier=semaphore
Restart=always
RestartSec=10s

[Install]
WantedBy=multi-user.target
EOF

其中几点:

  • ExecStart:是根据whereis的出的位置,config.json是根据自己实际的位置

重新加载服务配置

# 重新加载配置
sudo systemctl daemon-reload  
# 启动服务
sudo systemctl start semaphore
# 查看服务
sudo systemctl status semaphore

设置为开机自动启动:

sudo systemctl enable semaphore

6、更新服务

6.1 下载新的安装包

GitHub下载路径

在路径下下载对应的版本,ubuntu 64为要用:semaphore_2.9.112_linux_amd64.deb

6.2 安装

sudo dpkg -i semaphore_2.9.112_linux_amd64.deb

6.3 重新启动服务

# 启动服务
sudo systemctl restart semaphore
# 查看服务
sudo systemctl status semaphore