准备
更新 Yum
更新 Yum 源
1 2 3
| rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
|
安装 Git
安装 Htop
安装 Vim
Nginx
安装 Nginx 代码仓库
1
| yum install -y epel-release
|
安装 Nginx
启动 Nginx
开机启动 Nginx
Nginx 配置文件
- /usr/share/nginx/html 默认的代码目录
- /etc/nginx/conf.d/default.conf 默认的配置文件
MariaDB
安装 MariaDB
1
| yum install -y mariadb-server mariadb
|
启动 MariaDB
初始化 MariaDB
1
| mysql_secure_installation
|
开机启动 MariaDB
1
| systemctl enable mariadb
|
PHP
安装 PHP
1
| yum install -y php71w php71w-mysql php71w-xml php71w-soap php71w-xmlrpc php71w-mbstring php71w-json php71w-gd php71w-mcrypt php71w-fpm php71w-pdo php71w-pecl-redis
|
启动 PHP-FPM
开机启动
1
| systemctl enable php-fpm
|
配置 PHP 关联 Nginx,编辑 Nginx 配置文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| server{ listen 80; server_name cowcat.cc; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
|
在 /usr/share/nginx/html
新增文件 index.php
,编辑代码如下:
输入域名,检查 PHP 是否与 Nginx 关联起来
Redis
安装 Redis
1 2 3
| wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm rpm -ivh epel-release-7-9.noarch.rpm yum install -y redis
|
启动 Redis
开机启动 Redis
Beanstalkd
安装 Beanstalkd
1 2 3 4 5
| wget http://cbs.centos.org/kojifiles/packages/beanstalkd/1.9/3.el7/x86_64/beanstalkd-1.9-3.el7.x86_64.rpm wget http://cbs.centos.org/kojifiles/packages/beanstalkd/1.9/3.el7/x86_64/beanstalkd-debuginfo-1.9-3.el7.x86_64.rpm rpm -ivh beanstalkd-1.9-3.el7.x86_64.rpm rpm -ivh beanstalkd-debuginfo-1.9-3.el7.x86_64.rpm yum install -y beanstalkd
|
启动 Beanstalkd
1
| systemctl start beanstalkd
|
开机启动
1
| systemctl enable beanstalkd
|
Composer
安装 Composer
1 2 3
| curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer composer -v
|
全局设置国内镜像
1
| composer config -g repo.packagist composer https://packagist.phpcomposer.com
|
Node.js
安装 Node.js
1 2
| yum install -y gcc-c++ make yum install -y nodejs
|
安装 webpack、gulp、bower
1 2 3
| npm install bower -g npm install gulp -g npm install webpack -g
|
Gogs
设置子域名
1
| hostnamectl set-hostname git.cowcat.cc
|
禁用 SELinux 相关选项
1 2
| sed -i /etc/selinux/config -r -e 's/^SELINUX=.*/SELINUX=disabled/g' systemctl reboot
|
创建 gogs 数据库
1 2 3
| CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci; use gogs; SET default_storage_engine=INNODB;
|
安装 Go
安装 Gogs
1 2 3 4 5 6 7 8 9 10
| // 下载二进制包 wget http://7d9nal.com2.z0.glb.qiniucdn.com/0.10rc/linux_amd64.zip // 解压 unzip linux_amd64.zip cd gogs/ // 后台运行 nohup ./gogs web & tail -f nohup.out
|
访问 URL 进行安装,安装 URL 是主机 IP 地址加上 3000 端口。
以守护进程的形式运行 Gogs:https://github.com/gogits/gogs/blob/master/scripts/init/centos/gogs
Walle
进入 MySQL,新增数据库如下:
1
| create database walle default character set utf8 COLLATE utf8_general_ci;
|
安装依赖
代码检出
1 2
| mkdir -p /data/www/ # 新建目录 git clone https://github.com/meolu/walle-web.git # 代码检出
|
连接数据库
1 2 3 4 5 6 7 8 9
| cd walle-web/ vim config/local.php // 修改 PHP 数组 'db' => [ 'dsn' => 'mysql:host=127.0.0.1;dbname=walle', # 新建数据库walle 'username' => 'username', # 连接的用户名 'password' => 'password', # 连接的密码 ],
|
安装 vendor
1 2
| cd /data/www/walle-web composer install --prefer-dist --no-dev --optimize-autoloader -vvvv
|
初始化项目
1 2
| cd /data/www/walle-web ./yii walle/setup
|
配置 Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| server { listen 80; server_name walle.compony.com; # 改你的host root /the/dir/of/walle-web/web; # 根目录为web index index.php; # 建议放内网 # allow 192.168.0.0/24; # deny all; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri = 404; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
|
然后访问你配置好的域名或服务器地址,管理员默认账号密码是 admin/admin
,开发者默认账号密码是 demo/demo
。
有些错误 walle 捕捉不到,默认操作日志在 /tmp/walle/ 下,具体可在 config/local.php 里 log.dir 配置路径,tail 着日志,部署看日志。
如果发现 /tmp/walle 下没有日志,很有可能是因为 CentOs 7 yum 安装的 php-fpm 默认 /tmp 目录不可写:/usr/lib/systemd/system/php-fpm.service 中的 PrivateTmp=true 禁止了向tmp目录写日志,解决方法如下:
1 2 3 4 5
| vi /usr/lib/systemd/system/php-fpm.service PrivateTmp=false systemctl daemon-reload systemctl reload php-fpm
|
Supervisor
安装 Supervisor
1 2 3 4 5 6
| // supervisor 是 python 编写 yum install python-setuptools // 安装 supervisor easy_install supervisor // 运行命令生成一个默认的配置文件 echo_supervisord_conf > /etc/supervisord.conf
|
配置 Supervisor,打开刚才生成的配置文件 vim /etc/supervisord.conf
,把 include 块的注释打开,并修改如下:
1 2
| [include] files = /etc/supervisor/*.conf
|
使用新的配置文件启动 Supervisor
1
| supervisord -c /etc/supervisord.conf
|
查看 Supervisor 是否正常启动
1
| ps aux | grep supervisord
|
Vsftpd
安装 Vsftpd
开机启动
修改配置文件如下:
1 2 3 4 5 6 7 8 9 10 11
| vim /etc/vsftpd/vsftpd.conf # 编辑选项 anonymous_enable=NO local_enable=YES chroot_local_user=YES chroot_list_enable=YES chroot_list_file=/etc/vsftpd/chroot_list # 配置文件最后添加 allow_writeable_chroot=YES
|
新增用户
1 2
| useradd -d /data/www/ftp/ -g ftp -s /sbin/nologin ftp.cowcat.cc passwd ftp.cowcat.cc
|
Alias 常用进程命令
- Nginx
- alias nginx.start=’systemctl start nginx’
- alias nginx.restart=’systemctl restart nginx’
- alias nginx.stop=’systemctl stop nginx’
- alias nginx.status=’systemctl status nginx’
- Mysql
- alias mysql.start=’systemctl start mysql’
- alias mysql.restart=’systemctl restart mysql’
- alias mysql.stop=’systemctl stop mysql’
- alias mysql.status=’systemctl status mysql’
- PHP-FPM
- alias php-fpm.start=’systemctl start php-fpm’
- alias php-fpm.restart=’systemctl restart php-fpm’
- alias php-fpm.stop=’systemctl stop php-fpm’
- alias php-fpm.status=’systemctl status php-fpm’
- Redis
- alias redis.start=’systemctl start redis’
- alias redis.restart=’systemctl restart redis’
- alias redis.stop=’systemctl stop redis’
- alias redis.status=’systemctl status redis’
- Beanstalkd
- alias beanstalkd.start=’systemctl start beanstalkd’
- alias beanstalkd.restart=’systemctl restart beanstalkd’
- alias beanstalkd.stop=’systemctl stop beanstalkd’
- alias beanstalkd.status=’systemctl status beanstalkd’
- Gogs
- alias gogs.start=’/etc/rc.d/init.d/gogs start’
- alias gogs.stop=’/etc/rc.d/init.d/gogs stop’
- alias gogs.restart=’/etc/rc.d/init.d/gogs restart’
- alias gogs.status=’/etc/rc.d/init.d/gogs status’