2018年8月29日 星期三

安裝 ubuntn 18.04 LTS

A.安裝後更新
sudo apt update && sudo apt upgrade && sudo apt dist-upgrade
B.安裝後設定root 密碼
sudo passwd root

查詢網路狀態 ifconfig -a
C安裝網路卡
https://blog.toright.com/posts/6293/ubuntu-18-04-%E9%80%8F%E9%81%8E-netplan-%E8%A8%AD%E5%AE%9A%E7%B6%B2%E8%B7%AF%E5%8D%A1-ip.html


apache安裝及設定:
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04

Server Configuration

  • /etc/apache2: The Apache configuration directory. All of the Apache configuration files reside here.
  • /etc/apache2/apache2.conf: The main Apache configuration file. This can be modified to make changes to the Apache global configuration. This file is responsible for loading many of the other files in the configuration directory.
  • /etc/apache2/ports.conf: This file specifies the ports that Apache will listen on. By default, Apache listens on port 80 and additionally listens on port 443 when a module providing SSL capabilities is enabled.
  • /etc/apache2/sites-available/: The directory where per-site virtual hosts can be stored. Apache will not use the configuration files found in this directory unless they are linked to the sites-enabled directory. Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory with the a2ensite command.
  • /etc/apache2/sites-enabled/: The directory where enabled per-site virtual hosts are stored. Typically, these are created by linking to configuration files found in the sites-availabledirectory with the a2ensite. Apache reads the configuration files and links found in this directory when it starts or reloads to compile a complete configuration.
  • /etc/apache2/conf-available//etc/apache2/conf-enabled/: These directories have the same relationship as the sites-available and sites-enabled directories, but are used to store configuration fragments that do not belong in a virtual host. Files in the conf-available directory can be enabled with the a2enconf command and disabled with the a2disconf command.
  • /etc/apache2/mods-available//etc/apache2/mods-enabled/: These directories contain the available and enabled modules, respectively. Files in ending in .load contain fragments to load specific modules, while files ending in .conf contain the configuration for those modules. Modules can be enabled and disabled using the a2enmod and a2dismod command.
設定config在用連結
Activate the virtual host.
  1. sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/example
Delete the default Nginx server block.
  1. sudo rm /etc/nginx/sites-enabled/default



安裝Mysql
https://vitux.com/how-to-install-and-configure-mysql-in-ubuntu-18-04-lts/



1.參考: https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-18-04

鏈結: 
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
sudo cp /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf 
$ sudo a2enconf phpmyadmin

https://www.howtoing.com/install-apache-with-php-and-mysql-on-ubuntu-18-04-lamp

安裝 php7.2 curl 前:
/etc/apt/sources.list 文件中像下面這樣添加一行
deb http://security.ubuntu.com/ubuntu bionic-security main universe

sudo apt update && sudo apt upgrade && sudo apt dist-upgrade

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04

重啟: 
systemctl restart apache2
sudo systemctl start apache2

sudo systemctl reload apache2

Next, let’s test for configuration errors: sudo apache2ctl configtest

Restart Apache to implement your changes: sudo systemctl restart apache2


查詢可以安裝的原件
apt-cache search php7.2
apt search php- | less

apt show package_name
apt show php-curl
sudo apt install php-curl



防火牆

$ sudo ufw default deny     // 不允許任何的連線連入
$ sudo ufw allow ssh        // 允許SSH服務連線
$ sudo ufw enable           // 啟動防火牆,執行後開機也會自動啟動
$ sudo ufw status           // 查看防火牆狀態

時間校正

$ sudo timedatectl                              // 查看目前時區
$ sudo timedatectl set-timezone Asia/Taipei     // 設定時區
$ sudo timedatectl set-ntp true                 // 啟動NTP時間同步
$ vim /etc/systemd/timesyncd.conf               // 編輯NTP伺服器清單
[Time]
NTP=tick.stdtime.gov.tw tock.stdtime.gov.tw time.stdtime.gov.tw clock.stdtime.gov.tw watch.stdtime.gov.tw


開啟rewrite
sudo a2enmod rewrite
sudo a2enmod expires


設定防火牆

------------------------
調整
sql_mode=""
//8.0
[mysqld]
sql_mode = "NO_AUTO_VALUE_ON_ZERO,ERROR_FOR_DIVISION_BY_ZERO"

參考:


磁碟指令:
df -m
可以看目前系統上的分割區容量資訊,單位是MB

使用的總空間大小,使用"$ du -h --max-depth=1"命令即可。

df -i
可以顯示分割區可存放的檔案數量

df -h 可知道目前硬碟剩餘空間與使用空間

du -h 可知目前此資料夾下所有檔案與資料夾所佔硬碟大小總數

du -s 可知目前此資料夾總共佔用硬碟大小總數,以G為單位

du -sh 可知目前此資料夾總共佔用硬碟大小總數,以G為單位

ls -l可看檔案大小

du -h -d 1 [按 Enter] (列出第一層子資料夾所佔用的空間)

刪除30天前的關鍵字
find ./ -mtime +30 -name "u*" | xargs rm -rf


