CentOS8でサーバー構築 - 11.PHPでMemcached

DBへの接続は極力少なくして、キャッシュセッションはMemcachedを使いましょう。
って事でインストール。

Memcachedのインストール

Memcachedインストール
# dnf -y install memcached php-pecl-memcached
milter-manager_repos                                                                347  B/s | 819  B     00:02
milter-manager_repos-source                                                         446  B/s | 819  B     00:01
Dependencies resolved.
=====================================================
 Package                 Architecture    Version                        Repository             Size
======================================================
Installing:
 memcached           x86_64          1.5.9-3.el8           AppStream         132 k
 php-pecl-memcached      x86_64      3.1.5-1.el8.remi.7.4   remi-modular    96 k
Installing dependencies:
 fastlz        x86_64          0.1.0-0.12.20070619svnrev12.el8     epel        15 k
 libmemcached-libs       x86_64      1.0.18-15.el8          AppStream        137 k
 php-pecl-igbinary       x86_64      3.1.2-1.el8.remi.7.4       remi-modular      158 k
 php-pecl-msgpack        x86_64      2.1.0-1.el8.remi.7.4       remi-modular       65 k

Transaction Summary
=======================================================
Install  6 Packages
  epel、remiリポジトリを使用するので、使えるようにしておく事。

Memcachedの設定

Memcached設定
# vi /etc/sysconfig/memcached
PORT="11211"
USER="memcached"
MAXCONN="512"
CACHESIZE="64"
OPTIONS="-l 127.0.0.1"
phpのMemcached設定
# vi /etc/php.d/50-memcached.ini
;  Use memcache as a session handler
session.save_handler=memcached
;  Defines a comma separated list of server urls to use for session storage
session.save_path="localhost:11211"
# vi /etc/php.ini
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
;session.save_handler = files
memcached起動
# systemctl start memcached
# systemctl enable memcached
Created symlink /etc/systemd/system/multi-user.target.wants/memcached.service → /usr/lib/systemd/system/memcached.service.
Apache再起動
# systemctl restart httpd

Firewalledの設定

Firewalled設定
# firewall-cmd --add-port=11211/tcp --zone=public --permanent
# firewall-cmd --reload
下記の様なエラーが出て起動できず。
OPTIONS="-l 127.0.0.1"
と修正して解決。
systemctl status memcached
● memcached.service - memcached daemon
   Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2020-07-17 09:30:49 JST; 2min 21s ago
  Process: 446015 ExecStart=/usr/bin/memcached -p ${PORT} -u ${USER} -m ${CACHESIZE} -c ${MAXCONN} $OPTIONS (code=e>
 Main PID: 446015 (code=exited, status=71)

Jul 17 09:30:49 kowloonet.net systemd[1]: Started memcached daemon.
Jul 17 09:30:49 kowloonet.net memcached[446015]: bind(): Cannot assign requested address
Jul 17 09:30:49 kowloonet.net memcached[446015]: failed to listen on TCP port 11211: Cannot assign requested address
Jul 17 09:30:49 kowloonet.net systemd[1]: memcached.service: Main process exited, code=exited, status=71/OSERR
Jul 17 09:30:49 kowloonet.net systemd[1]: memcached.service: Failed with result 'exit-code'.