AWS cloud9 でディスク容量がいっぱいになったとき

updated: 2020/6/3

 

#1 インスタンスから不要なファイルを削除する 

 

残存容量の確認

$ df /boot

 

定期的に不要なファイルを削除するコマンド

sudo apt-get autoremove を実行

 

以下のコマンドで比較的使用量の大きいディレクトリを確認できる

du -h -t 50M

 参考:

munibus.hatenablog.com

kisk0419.hatenablog.com

 

root ディレクトリに移動

cd //

 

最近更新したファイルを調べる

find . -type f -mmin -10

 

大きいファイルを調べる

du -h -t 50m

 

 ファイルの削除

sudo rm -rv FILENAME

 

参考:

Linuxコマンド集 - 【 rm 】 ファイルやディレクトリを削除する:ITpro

 

npm キャッシュのクリアー

npm cache clean or npm cache verify

 

composer キャッシュのクリアー

composer clear-cache

 

apacheアクセスログ、エラーログを消去

 cd /home/ubuntu/lib/apache2/log

sudo rm access.log

sudo rm error.log

sudo touch access.log

sudo touch error.log

 

 

#2 インスタンスのディスク容量自体を増やす

AWSコンソールのEC2を開く。

Elastic Block Store >>> ボリュームページを開く。

cloud9で使用しているボリュームにチェックを入れて上部コマンドバーのアクションからボリュームの変更⇒ボリュームの上限を増やす。

>>> 数分後自動で容量が増えますが反映されない場合あり。

>>> パーティションが12gまでしか割り当てられていないため拡張する必要あり。

 

ディスク容量の確認

f:id:monteecristoo:20191028233006p:plain

>>> /dev/xvda1が満容量

 

パーティションの割り当ての確認

f:id:monteecristoo:20191028233148p:plain

>>> xvda1のパーティションが12GB

 

パーティションの拡張

f:id:monteecristoo:20191028233306p:plain

f:id:monteecristoo:20191028233338p:plain

 

容量の拡張

f:id:monteecristoo:20191028234924p:plain

ref:

https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html

 

 

 

Laravel mail notification with pusher and mailtrap

Laravel で pusher を使った notification を受けて mailtrap 経由で通知メールを送る。

monteecristoo.hatenablog.com

上記の続き

@.env mailtrap のアカウント情報を記入

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=YOUR MAILTRAP USER NAME
MAIL_PASSWORD=YOUR MAILTRAP PASSWORD
MAIL_ENCRYPTION=null

 

@notification/NewFriendRequest.php

notification イベントに mail を追加

mail 本文の設定

public function via($notifiable)
{
return ['mail''broadcast', 'database'];
}

public function toMail($notifiable)
{
return (new MailMessage)
->line('You received a new frined request from' . $this->user->name )
->action('View profile', route('profile', ['user_id'=> $this->user->id ]))
->line('Thank you for using our application!');
}

f:id:monteecristoo:20171027210742j:plain

上記のような通知メールが発行される。

 

Noty installation with Laravel + Vue.js App

npm install noty --save

 

@resources/assets/js/bootstrap.js

window.noty = require('noty');

 

@app.blade.php

<script>

@if(Session::has('success'))

  new noty({
    type: 'success',
    layout: 'bottomLeft',
    text: '{{ Session::get('success') }}'
  });
@endif
</script>

-------------------------------------------------------------------------------------kati#8

 

noty/lib/noty.css を別個読み込ませる

参考:

laracasts.com

Laravel Echo を使ってnotification の実装 with Pusher

Laravel Echo : A JavaScript library that makes it painless to subscribe to channels and listen for events broadcast by Laravel. 

 

Installation

composer require pusher/pusher-php-server "~3.0"

参考:

laravel.com

Problem 1
- Installation request for pusher/pusher-php-server ~3.0 -> satisfiable by pusher/pusher-php-server[3.0.0].
- pusher/pusher-php-server 3.0.0 requires ext-curl * -> the requested PHP extension curl is missing from your system.

