【Memache】部署Memcache,採用Supervisord管理

1.修改主機名

vim /etc/hostname
vim /etc/hosts 
hostname <主機名>

2.服務器磁盤掛載

vim /data/scripts/auto_fdisk.sh

3.將磁盤掛載修改成uuid方式

blkid /dev/xvdb1
vim /etc/fstab
 UUID=41852b97-3630-42b1-b2ae-9d8f77922245 /data ext4 defaults 1 2

4.初始化服務器

#!/bin/sh
yum clean all
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/enforcing/disabled/g' /etc/selinux/config
yum -y install vim openssh* ntp wget screen bash-completion git
service ntpd stop
ntpdate time.nist.gov
sed -i 's/0.centos.pool.ntp.org/time.nist.gov/g' /etc/ntp.conf
chkconfig ntpd on
service ntpd restart

5.安裝程序

下載oneinstack,根據需求安裝所需memcached與supervisordphp

6.執行cache初始化腳本

#!/bin/sh -e

########## 1. 基礎工做 start ##########

tmux_conf=/root/.tmux.conf

chk_service_super=`systemctl status supervisord.service | grep inactive`
if [[ -n $chk_service_super ]]
then
    echo "supervisord is inactive..."
else
    sudo service supervisord stop
fi

chk_service_hhvm=`systemctl status hhvm | grep inactive`
if [[ -n $chk_service_hhvm ]]
then
    echo "hhvm is inactive..."
else
    sudo service hhvm stop
fi

mkdir -p /data/logs
mkdir -p /data/backup
mkdir -p /data/components/
mkdir -p /data/scripts
mkdir -p /data/softs
mkdir -p /data/logs/access
mkdir -p /data/logs/general
mkdir -p /data/logs/logic
mkdir -p /data/logs/error/supervisor
chmod -R 777 /data/logs/*
chmod -R 777 /data/components/
# 經常使用類庫
sudo yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
# 經常使用軟件
sudo yum -y install net-tools unzip vim lrzsz subversion tmux

# tmux配置
cat > $tmux_conf <<EOF
set-option -g default-terminal "screen-256color"

#設置前綴爲Ctrl + x
set -g prefix C-x

#解除Ctrl+b 與前綴的對應關係
unbind C-b

#up
bind-key k select-pane -U
#down
bind-key j select-pane -D
#left
bind-key h select-pane -L
#right
bind-key l select-pane -R
#select last window
bind-key C-l select-window -l

#copy-mode 將快捷鍵設置爲vi 模式
setw -g mode-keys vi

#bind C-k run "./bin/tmux-zoom.sh"
EOF
########## 基礎工做 end ##########

########## 部署memcached start ##########

ip_addr=`ifconfig | grep 'inet' | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $2}'`
sed -i "s/OPTIONS=\"-l 127.0.0.1\"/OPTIONS=\"-l ${ip_addr}\"/g" /etc/init.d/memcached
sed -i 's/CACHESIZE=977/CACHESIZE=2048/g' /etc/init.d/memcached
sed -i 's/MAXCONN=1024$/MAXCONN=10240/g' /etc/init.d/memcached

systemctl daemon-reload
service memcached restart

########## 部署memcached end ##########

7.配置supervisord

7.1 啓動supervisord服務

service supervisord start

7.2 修改supervisord配置文件

vim /etc/supervisord.conf

修改以下信息:
[include]
files = supervisord.d/*.ini

#[program:hhvm]
#command=/usr/bin/hhvm --mode server --user www --config /etc/hhvm/server.ini --config /etc/hhvm/php.ini --config /etc/hhvm/config.hdf
#numprocs=1 ; number of processes copies to start (def 1)
#directory=/tmp ; directory to cwd to before exec (def no cwd)
#autostart=true ; start at supervisord start (default: true)
#autorestart=unexpected ; whether/when to restart (default: unexpected)
#stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)

7.4 添加memcached信息

vim /etc/supervisord/mc_11211.ini
vim /etc/supervisord/mc_11212.ini
vim /etc/supervisord/mc_11213.ini

添加以下信息linux

[program:mc_11211]
command=/usr/local/memcached/bin/memcached -p 11211 -u memcached -m 2048 -c 10240 -l 10.0.0.51
user=root                                ;執行命令的用戶
numprocs=1                            ; 啓動幾個進程 默認 1
#process_name=%(process_num)02d
;directory=                              ; 執行前要不要先cd到目錄去
autostart=true                          ; 隨着supervisord的啓動而啓動
autorestart=true                        ; 是否自動重啓 默認true
startretries=5                          ; 啓動失敗時的最多重試次數 默認5
;;exitcodes=0                            ; 正常退出代碼
;;stopsignal=KILL                         ; 用來殺死進程的信號
;;stopwaitsecs=10                        ; 發送SIGKILL前的等待時間
redirect_stderr=true                     ; 重定向stderr到stdout
stdout_logfile=/data/logs/error/supervisor/mc_11211.log
stderr_logfile=/data/logs/error/supervisor/mc_11211.log

8.最終配置

關閉防火牆服務c++

systemctl stop firewalld.service
systemctl disable firewalld.service

關閉memcached服務git

service memcached stop

關閉memcached開機自啓vim

chkconfig memcached off

重啓supervisord,採用supervisord啓動memcachedcentos

service supervisord restart
相關文章
相關標籤/搜索