Wednesday, February 24, 2021

Tuesday, February 23, 2021

Cài đặt Snipe-IT trên Ubuntu 20.04 Nginx



0. Snipe-IT là gì

Website: https://snipeitapp.com/

1. Cài đặt nginx

  • Gỡ apache2 nếu có
  • Cài nginx
root@dinguyen:~#apt update  
root@dinguyen:~#apt install nginx
root@dinguyen:~#systemctl start nginx
root@dinguyen:~#system enable nginx
root@dinguyen:~#systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-02-23 08:20:36 UTC; 6h left
       Docs: man:nginx(8)
   Main PID: 862 (nginx)
      Tasks: 3 (limit: 4586)
     Memory: 9.6M
     CGroup: /system.slice/nginx.service
             ├─862 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─863 nginx: worker process
             └─864 nginx: worker process

Feb 23 08:20:35 snipeit systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 23 08:20:36 snipeit systemd[1]: Started A high performance web server and a reverse proxy server.
root@dinguyen:~# 

2. Cài đặt mariadb

root@dinguyen:~# apt install mariadb-server mariadb-client
root@dinguyen:~#systemctl start mariadb
root@dinguyen:~#systemctl enable mariadb
root@dinguyen:~#systemctl status mariadb
root@dinguyen:~#systemctl status mariadb
● mariadb.service - MariaDB 10.3.25 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-02-23 08:20:37 UTC; 6h left
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 956 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 4586)
     Memory: 94.1M
     CGroup: /system.slice/mariadb.service
             └─956 /usr/sbin/mysqld

Feb 23 08:20:35 snipeit systemd[1]: Starting MariaDB 10.3.25 database server...
Feb 23 08:20:36 snipeit mysqld[956]: 2021-02-23  8:20:36 0 [Note] /usr/sbin/mysqld (mysqld 10.3.25-MariaDB-0ubuntu0.20.04.1) starting as process 956 ...
Feb 23 08:20:36 snipeit mysqld[956]: 2021-02-23  8:20:36 0 [Warning] Could not increase number of max_open_files to more than 16384 (request: 32184)
Feb 23 08:20:37 snipeit systemd[1]: Started MariaDB 10.3.25 database server.
Feb 23 08:20:37 snipeit /etc/mysql/debian-start[1066]: Upgrading MySQL tables if necessary.
Feb 23 08:20:37 snipeit /etc/mysql/debian-start[1070]: Looking for 'mysql' as: /usr/bin/mysql
Feb 23 08:20:37 snipeit /etc/mysql/debian-start[1070]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Feb 23 08:20:37 snipeit /etc/mysql/debian-start[1070]: This installation of MySQL is already upgraded to 10.3.25-MariaDB, use --force if you still need to run mysql_upgrade
Feb 23 08:20:37 snipeit /etc/mysql/debian-start[1081]: Checking for insecure root accounts.
Feb 23 08:20:37 snipeit /etc/mysql/debian-start[1085]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables
root@dinguyen:~
root@dinguyen:~#mysql_secure_installation
Enter current password for root (enter for none): Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

3. Tạo Snipe-IT database

root@dinguyen:~#mysql -u root -p
CREATE DATABASE snipeit;
CREATE USER 'snipeit'@'localhost' IDENTIFIED BY 'Dinguyen@2021';
GRANT ALL ON snipeit.* TO 'snipeit'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

4. Cài đặt PHP

  • Cài đăht php và các modules
root@dinguyen:~# apt install php-fpm php-common php-gmp php-curl php-intl php-mbstring php-xmlrpc php-mysql php-gd php-bcmath php-xml php-cli php-zip php-ldap
  • Set các tham số trong file php.ini
root@dinguyen:~# vi /etc/php/7.4/fpm/php.ini
file_uploads = On
allow_url_fopen = On
short_open_tag = On
cgi.fix_pathinfo = 0
memory_limit = 256M
upload_max_filesize = 100M
max_execution_time = 360
max_input_vars = 1500
date.timezone = Asia/Ho_Chi_Minh

5. Download và cài đặt Snipe-IT

root@dinguyen:~#apt install curl git
root@dinguyen:~#curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
cd /var/www/
root@dinguyen:~#git clone https://github.com/snipe/snipe-it snipeit
root@dinguyen:~#cp /var/www/snipeit/.env.example /var/www/snipeit/.env
  • Sửa file .env
root@dinguyen:~# vi /var/www/snipeit/.env
# --------------------------------------------
# REQUIRED: BASIC APP SETTINGS
# --------------------------------------------
APP_ENV=production
APP_DEBUG=false
APP_KEY=ChangeMe
APP_URL=dinguyen.com
APP_TIMEZONE='UTC'
APP_LOCALE=en
MAX_RESULTS=500

# --------------------------------------------
# REQUIRED: DATABASE SETTINGS
# --------------------------------------------
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=snipeit
DB_USERNAME=snipeit
DB_PASSWORD=Dinguyen@2021
DB_PREFIX=null
DB_DUMP_PATH='/usr/bin'
DB_CHARSET=utf8mb4
DB_COLLATION=utf8mb4_unicode_ci