ここでエラーが出たら → sudo apt-get update

                                         sudo apt-get install php7.1-curl

curl インストール後、apacheを再起動

npm install --save laravel-echo pusher-js

 

Laravel Echo setting up

@resources/assets/js/bootstrap.js から以下をコメントアウトから外す

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'your-pusher-key',
cluster: 'your-cluster' });

your-pusher-key, your-cluster に pusher アカウント情報を挿入

@config/app.php から以下をコメントアウトから外す

/*
* Application Service Providers...
*/

App\Providers\BroadcastServiceProvider::class,

 

Create a migration for the notifications table

php artisan notifications:table

php artisan migrate

 

 Create a new notification class

php artisan make:notification NewFriendRequest

 

Pusher setting up

Pusher の Your App/Overview ページの下部にある app_id, key, secret, cluster を記入

@config/broadcasting.php

'connections' => [

'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap1',
'encrypted' => true
],
],

@.env

BROADCAST_DRIVER=pusher  // Kati#25

 

PUSHER_APP_ID=

PUSHER_APP_KEY=

PUSHER_APP_SECRET=

 --------------------------------------------------------------------------------------------------------kati#21

Notification setting up @notification/NewFriendRequest.php

public $user;

/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}

-> User::find($id)->notify(new \App\Notifications\NewFriendRequest(Auth::user()) from FriendshipController

------------------------------------------------------------------------------------------------------------

via method that determines on which channels the notification will be delivered. Out of the box, notifications may be sent on the maildatabasebroadcastnexmo, and slack channels.

 

public function via($notifiable)
{
return ['broadcast', 'database'];
}

 ----------------------------------------------------------------------------------------------------------------

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/

public function toMail($notifiable)
{
return (new MailMessage)
->line('You received a new frined request from' . $this->user->name )
->action('View profile', route('profile', ['user-id'=> $this->user->id ]))
->line('Thank you for using our application!');
}

----------------------------------------------------------------------------------------------------------------

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'name' => $tihs->user->name,
'message' => $this->user->name . 'sent you a friend request.'
];
}

----------------------------------------------------------------------------------------------------------------

Sending Notification

@FriendshipsController.php

public function add_friend($id)
{
//sending notifications, emails, broadcasting.
  $resp = Auth::user()->add_friend($id);
  User::find($id)->notify(new \App\Notifications\NewFriendRequest(Auth::user()) );
  return $resp;
}

notification を Auth user から $id に送る。

 ------------------------------------------------------------------------------------------------------kati#23

参考:

laravel.com

Frontend setting up (private channel へ接続するためにAuth id を passing)

.notification 以降: サーバーから受けた notification を handling

@Notification.vue

<template>
<div>

</div>
</template>

<script>
export default {
mounted() {
this.listen();
},
props: ['id'],
methods: {
  listen() {
    Echo.private('App.User.' + id)
      .notification( (notification) => {
        alert('New Notification');
        console.log(notification);
    })
  }
}
}
</script>

 

親 component から props を notification.vue へ passing 

@app.blade.php

@yield('content')
@if(Auth::check())
  <notification :id="{{ Auth::id() }}"></notification>
@endif

 

console にログ出し

@resources/assets/js/bootstrap.js

Pusher.log = function(message)
{
window.console.log(message)
}

上記を追記

 

接続の確認

f:id:monteecristoo:20171018203145j:plain

 Pusher 側からリクエス

f:id:monteecristoo:20171018222413j:plain

Send event 後、Event sent successfully.  と表示され、

f:id:monteecristoo:20171018223106j:plain 

------------------------------------------------------------------------------------------------------kati#24

別のユーザーが接続された状態で friend request を受けるとコンソールに下記が表示

 

f:id:monteecristoo:20171026222800j:plain

 

------------------------------------------------------------------------------------------------------kati#25