顯示具有 CentOS 標籤的文章。 顯示所有文章
顯示具有 CentOS 標籤的文章。 顯示所有文章

2019年12月2日 星期一

[Linux] CentOS 7 Vsftp FTP Service 安裝

因為工作上的需求需要重建FTP Service,想說就順便寫一下SOP
筆記一下

先更新yum repo
yum update

安裝vsftp程式
yum -y install vsftpd

修改設定檔
vi /etc/vsftpd/vsftpd.conf

#限制匿名登入
anonymous_enable=NO

#限制使用者無法跳出家目錄
chroot_list_enable=YES 啟用鎖定家目錄
chroot_local_user=YES 啟用本地使用者(與chroot_list_file搭配,YES表示chroot_list內跳出家目錄)
chroot_list_file=/etc/vsftpd/chroot_list 家目錄使用者(這裡表示跳出者,不想有人跳出都設定空白即可)

#排除根目錄寫入的問題
allow_writeable_chroot=YES 安全性問題,預設不允許你的根目錄的權限設定是可以寫入的,這邊排除它

#寫入 /etc/vsftpd/user_list 變成可以使用 FTP 的帳號
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list 這裡面是可以使用喔,不要搞顛倒了
userlist_enable=YES

#最大速率 100k
local_max_rate=100000

啟動vsftpd 服務
systemctl enable vsftpd

systemctl start vsftpd

2019年11月22日 星期五

[Linux] 解決在 CentOS Vsftpd Service 連接 出現 500 OOPS 的錯誤訊息

最近老K在重建公司的FTP Server時遇到了這個500 OOPS的問題

上網找了一下解法...沒想到只要加一行指令就可以解掉了


修改前:
連線時會遇到500 OOPS錯誤













修改後:
編輯 /etc/vsftpd/vsftpd.conf 設定檔
vim /etc/vsftpd/vsftpd.conf
加入下面這一行
allow_writeable_chroot=YES

















重新啟動 vsftpd service
systemctl stop vsftpd
systemctl start vsftpd









就可以正常連接了

2019年10月9日 星期三

[CodiMD] Codimd 安裝血淚史...踩了一堆雷