# --------------------------------------------
# OPTIONAL: SSL DATABASE SETTINGS
root@dinguyen:~#cd /var/www/snipeit
root@dinguyen:~#composer install --no-dev --prefer-source
root@dinguyen:~#php artisan key:generate
Do you really wish to run this command? (yes/no) [no]:
 > yes
root@dinguyen:~#chown -R www-data:www-data /var/www/snipeit/
root@dinguyen:~#chmod -R 755 /var/www/snipeit/
  • Sửa file /etc/nginx/sites-available/default
root@dinguyen:~# vi /etc/nginx/sites-available/default
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/snipeit/public;
        index  index.php;
        server_name _;

        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php-fpm.sock;
                include fastcgi_params;
                fastcgi_intercept_errors on;
         }
}
  • Restart nginx
root@dinguyen:~#systemctl restart nginx.

... to be continued

Monday, February 22, 2021

Cài đặt zsh shell trên Redhat/Centos



# Kiểm tra các shell đã được cài đặt :
[root@dinguyen ~]# chsh -l
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
hoặc
[root@dinguyen ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
# Cài đặt zsh trên Redhat
[root@dinguyen ~]# yum upgrade
[root@dinguyen ~]# yum install zsh
# Kiểm tra zsh
[root@dinguyen ~]# chsh -l
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/usr/bin/zsh
/bin/zsh
# Gán default shell: #chsh -s
[root@dinguyen ~]# chsh -s /bin/zsh
Changing shell for root.
Shell changed
Relogin
# Gán default shell cho user
[root@dinguyen ~]# chsh -s /bin/zsh thiennl
# Kiểm tra current default shell
[root@dinguyen ~]# echo $SHELL
/bin/zsh

Sunday, February 21, 2021

Tuesday, February 9, 2021

Go variables


 -- Khai báo biến và gán giá trị cho biến

package main

import "fmt"

func main() {
var i int
var s string

i = 10
s = "Canada"

fmt.Println(i)
fmt.Println(s)
}
-- Khai báo và khởi tạo giá trị cho biến
package main

import "fmt"

func main() {
var i int = 10
var s string = "Canada"

fmt.Println(i)
fmt.Println(s)
}
-- Khai báo biến không type --> biến sẽ lấy type của giá trị gán cho nó
package main

import (
"fmt"
"reflect"
)

func main() {
var i = 10
var s = "Canada"

fmt.Println(reflect.TypeOf(i))
fmt.Println(reflect.TypeOf(s))
}
-- Khai báo biến với := --> Không cần từ khóa var
package main
import (
"fmt"
"reflect"
)
func main() {
name := "John Doe"
fmt.Println(reflect.TypeOf(name))
}
-- Khai báo nhiều biến trên 1 dòng
package main

import (
"fmt"
)

func main() {
var fname, lname string = "John", "Doe"
m, n, o := 1, 2, 3
item, price := "Mobile", 2000

fmt.Println(fname + lname)
fmt.Println(m + n + o)
fmt.Println(item, "-", price)
}
-- Khai báo biến trong các khối: Khối bên trong có thể truy cập các biến bên ngoài khối, khối bên ngoài không thể truy cập các biến khai báo ở các khối bên trong.
package main

import (
"fmt"
)

var s = "Japan"

func main() {
fmt.Println(s)
x := true

if x {
y := 1
if x != false {
fmt.Println(s)
fmt.Println(x)
fmt.Println(y)
}
}
fmt.Println(x)
}
-- Zero values: Nếu khai báo biến 0 gán giá trị -> biến sẽ được nhận giá trị default
package main

import "fmt"

func main() {
var quantity float32
fmt.Println(quantity)

var price int16
fmt.Println(price)

var product string
fmt.Println(product)

var inStock bool
fmt.Println(inStock)
}
Output
0
0

false
-- Quy ước đặt tên biến
-- Tên biến phải bắt đầu bằng chữ cái, không được bắt đầu bằng chữ số
-- Tên biến không chứa khoảng trắng
-- Nếu tên biến được bắt đầu bằng chữ cái thường -> nó chỉ được truy cập trong package hiện tại ( biến chưa được exported)
-- Nếu tên biến được bắt đầu bằng chữ cái hoa -> đó có thể được truy cập từ bên ngoài package hiện tại ( biến đã được export)
-- Nếu tên biến gồm nhiều từ, mỗi từ sau từ đầu tiên nên được viết hoa ( ví dụ empName, EmpAddress, ... )
-- Tên biến có phân biệt chữ hoa, chữ thường
-- Khai báo biến theo block
package main

import "fmt"

var (
product = "Mobile"
quantity = 50
price = 50.50
inStock = true
)

func main() {
fmt.Println(quantity)
fmt.Println(price)
fmt.Println(product)
fmt.Println(inStock)
}

Posted in