iT邦幫忙

2024 iThome 鐵人賽

DAY 17
0

韭菜系列寫到第十七篇,發現要做的事情還很多⋯,所以接下來要把前面開發好的程式碼,放到一個地方一直跑。
基於目前還在開發階段,所以我選擇使用一台虛擬主機來進行我們實驗。

EC2 / Ubuntu Server 安裝套件

  1. 連線進去之前要先在 EC2 console 選用機種(instance type)和作業系統
  2. 下載連線用的金鑰 (.pem) 並且改寫權限為 chmod 400 xxx.pem
  3. 配置 EIP 並修改 security group 允許自己的 IP 走 port 22 連入
  4. 用指令連線 ssh -i 金鑰名稱.pem ubuntu@xxx.xxx.xxx.43
  5. 更新套件清單
sudo apt-get update
  1. 安裝 git
sudo apt-get install git
  1. 安裝 python 執行環境與套件 / pyenv / 參考 https://github.com/pyenv/pyenv?tab=readme-ov-file#automatic-installer
  • 自動安裝腳本下載並觸發
curl https://pyenv.run | bash
  • 輸出結果
ubuntu@ip-172-31-132-147:~$ curl https://pyenv.run | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   270  100   270    0     0   1254      0 --:--:-- --:--:-- --:--:--  1250
Cloning into '/home/ubuntu/.pyenv'...
remote: Enumerating objects: 1284, done.
remote: Counting objects: 100% (1284/1284), done.
remote: Compressing objects: 100% (708/708), done.
remote: Total 1284 (delta 757), reused 744 (delta 443), pack-reused 0 (from 0)
Receiving objects: 100% (1284/1284), 635.05 KiB | 2.62 MiB/s, done.
Resolving deltas: 100% (757/757), done.
Cloning into '/home/ubuntu/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (11/11), 38.72 KiB | 38.72 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/ubuntu/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/ubuntu/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (56/56), done.
remote: Total 64 (delta 10), reused 25 (delta 1), pack-reused 0 (from 0)
Receiving objects: 100% (64/64), 42.89 KiB | 1.26 MiB/s, done.
Resolving deltas: 100% (10/10), done.

WARNING: seems you still have not added 'pyenv' to the load path.

# Load pyenv automatically by appending
# the following to
# ~/.bash_profile if it exists, otherwise ~/.profile (for login shells)
# and ~/.bashrc (for interactive shells) :

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# Restart your shell for the changes to take effect.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"
  • 有警告提示 pyenv 還需要夾到 load path
  • 然後還需要加一行到 ~./bashrc
  1. 安裝 redis / 參考 https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/install-redis-on-linux/
sudo apt update
sudo apt install redis-tools # for redis-cli
sudo snap install redis
  • 輸出
ubuntu@ip-172-31-132-147:~$ sudo apt install redis-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libatomic1 libjemalloc2 liblzf1
Suggested packages:
  ruby-redis
The following NEW packages will be installed:
  libatomic1 libjemalloc2 liblzf1 redis-tools
0 upgraded, 4 newly installed, 0 to remove and 20 not upgraded.
Need to get 1440 kB of archives.
After this operation, 7418 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu noble/main amd64 libatomic1 amd64 14-20240412-0ubuntu1 [10.4 kB]
Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu noble/universe amd64 libjemalloc2 amd64 5.3.0-2build1 [256 kB]
Get:3 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu noble/universe amd64 liblzf1 amd64 3.6-4 [7624 B]
Get:4 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu noble/universe amd64 redis-tools amd64 5:7.0.15-1build2 [1165 kB]
Fetched 1440 kB in 1s (1365 kB/s)
Selecting previously unselected package libatomic1:amd64.
(Reading database ... 104525 files and directories currently installed.)
Preparing to unpack .../libatomic1_14-20240412-0ubuntu1_amd64.deb ...
Unpacking libatomic1:amd64 (14-20240412-0ubuntu1) ...
Selecting previously unselected package libjemalloc2:amd64.
Preparing to unpack .../libjemalloc2_5.3.0-2build1_amd64.deb ...
Unpacking libjemalloc2:amd64 (5.3.0-2build1) ...
Selecting previously unselected package liblzf1:amd64.
Preparing to unpack .../liblzf1_3.6-4_amd64.deb ...
Unpacking liblzf1:amd64 (3.6-4) ...
Selecting previously unselected package redis-tools.
Preparing to unpack .../redis-tools_5%3a7.0.15-1build2_amd64.deb ...
Unpacking redis-tools (5:7.0.15-1build2) ...
Setting up libjemalloc2:amd64 (5.3.0-2build1) ...
Setting up liblzf1:amd64 (3.6-4) ...
Setting up libatomic1:amd64 (14-20240412-0ubuntu1) ...
Setting up redis-tools (5:7.0.15-1build2) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for libc-bin (2.39-0ubuntu8.3) ...
Scanning processes...
Scanning candidates...
Scanning linux images...

Pending kernel upgrade!
Running kernel version:
  6.8.0-1012-aws
Diagnostics:
  The currently running kernel version is not the expected kernel version 6.8.0-1016-aws.

Restarting the system to load the new kernel will not be handled automatically, so you should consider rebooting.

Restarting services...

Service restarts being deferred:
 systemctl restart networkd-dispatcher.service
 systemctl restart unattended-upgrades.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
  • 透過下列指令繼續安裝
sudo snap install redis
  • 完成後以 redis-cli 指令測試 Redis 服務有沒有起來;如果有,就可以用 Ctrl+C 離開
ubuntu@ip-172-31-132-147:~$ redis-cli
127.0.0.1:6379>
  1. 安裝 aws cli / 參考 https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
  • 第一次安裝 / 注意:常常會因為沒有安裝 unzip 導致指令整串貼上失敗在第二行指令
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
  • 補安裝 unzip
  • 再次把剛剛失敗的安裝執行完
unzip awscliv2.zip
sudo ./aws/install
  • 測試指令是否正確
ubuntu@ip-172-31-132-147:~$ sudo ./aws/install
You can now run: /usr/local/bin/aws --version
ubuntu@ip-172-31-132-147:~$ /usr/local/bin/aws --version
aws-cli/2.17.62 Python/3.12.6 Linux/6.8.0-1012-aws exe/x86_64.ubuntu.24

優化程式碼

  • 稍後更新在 github

結論

  • 明天放颱風假
  • 中東又在不安分了
  • 製造業 PMI 數值略差於預期
  • 綜合以上三點,現在台指期夜盤跌了五百點!!
  • 持續與期指奮戰~~

上一篇
【Day 16】 選擇權的定價公式 / 本日盈虧
下一篇
【Day 18】 說好的監控行情警報 / AWS SNS for mobile phone
系列文
從一萬元開始交易:收割韭菜三十天,量化交易工具製作32
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言