檢查是否有檔案 fd 仍然被開著沒有關掉呢? 可以透過以下指令:
lsof /| grep '(deleted)'


//////////////////////////////////////////////////////
設定使用者群組&權限


資料夾設定權限

step1:給web server write 權限讀寫settings.php並加入群組www-data

chgrp www-data sites/default/settings.php

chmod g+w sites/default/settings.php

step2:加入Apache群組-R整個資料夾-v詳細顯示哪些檔案做了更動

chgrp -Rv www-data sites/default/files

step3:更改files資料夾權限

# 2775的2意思是在此資料夾之後所新增檔案或目錄都擁有此權限

chmod 2775 sites/default/files

step4:確保你的web server有權限寫入

chmod g+w -R sites/default/files

step5:settings.php檔案權限更改為只能讀取

chmod 444 sites/default/settings.php


sudo find /var/www/beclass.com/public/ -type d -exec chmod 775 {} \;
sudo find /var/www/beclass.com/public_html/ -type f -exec chmod 664 {} \;
sudo find /var/www/beclass.com/public/share/xx/ -type d -exec chmod 744 {} \;
sudo find /var/www/beclass.com/public/share/xx/ -type f -exec chmod 644 {} \;
sudo chown -R www-data:www-data /var/www/beclass.com/public/share/xx/*
sudo find /var/www/beclass.com/public/share/2013* -type d -exec chmod 744 {} \;
sudo chown -R www-data:www-data /var/www/beclass.com/public/share/xx/*
sudo find /var/www/beclass.com/public/share/2013* -type f -exec chmod 644 {} \;

如何配置 SFTP 以允許用戶上傳到網頁伺服器的文檔根目錄(Document Root)
https://ui-code.com/archives/310

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

新增群組
groupadd abc

將user加入群組abc  -d 將user由群組中刪除!
gpasswd -a username abc

//adduser without home direction
useradd username
passwd username

# 新增 YOUR_ACCOUNT 使用者帳號,並指定主群組為 YOUR_GROUP
sudo useradd --create-home --gid YOUR_GROUP YOUR_ACCOUNT

# 新增 YOUR_ACCOUNT 使用者帳號,並指定副群組為 YOUR_GROUP1, YOUR_GROUP2
sudo useradd --create-home --groups YOUR_GROUP1,YOUR_GROUP2 YOUR_ACCOUNT

# 設定既有帳號的主要群組

usermod --gid YOUR_GROUP YOUR_ACCOUNT

# 將既有帳號加入指定群組
usermod --append --groups YOUR_GROUP1,YOUR_GROUP2 YOUR_ACCOUNT

#將username 加入 sudo 群組
usermod -a -G sudo <username>

# 查詢自己所隸屬的所有群組
groups

# 查詢自己所隸屬的所有群組與 ID
id

# 查詢指定帳號所隸屬的所有群組
groups YOUR_ACCOUNT

# 查詢指定帳號所隸屬的所有群組與 ID
id YOUR_ACCOUNT

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

創建一個新組(www-pub)並將用戶添加到該組

groupadd www-pub
usermod -a -G www-pub usera ##必須使用-a附加到現有組
usermod -a -G www-pub userb

groups usera ##顯示用戶組

將/ var / www下所有內容的所有權更改為root:www-pub

chown -R root:www-pub /var/www ## -R遞歸

將所有文件夾的權限更改為2775

chmod 2775 /var/www ## 2 =設置組ID,7 =所有者(root)的rwx,7 =組(www-pub)的rwx,5 =世界(包括Apache www-data用戶)的rx

設置組ID(SETGID)位(2)使該組(www-pub)複製到在該文件夾中創建的所有新文件/文件夾。其他選項包括SETUID(4)(用於復制用戶ID)和STICKY(1),我認為只能讓所有者刪除文件。

有一個-R遞歸選項,但不會區分文件和文件夾,因此您必須使用find,如下所示:

find /var/www -type d -exec chmod 2775 {} +

將所有文件更改為0664

find /var/www -type f -exec chmod 0664 {} +

將用戶的umask更改為0002

umask控制默認的文件創建權限,0002表示文件將具有664和目錄775。對此進行設置(在我的情況umask下,通過編輯底部的行/etc/profile)意味著一個用戶創建的文件可以被其他用戶寫入www-組,而無需chmod他們。


//////////////////////////////////////////////////////

mysql max connect 214
https://sibevin.github.io/posts/2016-12-02-174519-mysql-max-connections-always-be-set-with-214

在 /etc/mysql/my.cnf 中加上的max_connections的設定
/etc/mysql/my.cnf
[mysqld] max_connections=10000
但在查看實際的設定值仍然是214。
mysql> show global variables like '%max_connecti%';

造成這個問題是有兩個原因,一是系統的「一個process最大可開起的檔案數」的值預設是1024,可以使用 ulimit -a,或是從mysql下面的指令看到這個值:
sudo將下面的設定加入到/etc/security/limits.conf這個檔案。
/etc/security/limits.conf
* soft nofile 65536 * hard nofile 65536
當設定完成,可以重啟系統讓設定值生效。第二個原因是在啟動mysql的時候要解除open file的限制,方法是在啟動mysql的service檔裡加上LimitNOFILE=65535的設定:
/lib/systemd/system/mysql.service
LimitNOFILE=65535
當這兩步做完,重啟mysql之後,就可以看到正確的連線數設定了。









mysql max connect 214連線數設定

https://sibevin.github.io/posts/2016-12-02-174519-mysql-max-connections-always-be-set-with-214

在 /etc/mysql/my.cnf 中加上的max_connections的設定
/etc/mysql/my.cnf
[mysqld] max_connections=10000
sudo將下面的設定加入到/etc/security/limits.conf這個檔案。
/etc/security/limits.conf
* soft nofile 65536 * hard nofile 65536
當設定完成,可以重啟系統讓設定值生效

第二個原因是在啟動mysql的時候要解除open file的限制,方法是在啟動mysql的service檔裡加上LimitNOFILE=65535的設定:
/lib/systemd/system/mysql.service
LimitNOFILE=65535
當這兩步做完,重啟mysql之後,就可以看到正確的連線數設定了。

 manba 網路芳鄰
https://websiteforstudents.com/samba-setup-on-ubuntu-16-04-17-10-18-04-with-windows-systems/

sudo ufw allow from 10.10.10.58 to any app samba


更新phpmyadmin
https://devanswers.co/manually-upgrade-phpmyadmin/
定時執行
https://devanswers.co/backup-mysql-databases-linux-command-line/


SSH設定
~/.ssh/ (目錄):權限必須為 700 (drwx------)。
~.ssh/authorized_keys (Public Key)
權限必須為 644 (-rw-r--r--)。
擁有者必須屬於本身帳戶才行。
 Linux 產生的 Private Key 轉換成 Windows 系統可識別的 *.ppk
Private Key 在 client端, public key 放在server
直接將公鑰資料複製到 server 的 ~/.ssh/authorized_keys

# 重新啟動 SSH 服務(Ubuntu Linux)
service sshd restart

調整一下 /etc/ssh/sshd_config 
PermitRootLogin no
PasswordAuthentication no




2018年6月25日 星期一

簡單指令

服務監聽狀態:netstat -ntl
查看安裝的服務 service --status-all


2018年5月15日 星期二

SSL 安裝


HTTPS多網站1個IP多個SSL證書的Apache設定辦法 
原文網址:https://itw01.com/5OXHE2Q.html

Using Multiple SSL Certificates in Apache with One IP Address
https://www.digicert.com/ssl-support/apache-multiple-ssl-certificates-using-sni.htm

How To Set Up Multiple SSL Certificates on One IP with Apache on Ubuntu 12.04
https://www.digitalocean.com/community/tutorials/how-to-set-up-multiple-ssl-certificates-on-one-ip-with-apache-on-ubuntu-12-04


資料權限設定
SSL => chmod 755 
private => chmod 710 private
檔案:
The .crt file  (chown root:root and chmod 644)
private key location; (chown root:ssl-cert and chmod 640)


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

Note:
chmod 710 supports ssl-cert group under Ubuntu.
 (See comments)
Setting permission to 700 on /etc/apache2/ssl/private will also work fine.

Place SSL files:

Put public www ssl certificate(s) along with intermediate certificate(s) in /etc/apache2/ssl
Put private ssl key(s) in /etc/apache2/ssl/private

Set owner:

sudo chown -R root:root /etc/apache2/ssl/
sudo chown -R root:ssl-cert /etc/apache2/ssl/private/

Note:
If you do not have ssl-cert group, just use 'root:root' on line above or skip 2nd line.

Set permissions:

Public Certificate(s)

sudo chmod 644 /etc/apache2/ssl/*.crt

Private Key(s)

sudo chmod 640 /etc/apache2/ssl/private/*.key

Note:
The group permission is set to READ (640) due to Ubuntu ssl-cert group. '600' is fine as well.

Enable the Apache SSL module

sudo a2enmod ssl

Edit any Apache site files and enable

(see last paragraph) *

sudo nano /etc/apache/sites-available/mysiteexample-ssl.conf
sudo a2ensite mysiteexample-ssl
#             ^^^^^^^^^^^^^^^^^ <-Substitute your ".conf" filename(s)

Restart Apache2 service

sudo service apache2 restart

or

sudo systemctl restart apache2.service

2018年1月16日 星期二

jquery datapickup UI

if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
$(“#date”).datepicker(“destroy”);
$(“#date”).prop(“type”, “date”);
//(注意日期格式要調整成跟datepicker 日期格式一樣)
}

 

參考:https://blog.user.today/rwd-mistake/

變更寬度
$( document ).ready( function(){     setMaxWidth();     $( window ).bind( "resize", setMaxWidth ); //Remove this if it's not needed. It will react when window changes size.      function setMaxWidth() {     $( "#mainContainer" ).css( "maxWidth", ( $( window ).width() * 0.7 | 0 ) + "px" );     }  });