2023年9月29日 星期五

在Ubuntu 22.04 建立Node.js+MangoDB的Docker伺服主機環境

 1.首先下載並執行MangoDB docker image/container

$ sudo docker pull mongodb/mongodb-community-server

[sudo] password for user:

Using default tag: latest

latest: Pulling from mongodb/mongodb-community-server

445a6a12be2b: Pull complete

58881fc31a77: Pull complete

453d60504a24: Pull complete

7a5a2fda558f: Pull complete

aeac334df843: Pull complete

ace8b63f4bfe: Pull complete

acb03ef64e24: Pull complete

0306f57a2e92: Pull complete

4f4fb700ef54: Pull complete

2486c6c8aafa: Pull complete

Digest: sha256:7a2acbbc960ae0f8f51a102067afc846f98c4d0b27f42c828b9b81ebd5dae1ba

Status: Downloaded newer image for mongodb/mongodb-community-server:latest

docker.io/mongodb/mongodb-community-server:latest


$docker run --name mongoDB -d mongodb/mongodb-community-server

Current Mongosh Log ID: 65168b44c792982a55e6c285


$ sudo docker container ls

CONTAINER ID   IMAGE                              COMMAND                  CREATED          STATUS          PORTS                                                                                                NAMES

86abc95aa40a   mongodb/mongodb-community-server   "python3 /usr/local/…"   21 seconds ago   Up 20 seconds   27017/tcp                                                                                            mongoDB

7e886aa19c1f   openproject/community:13           "./docker/prod/entry…"   7 hours ago      Up 7 hours      5432/tcp, 0.0.0.0:1689->80/tcp, :::1689->80/tcp                                                      viaProject

26b00a8d3522   portainer/portainer                "/portainer"             3 months ago     Up 8 hours      8000/tcp, 9443/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/                                     tcp   portainer


$ sudo docker exec -it mongoDB mongosh

Current Mongosh Log ID: 65168b44c792982a55e6c285

Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.1

Using MongoDB:          7.0.1

Using Mongosh:          2.0.1


For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).

You can opt-out by running the disableTelemetry() command.


------

   The server generated these startup warnings when booting

   2023-09-29T08:29:48.288+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem

   2023-09-29T08:29:49.046+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted

   2023-09-29T08:29:49.046+00:00: vm.max_map_count is too low

------


test> db.runCommand(

...    {

...       hello: 1

...    }

... )

{

  isWritablePrimary: true,

  topologyVersion: {

    processId: ObjectId("65168afcd1b0d08b46767dd1"),

    counter: Long("0")

  },

  maxBsonObjectSize: 16777216,

  maxMessageSizeBytes: 48000000,

  maxWriteBatchSize: 100000,

  localTime: ISODate("2023-09-29T08:31:13.551Z"),

  logicalSessionTimeoutMinutes: 30,

  connectionId: 3,

  minWireVersion: 0,

  maxWireVersion: 21,

  readOnly: false,

  ok: 1

}

test> exit


2.然後安裝Node.JS環境

2023年9月2日 星期六

在Ubuntu 20.04 中使用Docker環境的MySQL Server

 

1.取得MySQL映像:

  docker pull mysql/mysql-server

2.執行Docker容器:

  docker run --name=mysql-container-name -d mysql/mysql-server:latest
3.更改預設登入密碼及權限
  docker logs mysql-container-name
  docker exec -it your-mysql-container-name mysql -u root -pEnter Password: <輸入上一指令中的內容>
  mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密碼'
4.建立新的mySQL用戶連接權限:
  mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'my-connect-password'
  mysql> FLUSH PRIVILEGES;
5.使用mysql-Workbench連接/測試/設定mySQL資料庫

2023年8月6日 星期日

解決Ubuntu 20.04突然發生Anydesk無法遠端登入問題

用Anydesk登入遠端Ubuntu 20.04時,出現 Display Server not supported之類的錯誤:

需以Putty登入或至Ubuntu本機終端機操作: (以管理者權限sudo修改檔案 /etc/gdm3/custom.conf)

sudo nano /etc/gdm3/custom.conf
  1. 尋找 [daemon] 段,修改或新增這行:
  2. WaylandEnable=false


(This line disables Wayland in GDM3.)

2023年7月4日 星期二

Ubuntu Linux 限制CPU使用率

 

安裝cpulimit,使用像top找出要限制cpu使用率的PID,

進行限制設定之前,可先找出前10大耗用CPU使用率的應用程式

ps -eo pcpu,pid,user,args | tail -n +2 | sort -k1 -r -n | head -10

==========

限制設定範例:

sudo cpulimit --pid 12345 --limit 50 --background

2023年5月12日 星期五

使用DOCKER架設ASP.NET CORE伺服主機

 開發階段,架設一個乾淨的服務器測試,很方便:

Windows平台: (需Pro或ENT版本,不能Home版)

   1.安裝WLS 2 及 Linux Distro

   2.安裝Docker Desktop

   3.參考範例 https://github.com/dotnet/dotnet-docker/tree/main/samples

docker run -it --rm -p 8000:80 --name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp

    (安全起見,建議使用https連線服務)

Linux平台: 以Ubuntu為例

參考 : https://docs.docker.com/engine/install/ubuntu/

其中 docker desktop需要kvm, 安裝 deb時也要切換至root使用者


實作內容範例:

    https://github.com/dotnet/dotnet-docker/tree/main/samples/aspnetapp

    使用vs2022發行專案,或者移至csproj專案檔所在資料夾,輸入:

dotnet publish -c Release -o published 

    之後,在專案資料夾,執行以下二個指令:

docker build --pull -t myAncApp4Docker .

docker run --rm -it -p 8000:80 myAncApp4Docker

以上docker build會使用到 Dockerfile , 主要是用以下來建立runtime環境

 FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS runtime

WORKDIR /app

COPY published/ ./

ENTRYPOINT ["dotnet", "myAncApp4Docker.dll"]

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



2021年6月1日 星期二

使用vs Code建立Win/Linux跨平台GUI視窗軟體

 #install gtk# tamplate

dotnet new -i "GtkSharp.Template.CSharp"





# to see all the installed templates
dotnet new --list
 
# to create a gtksharp application based on gtkapp template
dotnet new gtkapp