Hướng dẫn cài đặt Squid làm Proxy trên VPS CentOS 7

Bạn có VPS đang chạy hoặc một script nào đó để làm web, tuy nhiên bạn đang cần một nhưng lại không muốn mua thêm VPS. Bài viết này sẽ hướng dẫn các bạn cách cài đặt  làm trên VPS CentOS 7 (vì nó chỉ là một service nên không ảnh hưởng đến hay script đang chạy).

Cài đặt  làm Proxy trên VPS CentOS 7.

Bước 1: Đăng nhập SSH (mình không hướng dẫn bước này vì nó là điều cơ bản nhất rồi)

Bước 2: Cập nhật hệ thống.

yum -y update

Bước 3: Cài đặt kho EPEL vào hệ thống của mình vì Squid không có sẵn.

yum -y install epel-release
yum -y update
yum clean all

Bước 4: Proxy.

yum -y install squid

Bước 5: Khởi động Squid.

systemctl start squid

Bước 6: Để Squid tự động khởi động, bạn có thể chạy lệnh sau.

systemctl enable squid

Bước 7: Kiểm tra Squid.

systemctl status squid

Kết quả trả về tương tự như bên dưới là việc đã thành công.

● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-12-09 02:48:42 UTC; 18min ago
  Process: 16102 ExecStop=/usr/sbin/squid -k shutdown -f $SQUID_CONF (code=exited, status=0/SUCCESS)
  Process: 16109 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS)
  Process: 16104 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
 Main PID: 16111 (squid)
   CGroup: /system.slice/squid.service
           ├─16111 /usr/sbin/squid -f /etc/squid/squid.conf
           ├─16113 (squid-1) -f /etc/squid/squid.conf
           ├─16114 (logfile-daemon) /var/log/squid/access.log
           └─16204 (basic_ncsa_auth) /etc/squid/passwd

Dec 09 02:48:42 li1323-230.members.linode.com systemd[1]: Stopped Squid cachi...
Dec 09 02:48:42 li1323-230.members.linode.com systemd[1]: Starting Squid cach...
Dec 09 02:48:42 li1323-230.members.linode.com squid[16111]: Squid Parent: wil...
Dec 09 02:48:42 li1323-230.members.linode.com systemd[1]: Started Squid cachi...
Dec 09 02:48:42 li1323-230.members.linode.com squid[16111]: Squid Parent: (sq...
Hint: Some lines were ellipsized, use -l to show in full.

Bước 8: Cài đặt httpd-tools

yum -y install httpd-tools

Nếu bạn đã cài DirectAdmin rồi thì lệnh này sẽ trả về kết quả là “no package httpd-tools available. Error: Nothing to do”. Nhưng không sao cả, vì DirectAdmin đã có httpd sẵn rồi.

Bước 9: Tạo một file mới và cấp quyền cho Squid daemon để nó có thể truy cập.

touch /etc/squid/passwd && chown squid /etc/squid/passwd

Bước 10: Tạo tài khoản .

htpasswd /etc/squid/passwd namlee

Trong đó namlee chính là user, bạn có thể thay đổi tùy theo ý bạn.
Lúc này nó sẽ yêu cầu bạn nhập mật khẩu cho tài khoản namlee, bạn nhập mật khẩu và nhấn Enter cho đến khi có kết quả như bên dưới.

New password: 
Re-type new password: 
Adding password for user namlee

Bước 11: Cấu hình Squid.

nano /etc/squid/squid.conf

Nếu bạn chưa cài đặt nano có thể thay bằng vi.

Thêm các dòng sau vào bên dưới danh sách port.

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid Basic Authentication
auth_param basic credentialsttl 2 hours
acl auth_users proxy_auth REQUIRED
http_access allow auth_users

Khởi động lại Squid.

systemctl restart squid

Bước 12: Mở port cho Squid.
Mặc định, Squid sẽ sử dụng port 3128, bạn có thể sửa lại port trong file /etc/squid/squid.conf
Chạy lệnh sau để mở port 3128 cho FirewallD.

firewall-cmd --zone=public --add-port=3128/tcp
firewall-cmd --zone=public --add-port=3128/tcp --permanent
firewall-cmd --reload

*Nếu bạn sử dụng CSF trên DirectAdmin thì bạn truy cập vào CSF để mở port.

Bây giờ bạn đã có thể sử dụng Proxy bạn vừa tạo, mình thường sử dụng trình duyệt Firefox để thêm proxy.
Chúc các bạn thành công.

0 0 vote
Article Rating

NamLee Blog - Chia sẻ là đam mê
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x