為什麼會有這個需求呢...因為一開始SOP都是放在外面服務上
但你又要把一些ip密碼的什麼修改掉...新人到職後根本看不懂你在寫什麼
後來就上網查到Codimd(hackmd)這套mark down 共編筆記
相關功能請參考 >(https://hackmd.io/s/features-tw)













設定Proxy
vim /etc/yum.conf
設定Proxy=http://x.x.x.x:3128   (因為內部鎖很多只能透過proxy出去更新)
yum update -y

關閉防火牆
systemctl stop firewalld
 systemctl disable firewalld

關閉Selinux
 vim /etc/selinux/config
SELINUX=disabled
修改完 Selinux 後需Reboot一次

安裝需要套件
yum install git curl

因為要安裝新版node js 需要curl 新的source
curl -sL https://rpm.nodesource.com/setup_11.x | sudo -E bash -
yum install nodejs npm node-gyp  gcc gcc-c++
yum install epel-release
yum update

因為要安裝新版mysql 需要wget 新的source
yum install mysql-community-server
systemctl start mysqld
systemctl status mysqld


Clone Codimd git

安裝Codimd
cp config.json.example config.json
bin/setup

設定MySQL資料庫
mysql -uroot -p
設定密碼等等
新建databases "codimd"

CREATE DATABASE codimd CHARACTER SET utf8 COLLATE utf8_general_ci;
show databases;
確認codimd 這個databases 有被成功建立

設定Codimd 去串mysql 連線
vim /你的安裝路徑/codimd/.sequelizerc
修改 "url" 這行就好了
"mysql://root:XXXXXXX@localhost:3306/codimd"

開始編輯config.json(很重要…Codimd的精華)
Vim config.jason
主要是修改db參數,因為這邊我沒有要串ldap,有需要者可參考此blog (https://spicyboyd.blogspot.com/2019/03/linux-hackmd-codimd.html)

 "db": {
            "username": "root",
            "password": "xxxxxxxx",
            "database": "codimd",
            "host": "localhost",
            "port": "3306",
            "dialect": "mysql"


可以改port 他預設是3000,K這邊改成80,因為只有內部使用而已
(之後會再餵憑證進去...畢竟只走http會被稽核"誤")
然後我沒有要開放給匿名建置筆記本
所以我這兩個選項都改成 "false"
 allowAnonymous: false,
 allowAnonymousEdits: false,

如果沒串ldap,他可以用email註冊登入
所以這邊也要設定 "true"
  email: true,
  allowEmailRegister: true,
編輯完後 存檔離開























修改環境變數
另外因為他預設吃的環境變數是 "development"
所以要改成  "production"
暫時設定環境變數
export PATH=$PATH:NODE_ENV=production
永久的就寫到 vim /etc/profile 就好


執行服務
cd /你的安裝路徑/codimd/
npm run build
node_modules/.bin/sequelize db:migrate
npm start
開啟瀏覽器 輸入 Server IP:80 <-----K這邊已經先改成80 port


這樣一個私有的mark down 筆記服務就起來了

因為網路上文件很雜很亂,我踩過很多雷
後來整合了很多blog的技術文件才成功安裝

安裝完畫面如下:







Codimd github : (https://github.com/codimd)





2019年4月9日 星期二

[Citrix] Xenserver 監控 - Netdata 安裝

最近同事推薦了一款很炫炮的監控軟體,畫面很漂亮很酷
二話不說就馬上上網找步驟安裝起來,但是因為XenServer
安裝比較麻煩需要先改repo才能進行 yum install
這邊我會再寫一篇修改for XenServer 7.x版本的repo檔
下圖是Netdata 監控XenServer 所看到的DashBoard



安裝步驟如下 :

Step 1: Update the system

For security purposes, update the system to the latest stable status using YUM:
sudo yum update -y && sudo reboot
After the reboot finishes, log in with the same sudo user.

Step 2: Install dependencies

In order to install Netdata, you need to install the dependencies below:
sudo yum install zlib-devel libuuid-devel libmnl-devel gcc make git autoconf autogen automake pkgconfig
sudo yum install curl jq nodejs

Step 3: Install Netdata

Install Netdata with the official installation script:
cd ~
git clone https://github.com/firehol/netdata.git --depth=1
cd netdata
sudo ./netdata-installer.sh
During the installation process, Press ENTER to start the installation.
If no errors occur during installation, the Netdata daemon will start.

Step 4: Modify firewall rules

Before you can access Netdata's web interface, you need to modify firewall rules to allow traffic on port 19999, the default communication port of Netdata:
sudo firewall-cmd --permanent --zone=public --add-port=19999/tcp
sudo firewall-cmd --reload

Step 5: View the monitoring interface

Confirm the installation by opening your web browser and visiting the monitoring interface of Netdata:
http://<your-Vultr-server-IP>:19999

[系統設定]
vim /etc/netdata/netdata.conf

* global - 服務的全域設定
* plugins - 啟用或停用插件
* plugin:NAME - 各個插件的設定
* CHART_NAME - 各個圖表的設定
以預設值就已經可以正常的運作了,而這些參數可以視狀況修改:
* update every = 1,每一秒更新一次
* default port = 19999,預設通訊埠在 TCP 19999
* bind to = *,不綁定 IPv4、IPv6 位址
* disconnect idle web clients after seconds = 60,Web Client 閒置 60 秒後就踢掉
* enable web responses gzip compression = yes,啟用網頁 GZip 壓縮功能

2018年9月27日 星期四

[Security] 弱點掃描修正 - How to disable the mDNS service on CentOS

Run the following commands to disable the mDNS service on CentOS 6 and lower:
service avahi-daemon stop
chkconfig avahi-daemon off

Or when you have CentOS 7:
systemctl stop avahi-daemon
systemctl disable avahi-daemon

What is the avahi-daemon service?
The Avahi mDNS/DNS-SD daemon implements Apple’s Zeroconf architecture 
(also known as “Rendezvous” or “Bonjour”). 

The daemon registers local IP addresses and static services using 
mDNS/DNS-SD and provides two IPC APIs for 
local programs to make use of the mDNS record 
cache the avahi-daemon maintains.

 First there is the so called “simple protocol” which is used exclusively 
by avahi-dnsconfd (a daemon which configures unicast DNS servers 
using server info published via mDNS) and nss-mdns 
(a libc NSS plugin, providing name resolution via mDNS). 
Finally there is the D-Bus interface which provides a rich 
object oriented interface to D-Bus enabled applications.

2017年10月13日 星期五

Centos Postfix Server安裝設定教學

Postfix軟體需求CentOS 6
(此編教學都是在CentOS 6下進行的,其它的Linux版本或是CentOS 5之前的版本可能不適用)
Postfix安裝
安裝指令
1
yum install postfix
CentOS 5之前預設的Mail Server服務是Sendmail,而在CentOS 6 後即是以Postfix當作預設的 Mail Server,Postfix比起Sendmail在設定上更容易上手,因此不需要像網路上其它的教學安裝system-switch-mail,因為system-switch-mail是用來將Sendmail切換成Postfix。
Postfix最主要的功能則是啟動SMTP的服務,也就是架設一台MTA(Mail Transfer Agent)。
Postfix設定
Postmail的主要設定都在”etc/postfix/main.cf”,編輯的方式如下
1
#vi /etc/postfix/main.cf
以下就來介紹要架設完一台MTA(也就是Mail Server的SMTP服務)的相關設定
1.設定Hostname,Hostname即是我們的郵件伺服器的主機名稱,是由英文字母或數字所組成,比如www.google.com或mail.google.com就是一個Hostname。Postmail的Hostname設定如下
尋找”#myhostname =”字串,預設會看到”#myhostname = host.domain.tld”和”#myhostname = virtual.domain.tld”這二行字串
請在這二行後面增加以下的字串設定即可
1
2
3
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = 你的主機名稱 #新增此行,約加在第77
2.設定網域名稱(Domain Name),主機名稱通常都是在建立在網域名稱之內,像是www.google.com則是網頁服務,mail.google.com則會是郵件主機服務,通常網域名稱都會是主機名稱(Hostname)去掉第一個掉包含前面的文字部份,比如說www.google.com的Domain則是google.com。 以下則是Postfix的網域名稱設定方法
尋找”#mydomain =”字串,預設會看到”#mydomain =domain.tld”
新增一行如下
1
2
#mydomain =domain.tld
mydomain = 你的網域名稱         #新增此行,約加在第  85
3.設定Origin Name,Origin Name是我們的郵件位址在”@”後面的文字內容,比如像是stnet253@gmail.com,gmail.com就是我們的Origin Name,而stnet253則是郵件擁有人的帳號名稱。以下為Postfix的Origin Name的設定。
尋找”#myorigin = $mydomain”字串,將”#”移除,變成
1
2
3
#myorigin = $mydomain                               #刪除此行

myorigin = $mydomain                 #新增此行,約加在第  100
4.設定 postfix 的監聽介面,Postfix預設只會監聽來自於本機端的所傳出的封包,必須使用下列設定,才可以傳收所有來自於網路端的所有封包。
尋找”#inet_interfaces = all”字串,將”#”移除 (表示此行Enable) 。
後面的”inet_interfaces = localhost”字串,在最前面加上”#”(表示disable此行設定)
此步驟的設定內容整理如下
1
2
3
4
inet_interfaces = all #修改此行,約在第 114
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, locatlhost
#inet_interfaces = localhost #修改此行,約在第 117 行
5.修改Postfix的通訊協定,目前網路的協定主流有IPv4與IPv6,在大部份的情況下,我們都是利用IPv4在通訊的,如果你的Mail Server沒有需要使用到IPv6,可以做以下的設定修改。
尋找” inet_protocols = all”字串,改成
1
inet_protocols = ipv4 #約在第 120
6.設定能收收信件的主機名稱,Postfix預設只能收到設定的Hostname與Domain Name以及本機端的信件,此步驟是再增加能收信件的網路名稱。
尋找”mydestination = $myhostname, localhost.$mydomain, localhost”字串,在最前面加入”#”(表示此行disable)。
將”#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain”的”#”移除(表示此行Enable)。
#mydestination = $myhostname, localhost.$mydomain, localhost
1
2
3
4
5
#修改此行,約在第 165行

mydestination = $myhostname, localhost.$mydomain, localhost, mydomain

#修改此行,約在第 166行
7.設定信任的用戶端,當要寄信時,會參考此值,若非信任的用戶,則不會幫你的信件轉到其它的MTA主機上
尋找”#mynetworks =”,在”#mynetworks = hash:/etc/postfix/networks”這行後面加上
1
2
3
4
5
#mynetworks = hash:/etc/postfix/networks

mynetworks = 127.0.0.0/8, 192.168.1.0/24, hash:/etc/postfix/access

#加入此行,約在268行
8.規範可以 relay 的 MTA 主機位址,通常這個都直接設為mydestination
尋找”#relay_domains = $mydestination”,將”#”移除,變成
1
relay_domains = $mydestination                 #修改此行,約在第 298
9.設定郵件別名的路徑
檢查” alias_maps”設定是否為以下字串設定
1
alias_maps = hash:/etc/aliases                     #約在第 388
10.設定指定郵件別名表資料庫路徑
檢查” alias_ database”設定是否為以下字串設定
1
alias_database = hash:/etc/aliases               #約在第 399
在main.cf的設定整理如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
myhostname = 你的主機名稱                    #約在第  77

mydomain = 你的網載名稱                        #約加在第  85

myorigin = $myhostname                             #約在第 100

inet_interfaces = all                       #約在第 114 行,117 行要註解掉

inet_protocols = ipv4                     #約在第 120

mydestination = $myhostname, localhost.$mydomain, localhost, mydomain  #約在第166

mynetworks = 127.0.0.0/8, 192.168.1.0/24, hash:/etc/postfix/access #約在268

relay_domains = $mydestination                 #約在第 298

alias_maps = hash:/etc/aliases                     #約在第 388

alias_database = hash:/etc/aliases               #約在第 399
11.設定完成後,請在終端機下輸入以下二行指令(詳細請參考後面章節” 設定郵件主機使用權限與過濾機制”及” 郵件別名”)

1
2
3
# postmap hash:/etc/postfix/access

# postalias hash:/etc/aliases
12.重啟postfix就可以利用smtp的服務收發信件,在終端機視窗下輸入

1
# service postfix restart
13.檢查SMTP服務是否開啟,如果有的話,輸入下列命列,會看到Port 25正在監聽的狀態

1
# netstat -tlunp | grep ':25'
Postfix測試
1.寄信測試
此時我們已經可以利用此台主機使用smtp收送電子郵件了, 利用mail指令來測試
mail root@網域名稱
Subject:Test
This is test mail
.
EOT
2.收信測試
當我們從內部或外部寄信過來時,預設的郵件存放位址如下:
/var/spool/mail(或 /var/mail)
從此目錄裡查看帳號名稱的檔案,我們所收發的信件都會存在這裡
如果使用 ip:222.222.222.222 的主機經由outlook smtp寄信 會被
554 5.7.1 <username@gmail.com>: Relay access denied
請在main.cf中mynetworks設定後面加入
1
mynetworks = 127.0.0.0/8, 192.168.1.0/24, hash:/etc/postfix/access

1
2
cd /etc/postfix
vi access
加入外寄允許的ip
222.222.222.222  OK
不允許smtp
222.222.222.222 REJECT
修改完畢後要下行

1
postmap /etc/postfix/access