更新apt源
清华大学镜像地址
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
阿里云镜像地址
https://developer.aliyun.com/mirror/ubuntu
//查看ubuntu版本
cat /etc/issue
mv /etc/apt/sources.list /etc/apt/sources.list.bak
vim /etc/apt/sources.list
// 进入上面网址选择相应的版本复制内容
apt-get update
apt-get upgrade
挂载磁盘
fdisk /dev/vdb
mkfs.ext4 /dev/vdb1
mkdir /data
mount /dev/vdb1 /data
echo "/dev/vdb1 /data ext4 defaults 0 0" >> /etc/fstab
LNMP搭建日志记录
php安装
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
# 安装php
sudo apt install -y php7.4-fpm php7.4-redis php7.4-common php7.4-bcmath php7.4-curl php7.4-gd php7.4-mbstring php7.4-mysql php7.4-xml php7.4-zip php7.4-swoole
# 修改PHP Pools
sudo sed -i 's/listen =.*/listen = 127.0.0.1:9000/' /etc/php/7.4/fpm/pool.d/www.conf
# 重启php-fpm
sudo systemctl restart php7.4-fpm
# composer
sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# 干净卸载
sudo apt-get autoremove php7*
sudo find /etc -name "*php*" |xargs rm -rf
sudo apt purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
start:立刻启动后面接的 unit。
stop:立刻关闭后面接的 unit。
restart:立刻关闭后启动后面接的 unit,亦即执行 stop 再 start 的意思。
reload:不关闭 unit 的情况下,重新载入配置文件,让设置生效。
enable:设置下次开机时,后面接的 unit 会被启动。
disable:设置下次开机时,后面接的 unit 不会被启动。
status:目前后面接的这个 unit 的状态,会列出有没有正在执行、开机时是否启动等信息。
is-active:目前有没有正在运行中。
is-enable:开机时有没有默认要启用这个 unit。
kill :不要被 kill 这个名字吓着了,它其实是向运行 unit 的进程发送信号。
show:列出 unit 的配置。
mask:注销 unit,注销后你就无法启动这个 unit 了。
unmask:取消对 unit 的注销。
PHP CLI
sudo sed -i 's/display_errors = .*/display_errors = On/' /etc/php/7.4/cli/php.ini
sudo sed -i 's/error_reporting = .*/error_reporting = E_ALL/' /etc/php/7.4/cli/php.ini
sudo sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/7.4/cli/php.ini
sudo sed -i 's/;date.timezone.*/date.timezone = UTC/' /etc/php/7.4/cli/php.iniPHP FPM
sudo sed -i 's/error_reporting = .*/error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/memory_limit = .*/memory_limit = 512M/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/upload_max_filesize = .*/upload_max_filesize = 50M/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/post_max_size = .*/post_max_size = 50M/' /etc/php/7.4/fpm/php.ini
sudo sed -i 's/;date.timezone.*/date.timezone = UTC/' /etc/php/7.4/fpm/php.iniPHP Pools
sudo sed -i 's/user = www-data/user = www/' /etc/php/7.4/fpm/pool.d/www.conf
sudo sed -i 's/group = www-data/group = www/' /etc/php/7.4/fpm/pool.d/www.conf
sudo sed -i 's/listen =.*/listen = 127.0.0.1:9000/' /etc/php/7.4/fpm/pool.d/www.conf
sudo sed -i 's/listen.owner.*/listen.owner = www/' /etc/php/7.4/fpm/pool.d/www.conf
sudo sed -i 's/listen.group.*/listen.group = www/' /etc/php/7.4/fpm/pool.d/www.conf
sudo sed -i 's/;listen.mode.*/listen.mode = 0666/' /etc/php/7.4/fpm/pool.d/www.conf
nginx安装
apt remove nginx nginx-common nginx-full nginx-core
sudo apt install -y curl gnupg2 ca-certificates lsb-release
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
rm -rf nginx_signing.key
apt install nginx
service nginx stop
service nginx start
service nginx restart
service nginx status
nginx
nginx -s quit
nginx -s stop
nginx -t -c /etc/nginx/nginx.conf
nginx -t
nginx -s reload
nginx -s reopen
nginx与php配置文件
方式1:推荐使用
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
include fastcgi_params;
}
方式2:需要修改/etc/php/7.2/fpm/pool.d/www.conf
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
include fastcgi_params;
}
//需修改/etc/php/7.2/fpm/pool.d/www.conf
;listen = /run/php/php7.2-fpm.sock
listen = 127.0.0.1:9000
openresty安装
apt-get update
# 导入我们的 GPG 密钥:
wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
# 安装 add-apt-repository 命令
# (之后你可以删除这个包以及对应的关联包)
sudo apt-get -y install software-properties-common
# 添加我们官方 official APT 仓库:
sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
# 更新 APT 索引:
sudo apt-get update
# 然后就可以像下面这样安装软件包,比如 openresty:
sudo apt-get install openresty
export PATH=$PATH:/usr/local/openresty/nginx/sbin
mysql安装
apt install -y mysql-server mysql-client
service mysql start
service mysql status
service mysql stop
service mysql restart
// 注释my.cnf
//# bind-address = 127.0.0.1
mysql -uroot -p
// 给root 远程登录权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
mysql> select Host,User,authentication_string from mysql.user;
mysql> create user "zhiqiang"@"localhost" identified by "123456";
mysql> update mysql.user set authentication_string=password("123456") where User="root";
mysql> alter user 'zhiqiang'@'localhost' identified by "123456";
mysql> set password for 'zhiqiang'@'localhost' = '123456';
mysql> update user set plugin="mysql_native_password";
mysql> flush privileges;
# 首先创建一个数据库(zqw)
create database zqw;
# 授权zhiqw用户拥有zqw数据库的所有权限,但只能在本地访问。
grant all privileges on zqw.* to 'zqw'@localhost identified by '123456';
# 用户可以远程访问zqw数据库
grant all privileges on zqw.* to 'zqw'@'%' identified by '123456';
# 刷新系统权限表
flush privileges;
# 卸载
sudo rm /var/lib/mysql/ -R
sudo rm /etc/mysql/ -R
sudo apt-get autoremove mysql* --purge
搭建 GitLab 笔记
https://about.gitlab.com/install/
apt-get install curl openssh-server ca-certificates postfix
service sshd start
service postfix start
sudo curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
apt install -y gitlab-ce
//配置访问路径
vi /etc/gitlab/gitlab.rb
>external_url 'http://127.0.0.1'
//更新配置
gitlab-ctl reconfigure
启动Gitlab所有组件
gitlab-ctl start
//重新启动gitlab
gitlab-ctl restart
//查看状态
gitlab-ctl status
RabbitMQ环境搭建
apt install -y rabbitmq-server
启动rabbit服务:service rabbitmq-server start
停止rabbit服务:service rabbitmq-server stop
后台启动:rabbitmq-server -detached
运行状态:rabbitmqctl status
查看所有用户:rabbitmqctl list_users
添加用户:rabbitmqctl add_user username password
删除用户:rabbitmqctl delete_user username
修改密码:rabbitmqctl change_password username newpassword
设置超级权限
rabbitmqctl set_user_tags username administrator
rabbitmqctl set_permissions -p / username ".\*" ".\*" ".\*"
开启rabbit网页控制台
进入rabbit安装目录:cd /usr/lib/rabbitmq
查看已经安装的插件:rabbitmq-plugins list
开启网页版控制台:rabbitmq-plugins enable rabbitmq_management
重启rabbitmq服务
输入网页访问地址:http://localhost:15672 使用默认账号:guest/guest登录
spug搭建
apt install -y supervisor redis git python3-dev python3-venv libsasl2-dev python-dev libldap2-dev libssl-dev
apt install -y libmariadbclient-dev
mkdir /data
cd /data
git clone https://github.com/openspug/spug
cd spug && git checkout -b v2.3.16
//后端部署
cd /data/spug/spug_api
python3 -m venv venv
source venv/bin/activate
pip install -U pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip install gunicorn mysqlclient -i https://pypi.tuna.tsinghua.edu.cn/simple/
python3 manage.py updatedb
python manage.py user add -u admin -p spug.dev -s -n 管理员
// 前端部署
https://github.com/openspug/spug/releases/download/v2.3.16/web_v2.3.16.tar.gz
rm -rf /data/spug/spug_web
mkdir -p /data/spug/spug_web
tar zxf web_v2.3.16.tar.gz -C /data/spug/spug_web
spug-nginx配置参考:https://spug.dev/docs/deploy-product/
// 守护进程
cp /data/spug/spug_api/tools/supervisor-spug.ini /etc/supervisor/conf.d/supervisor-spug.conf
service nginx restart
service supervisor restart
service redis restart